packaging: use [[ for bash tests (SonarCloud S7688)

Behaviour-preserving: `[[ ]]` in place of `[ ]` for bash tests (SonarCloud shell:S7688). Every script has a bash shebang; no test uses `-a`/`-o`, escaped parentheses or an unquoted pattern on the right of `=`. `bash -n` passes on each script; the rest is left to CI.

- `packaging/linux/apprun-cli-test.sh` (14)
This commit is contained in:
Dylan M. Taylor committed 2026-11-10 23:22:00 +00:00
1 parent de9add28b2
commit 6f2860686d
1 file changed
+14 -14
+14 -14
View File
@@ -41,39 +41,39 @@ fail() { echo "FAIL: $*" >&2; exit 1; }
out="$("$app_dir/AppRun" --cli convert 'input file.png' '' '*.psd' --out 'output file.psd')"
expected=$'cli\n<convert>\n<input file.png>\n<>\n<*.psd>\n<--out>\n<output file.psd>'
[ "$out" = "$expected" ] || fail "CLI arguments changed: $out"
[ "$("$app_dir/AppRun" --cli)" = cli ] || fail "empty CLI invocation"
[[ "$out" = "$expected" ]] || fail "CLI arguments changed: $out"
[[ "$("$app_dir/AppRun" --cli)" = cli ]] || fail "empty CLI invocation"
# The AppImage runtime exposes the original symlink name through ARGV0.
for argv0 in photocraft-cli ./photocraft-cli "$test_dir/with spaces/photocraft-cli"; do
out="$(ARGV0="$argv0" "$app_dir/AppRun" --version)"
[ "$out" = $'cli\n<--version>' ] || fail "CLI symlink not selected: $argv0"
[[ "$out" = $'cli\n<--version>' ]] || fail "CLI symlink not selected: $argv0"
done
out="$(ARGV0=photocraft-cli "$app_dir/AppRun" --cli --version)"
[ "$out" = $'cli\n<--version>' ] || fail "CLI selector not removed with a symlink"
[[ "$out" = $'cli\n<--version>' ]] || fail "CLI selector not removed with a symlink"
request='{"jsonrpc":"2.0","id":1,"method":"initialize"}'
out="$(printf '%s\n' "$request" | "$app_dir/AppRun" --cli mcp 2>"$test_dir/stderr")"
[ "$out" = "$request" ] || fail "MCP stdin/stdout changed: $out"
[ "$(cat "$test_dir/stderr")" = 'cli stderr' ] || fail "CLI stderr lost"
[[ "$out" = "$request" ]] || fail "MCP stdin/stdout changed: $out"
[[ "$(cat "$test_dir/stderr")" = 'cli stderr' ]] || fail "CLI stderr lost"
status=0
"$app_dir/AppRun" --cli --exit-37 || status=$?
[ "$status" = 37 ] || fail "CLI exit status changed: $status"
[ ! -e "$XDG_DATA_HOME" ] || fail "CLI performed desktop integration"
[[ "$status" = 37 ]] || fail "CLI exit status changed: $status"
[[ ! -e "$XDG_DATA_HOME" ]] || fail "CLI performed desktop integration"
# GUI invocations still forward all arguments; only a leading --cli is a selector.
out="$("$app_dir/AppRun" 'input file.png' --cli)"
[ "$out" = $'gui\n<input file.png>\n<--cli>' ] || fail "GUI arguments changed: $out"
[ -f "$XDG_DATA_HOME/applications/ai.storyteller.photocraft.desktop" ] || fail "GUI integration lost"
[[ "$out" = $'gui\n<input file.png>\n<--cli>' ]] || fail "GUI arguments changed: $out"
[[ -f "$XDG_DATA_HOME/applications/ai.storyteller.photocraft.desktop" ]] || fail "GUI integration lost"
out="$(ARGV0=another-photocraft-cli "$app_dir/AppRun" mcp)"
[ "$out" = $'gui\n<mcp>' ] || fail "an unrelated filename selected CLI"
[[ "$out" = $'gui\n<mcp>' ]] || fail "an unrelated filename selected CLI"
# A broken package must fail visibly, rather than silently opening the GUI.
rm "$app_dir/usr/bin/photocraft-cli"
status=0
"$app_dir/AppRun" --cli --version >"$test_dir/missing-out" 2>"$test_dir/missing-err" || status=$?
[ "$status" != 0 ] || fail "missing CLI succeeded"
[ ! -s "$test_dir/missing-out" ] || fail "missing CLI launched the GUI"
[ -s "$test_dir/missing-err" ] || fail "missing CLI had no diagnostic"
[[ "$status" != 0 ]] || fail "missing CLI succeeded"
[[ ! -s "$test_dir/missing-out" ]] || fail "missing CLI launched the GUI"
[[ -s "$test_dir/missing-err" ]] || fail "missing CLI had no diagnostic"
echo "AppRun CLI selection ok"