From 9b3f994be65fe37516c74a60aa158b5bb340b20d Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Wed, 3 Jun 2026 19:57:19 +0300 Subject: Add print-config mode for task 0j0 --- tests/cli.sh | 308 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 308 insertions(+) (limited to 'tests') diff --git a/tests/cli.sh b/tests/cli.sh index 590afa4..26470e6 100755 --- a/tests/cli.sh +++ b/tests/cli.sh @@ -752,6 +752,288 @@ test_repeated_output_flags_use_last_value() { test::teardown } +test_print_config_reflects_defaults() { + local expected + local output + + test::setup + + output=$( + cd "$TEST_TMPDIR" + "$TEST_PHOTOALBUM" \ + --print-config \ + --config "$TEST_REPO_ROOT/src/photoalbum.default.conf" + ) + expected=$(cat <> "$config_file" + + output=$( + cd "$TEST_TMPDIR" + "$TEST_PHOTOALBUM" --print-config --config "$config_file" + ) + expected=$(cat <> "$config_file" + + output=$( + cd "$TEST_TMPDIR" + "$TEST_PHOTOALBUM" --print-config --no-shuffle --no-tarball + ) + + test::assert_contains 'SHUFFLE=no' "$output" + test::assert_contains 'TARBALL_INCLUDE=no' "$output" + test::teardown +} + +test_print_config_normalizes_scalar_and_array_tar_opts() { + local array_config + local array_output + local scalar_config + local scalar_output + + test::setup + scalar_config="$TEST_TMPDIR/scalar.conf" + array_config="$TEST_TMPDIR/array.conf" + test::write_album_config \ + "$scalar_config" "$TEST_TMPDIR/incoming" "$TEST_TMPDIR/dist" \ + 'Scalar tar opts' 40 + { + printf 'TARBALL_INCLUDE=yes\n' + printf 'TAR_OPTS=%q\n' '--sort=name --mtime=@0 -c' + } >> "$scalar_config" + test::write_album_config \ + "$array_config" "$TEST_TMPDIR/incoming" "$TEST_TMPDIR/dist" \ + 'Array tar opts' 40 + printf 'TAR_OPTS=(--sort=name --mtime=@0 -c)\n' >> "$array_config" + + scalar_output=$("$TEST_PHOTOALBUM" --print-config --config "$scalar_config") + array_output=$("$TEST_PHOTOALBUM" --print-config --config "$array_config") + + test::assert_contains \ + 'TAR_OPTS=( --sort=name --mtime=@0 -c )' \ + "$scalar_output" + test::assert_contains \ + 'TAR_OPTS=( --sort=name --mtime=@0 -c )' \ + "$array_output" + test::teardown +} + +test_print_config_quiet_and_verbose_keep_machine_output() { + local config_file + local plain_output + local quiet_output + local verbose_output + + test::setup + config_file="$TEST_TMPDIR/photoalbum.conf" + test::write_album_config \ + "$config_file" "$TEST_TMPDIR/incoming" "$TEST_TMPDIR/dist" \ + 'Output mode config' 40 + + plain_output=$( + cd "$TEST_TMPDIR" + "$TEST_PHOTOALBUM" --print-config + ) + quiet_output=$( + cd "$TEST_TMPDIR" + "$TEST_PHOTOALBUM" --quiet --print-config + ) + verbose_output=$( + cd "$TEST_TMPDIR" + "$TEST_PHOTOALBUM" --verbose --print-config + ) + + test "$quiet_output" = "$plain_output" + test "$verbose_output" = "$plain_output" + test::assert_not_contains 'Verbose:' "$verbose_output" + test::teardown +} + +test_print_config_validates_basic_values_without_generation_preflight() { + local config_file + local output + + test::setup + config_file="$TEST_TMPDIR/photoalbum.conf" + test::write_album_config \ + "$config_file" "$TEST_TMPDIR/missing-incoming" \ + "$TEST_TMPDIR/missing-parent/dist" 'Printable missing paths' 40 + printf 'TEMPLATE_DIR=%q\n' "$TEST_TMPDIR/missing-template" >> "$config_file" + + output=$( + cd "$TEST_TMPDIR" + "$TEST_PHOTOALBUM" --print-config + ) + test::assert_contains "INCOMING_DIR=$TEST_TMPDIR/missing-incoming" "$output" + test::assert_contains "DIST_DIR=$TEST_TMPDIR/missing-parent/dist" "$output" + test::assert_contains "TEMPLATE_DIR=$TEST_TMPDIR/missing-template" "$output" + + printf 'MAXPREVIEWS=not-a-number\n' >> "$config_file" + output=$( + cd "$TEST_TMPDIR" + test::capture_failure_output "$TEST_PHOTOALBUM" --print-config + ) + test::assert_contains 'ERROR: MAXPREVIEWS must be a positive integer' \ + "$output" + test::assert_path_absent "$TEST_TMPDIR/missing-parent" + test::teardown +} + test_dry_run_reports_cli_overrides_without_writes() { local config_file local dist_dir @@ -1686,6 +1968,8 @@ test_unknown_options_and_conflicting_actions_fail() { "$TEST_PHOTOALBUM" --generate --init test::assert_failure 'clean/version conflict is rejected' \ "$TEST_PHOTOALBUM" --clean --version + test::assert_failure 'print-config/dry-run conflict is rejected' \ + "$TEST_PHOTOALBUM" --print-config --dry-run } test_empty_args_fail() { @@ -1780,6 +2064,30 @@ main() { test::run_case \ 'repeated output flags use last value' \ test_repeated_output_flags_use_last_value + test::run_case \ + '--print-config reflects defaults' \ + test_print_config_reflects_defaults + test::run_case \ + '--print-config reads selected config' \ + test_print_config_reads_selected_config + test::run_case \ + '--print-config reads current directory config' \ + test_print_config_reads_current_directory_config + test::run_case \ + '--print-config applies CLI overrides without writes' \ + test_print_config_applies_cli_overrides_without_writes + test::run_case \ + '--print-config applies negative CLI overrides' \ + test_print_config_applies_negative_cli_overrides + test::run_case \ + '--print-config normalizes scalar and array TAR_OPTS' \ + test_print_config_normalizes_scalar_and_array_tar_opts + test::run_case \ + '--print-config quiet and verbose keep machine output' \ + test_print_config_quiet_and_verbose_keep_machine_output + test::run_case \ + '--print-config validates values without generation preflight' \ + test_print_config_validates_basic_values_without_generation_preflight test::run_case \ '--dry-run reports CLI overrides without writes' \ test_dry_run_reports_cli_overrides_without_writes -- cgit v1.2.3