Skip to content

Commit 9d79391

Browse files
committed
[Tests] colors: pin NVM_HAS_COLORS to stay local, and pin the invalid-.nvmrc message
Address ljharb's review: assert `nvm --help` and `nvm set-colors` don't leak the `local NVM_HAS_COLORS` guard into the calling shell, and assert `nvm_nvmrc_invalid_msg` still emits its actual message text, not just that it's uncolored.
1 parent d0fab8b commit 9d79391

3 files changed

Lines changed: 13 additions & 0 deletions

File tree

test/fast/Set Colors/nvm --help colors the set-colors legend

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,7 @@ case "${HELP}" in
5151
*"${EXPECTED}"*) die "nvm --help --no-colors colored the legend" ;;
5252
esac
5353

54+
nvm --help >/dev/null
55+
[ -z "${NVM_HAS_COLORS-}" ] || die "nvm --help leaked NVM_HAS_COLORS=${NVM_HAS_COLORS} into the shell"
56+
5457
cleanup

test/fast/Set Colors/nvm set-colors colors the confirmation line

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,9 @@ EXPECTED_OUTPUT="$(command printf %b 'Setting colors to: \033[0;34mb\033[0m\033[
2929

3030
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
3131

32+
rm -f "${NVM_HAS_COLORS_MARKER}"
33+
NVM_HAS_COLORS_MARKER="$(mktemp)"
34+
nvm set-colors bygre >/dev/null
35+
[ -z "${NVM_HAS_COLORS-}" ] || die "nvm set-colors leaked NVM_HAS_COLORS=${NVM_HAS_COLORS} into the shell"
36+
3237
cleanup

test/fast/Unit tests/nvm_nvmrc_invalid_msg

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,9 @@ case "${OUTPUT}" in
1717
*"${ESC}"*) die "an exported NVM_HAS_COLORS should not color the invalid .nvmrc message; got >${OUTPUT}<" ;;
1818
esac
1919

20+
case "${OUTPUT}" in
21+
*'invalid .nvmrc!'*) ;;
22+
*) die "expected the invalid-.nvmrc message; got >${OUTPUT}<" ;;
23+
esac
24+
2025
cleanup

0 commit comments

Comments
 (0)