From 3860f0f1481f1d0e117392030f55ef19cc018ee4 Mon Sep 17 00:00:00 2001 From: "Ethan P." Date: Fri, 21 Feb 2025 18:52:00 -0800 Subject: [PATCH] test: Add tests for nu shell detection --- test/shimexec/nu | 7 +++++++ test/suite/batpipe.sh | 16 ++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100755 test/shimexec/nu 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."