test: Add tests for nu shell detection

This commit is contained in:
Ethan P. 2025-02-21 18:52:00 -08:00
parent 58e7f52717
commit 3860f0f148
No known key found for this signature in database
GPG Key ID: B29B90B1B228FEBC
2 changed files with 23 additions and 0 deletions

7
test/shimexec/nu Executable file
View File

@ -0,0 +1,7 @@
#!/usr/bin/env bash
# Run bash, but with executable name as `nu`.
#
# Spawn the process in the background and wait on it to ensure we keep
# the fake shell as a parent process.
exec -a "${SHIM_ARGV0:-nu}" bash "$@"
exit $?

View File

@ -26,6 +26,22 @@ test:detected_fish_shell() {
grep '^set -x' <<< "$output" >/dev/null || fail 'Detected wrong shell when checking parent process.'
}
test:detected_nu_shell() {
description "Test it can detect a nushell shell."
# Note: We don't use bash's `-c` option when testing with a fake nu shell.
# 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)" | nu -l)"
grep '^\$env' <<< "$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='-nu' nu -l)"
grep '^\$env' <<< "$output" >/dev/null || fail 'Detected wrong shell when checking parent process.'
}
test:viewer_gzip() {
description "Test it can view .gz files."
command -v "gunzip" &>/dev/null || skip "Test requires gunzip."