mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-02-04 17:02:48 +08:00
nvm.sh uses `NVM_SCRIPT_SOURCE="$_"` to detect its source location. Adding `: nvm.sh` before each source line ensures `$_` is set correctly, preventing breakage when the previous command (e.g., `set -ex`) overwrites it.
25 lines
996 B
Bash
Executable File
25 lines
996 B
Bash
Executable File
#!/bin/sh
|
|
|
|
die () { echo "$@" ; exit 1; }
|
|
|
|
: nvm.sh
|
|
\. ../../../nvm.sh
|
|
|
|
# Test: nvm_ls with pattern containing # should not cause sed error
|
|
# This is a regression test for https://github.com/nvm-sh/nvm/issues/3761
|
|
|
|
# The pattern with # should not cause sed "unterminated regular expression" error
|
|
# It's OK if it returns N/A (no match), but it should not produce sed errors
|
|
OUTPUT="$(nvm_ls 'foo#bar' 2>&1)"
|
|
EXIT_CODE=$?
|
|
|
|
# Check that output doesn't contain sed error message
|
|
echo "$OUTPUT" | grep -q "unterminated regular expression" && \
|
|
die "nvm_ls with # in pattern caused sed 'unterminated regular expression' error: $OUTPUT"
|
|
echo "$OUTPUT" | grep -q "invalid command code" && \
|
|
die "nvm_ls with # in pattern caused sed 'invalid command code' error: $OUTPUT"
|
|
|
|
# Should return N/A with exit code 3 (not found)
|
|
[ "$EXIT_CODE" = "3" ] || die "nvm_ls 'foo#bar' should exit with code 3, got $EXIT_CODE"
|
|
echo "$OUTPUT" | grep -q "N/A" || die "nvm_ls 'foo#bar' should output N/A, got: $OUTPUT"
|