Skip to content

Commit 01a8749

Browse files
userwithsljharb
authored andcommitted
[Fix] nvm exec: Do a version check on nvm-exec
This check would display a message in case the `.nvmrc` version is not installed, and would not alter the output otherwise.
1 parent 0fbe3a6 commit 01a8749

File tree

3 files changed

+30
-7
lines changed

3 files changed

+30
-7
lines changed

nvm-exec

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ unset NVM_CD_FLAGS
99

1010
if [ -n "$NODE_VERSION" ]; then
1111
nvm use "$NODE_VERSION" > /dev/null || exit 127
12-
elif ! nvm use >/dev/null 2>&1; then
13-
echo "No NODE_VERSION provided; no .nvmrc file found" >&2
14-
exit 127
12+
else
13+
nvm_rc_version > /dev/null && nvm_ensure_version_installed "$NVM_RC_VERSION";
14+
if ! nvm use >/dev/null 2>&1; then
15+
echo "No NODE_VERSION provided; no .nvmrc file found" >&2
16+
exit 127
17+
fi
1518
fi
1619

1720
exec "$@"
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
set -x
4+
\. ../../nvm.sh
5+
6+
die () { echo "$@" ; rm .nvmrc ; exit 1; }
7+
8+
NVM_TEST_VERSION=v0.42
9+
10+
# Write it to nvmrc
11+
echo "$NVM_TEST_VERSION" > .nvmrc
12+
13+
OUTPUT="$(../../nvm-exec 2>&1)";
14+
EXPECTED="N/A: version \"${NVM_TEST_VERSION}\" is not yet installed.
15+
16+
You need to run \`nvm install ${NVM_TEST_VERSION}\` to install and use it.
17+
No NODE_VERSION provided; no .nvmrc file found";
18+
19+
# Skip install, we want to test the error message
20+
[ "${EXPECTED}" = "${OUTPUT}" ] || die "expected >${EXPECTED}<, got >${OUTPUT}<"

test/fast/Set Colors/nvm_print_versions calls nvm_get_colors

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
\. ../../../nvm.sh
44

5-
set -e
5+
#set -e #nvm use system returns 127 and No system set message
66

77
die () {
88
# echo "$@" ;
@@ -24,7 +24,7 @@ fi
2424
# default system color
2525
nvm use system
2626
OUTPUT=$(nvm_print_versions system)
27-
FORMAT="\033[0;32m-> %12s\033[0m"
27+
FORMAT="\033[0;33m%15s\033[0m"
2828
VERSION='system'
2929
EXPECTED_OUTPUT=$(command printf -- "${FORMAT}\\n" "${VERSION}")
3030

@@ -34,7 +34,7 @@ nvm_ls_current() { echo "current";}
3434

3535
# default current color
3636
OUTPUT=$(nvm_print_versions current)
37-
FORMAT="\033[0;32m-> %12s\033[0m"
37+
FORMAT="\033[0;32m->%13s\033[0m"
3838
VERSION="current"
3939
EXPECTED_OUTPUT=$(command printf -- "${FORMAT}\\n" "${VERSION}")
4040

@@ -43,7 +43,7 @@ EXPECTED_OUTPUT=$(command printf -- "${FORMAT}\\n" "${VERSION}")
4343
# custom current color
4444
nvm set-colors YCMGR
4545
OUTPUT=$(nvm_print_versions current)
46-
FORMAT="\033[1;35m-> %12s\033[0m"
46+
FORMAT="\033[1;35m->%13s\033[0m"
4747
VERSION="current"
4848
EXPECTED_OUTPUT=$(command printf -- "${FORMAT}\\n" "${VERSION}")
4949

0 commit comments

Comments
 (0)