mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-07-19 05:18:22 +08:00
- `cleanup` unset TEST_DIR before `rm -rf "${TEST_DIR-}"`, so the temp dir (with an executable fake `node`) was never removed,
and urchin executes any executable file it finds under the test dir on the next local run.
- the preexisting `foo#bar` assertions ran against the ambient NVM_DIR;
now that `#` patterns comment-strip to `foo`, a real local alias named `foo` would resolve and break them,
so all assertions now run against an isolated NVM_DIR.
- the multiline content used a full x.y.z version, which takes nvm_ls's explicit-version fast path and never reaches the find/sed pipeline where the newline actually broke sed;
a partial version exercises that path, and matching on "unterminated" covers both the BSD and GNU sed error wordings.
69 lines
2.7 KiB
Bash
Executable File
69 lines
2.7 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
die () { echo "$@" ; cleanup ; exit 1; }
|
|
|
|
cleanup() {
|
|
rm -rf "${TEST_DIR-}"
|
|
unset NVMRC_CONTENT OUTPUT EXIT_CODE TEST_DIR NVM_DIR
|
|
}
|
|
|
|
: nvm.sh
|
|
\. ../../../nvm.sh
|
|
|
|
\. ../../common.sh
|
|
|
|
# an isolated NVM_DIR with a single known version, so that ambient versions
|
|
# and aliases can not affect any assertions
|
|
TEST_DIR="${PWD}/nvm_ls_hash_pattern_tmp"
|
|
mkdir -p "${TEST_DIR}/versions/node/v24.13.0/bin" || die 'failed to create test version dir'
|
|
make_echo "${TEST_DIR}/versions/node/v24.13.0/bin/node" 'v24.13.0' || die 'failed to create test node binary'
|
|
NVM_DIR="${TEST_DIR}"
|
|
|
|
# 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"
|
|
|
|
NVMRC_CONTENT='v24.13.0
|
|
# krypton is the codename for Node.js v24.x'
|
|
|
|
OUTPUT="$(nvm_ls "${NVMRC_CONTENT}" 2>&1)"
|
|
EXIT_CODE=$?
|
|
|
|
[ "$EXIT_CODE" = "0" ] || die "nvm_ls with .nvmrc comments should exit with code 0, got $EXIT_CODE"
|
|
[ "$OUTPUT" = "v24.13.0" ] || die "nvm_ls with .nvmrc comments should output v24.13.0, got: $OUTPUT"
|
|
|
|
OUTPUT="$(nvm_version "${NVMRC_CONTENT}" 2>&1)"
|
|
[ "$OUTPUT" = "v24.13.0" ] || die "nvm_version with .nvmrc comments should output v24.13.0, got: $OUTPUT"
|
|
|
|
# a partial version reaches nvm_ls's find/sed pipeline, which is where multiline
|
|
# patterns used to break sed ("unterminated regular expression" on BSD sed,
|
|
# "unterminated address regex" on GNU sed); a full x.y.z version takes the
|
|
# explicit-version fast path and never reaches it
|
|
NVMRC_CONTENT='24
|
|
# krypton is the codename for Node.js v24.x'
|
|
|
|
OUTPUT="$(nvm_ls "${NVMRC_CONTENT}" 2>&1)"
|
|
EXIT_CODE=$?
|
|
|
|
echo "$OUTPUT" | grep -q "unterminated" && \
|
|
die "nvm_ls with partial version + comments caused a sed error: $OUTPUT"
|
|
|
|
[ "$EXIT_CODE" = "0" ] || die "nvm_ls with partial version + comments should exit with code 0, got $EXIT_CODE"
|
|
[ "$OUTPUT" = "v24.13.0" ] || die "nvm_ls with partial version + comments should output v24.13.0, got: $OUTPUT"
|
|
|
|
cleanup
|