diff --git a/test/shimexec/nu b/test/shimexec/nu new file mode 100755 index 0000000..b8e8447 --- /dev/null +++ b/test/shimexec/nu @@ -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 $? diff --git a/test/suite/batpipe.sh b/test/suite/batpipe.sh index d942b41..e834f6e 100644 --- a/test/suite/batpipe.sh +++ b/test/suite/batpipe.sh @@ -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."