test: Test shell detection with fake fish shell

Rather than using a real fish shell for tests, we're faking it so
package maintainers don't need to add multiple shells as build
dependencies.
This commit is contained in:
Ethan P. 2025-02-21 18:12:48 -08:00
parent a0d3a9bd63
commit 86fd93e47e
No known key found for this signature in database
GPG Key ID: B29B90B1B228FEBC
2 changed files with 4 additions and 16 deletions

View File

@ -1,14 +1,4 @@
#!/usr/bin/env bash #!/usr/bin/env bash
# Find the real fish. # Run bash, but with executable name as `fish`.
HERE="$(cd "$(dirname "$0")" && pwd)" exec -a "${SHIM_ARGV0:-fish}" bash "$@"
while read -d ':' -r dir; do exit $?
if [[ "$dir" == "$HERE" || -z "$dir" ]]; then continue; fi
if [[ -f "${dir}/fish" ]]; then
TMPDIR='' "${dir}/fish" "$@"
exit $?
fi
done <<<"$PATH:"
# Print error and exit.
echo "fish was not found on \$PATH" 1>&2
exit 127

View File

@ -11,9 +11,7 @@ test:detected_bash_shell() {
} }
test:detected_fish_shell() { test:detected_fish_shell() {
description "Test it can detect a bash shell." description "Test it can detect a fish shell."
command -v "fish" &>/dev/null || skip "Test requires fish shell."
fish -c 'exit 0' &>/dev/null || skip "Test requires fish shell." # This is in case it finds "fish" in shimexec dir.
output="$(SHELL="fish" fish --login -c "$(batpipe_path)")" output="$(SHELL="fish" fish --login -c "$(batpipe_path)")"
grep '^set -x' <<< "$output" >/dev/null || fail "Detected the wrong shell for fish." grep '^set -x' <<< "$output" >/dev/null || fail "Detected the wrong shell for fish."