Skip to content

Commit dc76607

Browse files
Andrew LengAndrew Leng
authored andcommitted
test: add regression test for nullglob issue nvm-sh#3727
Adds a test that explicitly disables nullglob and runs nvm ls with an empty versions directory to ensure the fix prevents regressions. The test verifies: - nvm ls does not produce 'No such file or directory' errors - nvm ls exits with code 0 when no versions are installed
1 parent fc05468 commit dc76607

1 file changed

Lines changed: 35 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
# Regression test for issue #3727
3+
# This test ensures nvm ls works correctly when:
4+
# 1. nullglob is NOT set (default bash behavior)
5+
# 2. No node versions are installed (empty versions directory)
6+
# Previously, this would cause "find: ... No such file or directory" errors
7+
8+
die () { echo "$@" ; exit 1; }
9+
10+
\. ../../../nvm.sh
11+
\. ../../common.sh
12+
13+
# Ensure nullglob is OFF (to test the fix works without it)
14+
# This simulates a user who hasn't set nullglob in their shell
15+
if [ -n "${BASH_VERSION-}" ]; then
16+
shopt -u nullglob 2>/dev/null || true
17+
fi
18+
19+
# Make sure no fake versions exist - empty dir triggers the bug
20+
rm -rf "${NVM_DIR}/versions/node/"* 2>/dev/null
21+
mkdir -p "${NVM_DIR}/versions/node"
22+
23+
# Run nvm ls and capture stderr
24+
OUTPUT="$(nvm ls 2>&1)"
25+
EXIT_CODE=$?
26+
27+
# Should not contain "No such file or directory" error
28+
if echo "$OUTPUT" | grep -q "No such file or directory"; then
29+
die "FAIL: nvm ls produced 'No such file or directory' error with empty versions directory"
30+
fi
31+
32+
# Should succeed (exit 0)
33+
[ "$EXIT_CODE" = "0" ] || die "FAIL: nvm ls exited with code $EXIT_CODE, expected 0"
34+
35+
echo "PASS: nvm ls works with empty versions directory and nullglob disabled"

0 commit comments

Comments
 (0)