test: Add more robust tests for shell detection

This commit is contained in:
Ethan P. 2025-02-21 18:17:46 -08:00
parent 86fd93e47e
commit 58e7f52717
No known key found for this signature in database
GPG Key ID: B29B90B1B228FEBC

View File

@ -12,9 +12,18 @@ test:detected_bash_shell() {
test:detected_fish_shell() { test:detected_fish_shell() {
description "Test it can detect a fish shell." description "Test it can detect a fish shell."
output="$(SHELL="fish" fish --login -c "$(batpipe_path)")" # Note: We don't use bash's `-c` option when testing with a fake fish shell.
grep '^set -x' <<< "$output" >/dev/null || fail "Detected the wrong shell for fish." # Bash `-c` will automatically exec() into the last process, which loses the
# argv0 we intentionally named after a different shell.
# Test detection via `*sh -l` parent process.
output="$(printf "%q" "$(batpipe_path)" | fish -l)"
grep '^set -x' <<< "$output" >/dev/null || fail 'Detected wrong shell when checking parent process args.'
# Test detection via hypen-prefixed parent process.
output="$(printf "%q" "$(batpipe_path)" | SHIM_ARGV0='-fish' fish)"
grep '^set -x' <<< "$output" >/dev/null || fail 'Detected wrong shell when checking parent process.'
} }
test:viewer_gzip() { test:viewer_gzip() {