Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix] nvm exec: Do a version check on nvm-exec #3308

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions nvm-exec
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ unset NVM_CD_FLAGS
# shellcheck disable=SC1090,SC1091
\. "$DIR/nvm.sh" --no-use

nvm_rc_version > /dev/null && nvm_ensure_version_installed "$NVM_RC_VERSION";
if [ -n "$NODE_VERSION" ]; then
nvm use "$NODE_VERSION" > /dev/null || exit 127
elif ! nvm use >/dev/null 2>&1; then
Expand Down
19 changes: 19 additions & 0 deletions test/fast/Running 'nvm-exec' should display required node version
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/bash

set -x
\. ../../nvm.sh

NVM_TEST_VERSION=v0.42

# Write it to nvmrc
echo "$NVM_TEST_VERSION" > .nvmrc

OUTPUT="$(../../nvm-exec 2>&1)";
EXPECTED="N/A: version \"${NVM_TEST_VERSION}\" is not yet installed.

You need to run \`nvm install ${NVM_TEST_VERSION}\` to install and use it.
No NODE_VERSION provided; no .nvmrc file found";

# Skip install, we want to test the error message
diff <(echo "${EXPECTED}") <(echo "${OUTPUT}")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line can't work tho, due to https://www.shellcheck.net/wiki/SC3001 - i'll change this to a normal = comparison unless you have a better idea

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, sound reasonable.
Was hoping that the #!/bin/bash on top would allow for that to pass, but I think = should work too.

rm .nvmrc
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aha, good catch. note tho that this doesn't actually restore what might already be present - we should back up and restore the existing .nvmrc in setup/teardown files

i'll take a crack at this part tho

8 changes: 4 additions & 4 deletions test/fast/Set Colors/nvm_print_versions calls nvm_get_colors
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

\. ../../../nvm.sh

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

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

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

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

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

Expand Down
Loading