diff options
| author | Paul Buetow <paul@buetow.org> | 2026-06-02 22:01:27 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2026-06-02 22:01:27 +0300 |
| commit | c94364885deb7d2a22a6ef8d78946a8c1cd52501 (patch) | |
| tree | ebe0bee0976461678bdd4ff87698bd00d6f0069c /tests | |
| parent | 32abc9059610f14046feb058cb323438210d7694 (diff) | |
Implement explicit config CLI behavior for li0
Diffstat (limited to 'tests')
| -rwxr-xr-x | tests/cli.sh | 95 |
1 files changed, 91 insertions, 4 deletions
diff --git a/tests/cli.sh b/tests/cli.sh index a6f8e14..6bc0267 100755 --- a/tests/cli.sh +++ b/tests/cli.sh @@ -57,6 +57,30 @@ assert_failure() { rm -f "$output_file" } +capture_failure_output() { + local output + local output_file + local -i status=0 + + output_file=$(mktemp) + set +e + "$@" > "$output_file" 2>&1 + status=$? + set -e + + if (( status == 0 )); then + echo 'FAIL: expected command to fail' >&2 + output=$(<"$output_file") + echo "$output" >&2 + rm -f "$output_file" + exit 1 + fi + + output=$(<"$output_file") + rm -f "$output_file" + printf '%s\n' "$output" +} + assert_contains() { local -r needle="$1"; shift local -r haystack="$1"; shift @@ -85,17 +109,19 @@ test_init() { cd "$TEST_TMPDIR" PHOTOALBUM_DEFAULT_RC="$TEST_TMPDIR/missing" \ "$PHOTOALBUM" --init >/dev/null - test -f photoalbumrc + test -f photoalbum.conf + test ! -f Makefile grep -q \ "^TEMPLATE_DIR=$REPO_ROOT/share/templates/default$" \ - photoalbumrc + photoalbum.conf ) teardown } test_clean() { setup - printf 'DIST_DIR=%q/dist\n' "$TEST_TMPDIR" > "$TEST_TMPDIR/photoalbumrc" + printf 'DIST_DIR=%q/dist\n' "$TEST_TMPDIR" \ + > "$TEST_TMPDIR/photoalbum.conf" mkdir -p "$TEST_TMPDIR/dist" ( @@ -106,12 +132,64 @@ test_clean() { teardown } +test_clean_with_config() { + local config_file + + setup + config_file="$TEST_TMPDIR/custom.conf" + printf 'DIST_DIR=%q/custom-dist\n' "$TEST_TMPDIR" > "$config_file" + mkdir -p "$TEST_TMPDIR/custom-dist" + + ( + cd "$TEST_TMPDIR" + "$PHOTOALBUM" --clean --config "$config_file" + test ! -e "$TEST_TMPDIR/custom-dist" + ) + teardown +} + +test_clean_missing_config_fails() { + local output + + setup + printf 'DIST_DIR=%q/dist\n' "$TEST_TMPDIR" > "$TEST_TMPDIR/photoalbumrc" + output=$( + cd "$TEST_TMPDIR" + capture_failure_output "$PHOTOALBUM" --clean + ) + + assert_contains 'Error: Can not find config file ./photoalbum.conf' "$output" + assert_contains 'Run photoalbum --init to create ./photoalbum.conf.' "$output" + teardown +} + +test_generate_with_config_missing_incoming_fails() { + local config_file + local output + + setup + config_file="$TEST_TMPDIR/custom.conf" + { + printf 'INCOMING_DIR=%q/missing\n' "$TEST_TMPDIR" + printf 'DIST_DIR=%q/custom-dist\n' "$TEST_TMPDIR" + } > "$config_file" + + output=$( + cd "$TEST_TMPDIR" + capture_failure_output "$PHOTOALBUM" --generate --config "$config_file" + ) + + assert_contains "ERROR: You have to create $TEST_TMPDIR/missing first" \ + "$output" + teardown +} + test_generate_missing_incoming_fails() { setup { printf 'INCOMING_DIR=%q/missing\n' "$TEST_TMPDIR" printf 'DIST_DIR=%q/dist\n' "$TEST_TMPDIR" - } > "$TEST_TMPDIR/photoalbumrc" + } > "$TEST_TMPDIR/photoalbum.conf" ( cd "$TEST_TMPDIR" @@ -131,6 +209,10 @@ test_positional_commands_fail() { test_extra_args_fail() { assert_failure 'extra operand is rejected' "$PHOTOALBUM" --version extra assert_failure 'unsupported option is rejected' "$PHOTOALBUM" --unknown + assert_failure 'missing config value is rejected' "$PHOTOALBUM" --config + assert_failure \ + '--config is rejected with --init' \ + "$PHOTOALBUM" --init --config custom.conf } main() { @@ -139,6 +221,11 @@ main() { run_test '--version succeeds' test_version run_test '--init succeeds' test_init run_test '--clean succeeds' test_clean + run_test '--clean --config succeeds' test_clean_with_config + run_test '--clean missing config fails clearly' test_clean_missing_config_fails + run_test \ + '--generate --config reads selected config' \ + test_generate_with_config_missing_incoming_fails run_test \ '--generate missing incoming fails' \ test_generate_missing_incoming_fails |
