Compare commits

...

3 Commits

Author SHA1 Message Date
Atsushi Yamamoto
40052b2247
Merge 27dea683a5 into 759f70f196 2025-02-14 09:27:25 +01:00
Atsushi Yamamoto
27dea683a5
[Tests] add tests for "make 'nvm use' display '.nvmrc' version"
See #1187.
2016-10-20 22:37:29 -07:00
Olivier Martin DTSI/DSI
c0e6d8f332
[Fix] make nvm use display .nvmrc's version in output messages
Set $PROVIDED_VERSION equals to $NVM_RC_VERSION only if a .nvmrc file is
present and the user didn't provided a version to use (.ie typed `nvm
use`).

- Behavior before this fix :

nvm use
Found '.nvmrc' with version <v0.10.28>
N/A: version "N/A" is not yet installed.

You need to run "nvm install N/A" to install it before using it.

- Behavior after this fix :

nvm use
Found '.nvmrc' with version <v0.10.28>
N/A: version "v0.10.28" is not yet installed.

You need to run "nvm install v0.10.28" to install it before using it.
2016-08-03 12:49:33 +02:00
4 changed files with 38 additions and 0 deletions

5
nvm.sh
View File

@ -715,6 +715,11 @@ nvm_ensure_version_installed() {
LOCAL_VERSION="$(nvm_version "${PROVIDED_VERSION}")" LOCAL_VERSION="$(nvm_version "${PROVIDED_VERSION}")"
EXIT_CODE="$?" EXIT_CODE="$?"
local NVM_VERSION_DIR local NVM_VERSION_DIR
if [ "_$PROVIDED_VERSION" = "_N/A" ] && [ ! -d "$NVM_RC_VERSION" ] ; then
PROVIDED_VERSION="$(nvm_ensure_version_prefix "$NVM_RC_VERSION")"
fi
if [ "${EXIT_CODE}" != "0" ] || ! nvm_is_version_installed "${LOCAL_VERSION}"; then if [ "${EXIT_CODE}" != "0" ] || ! nvm_is_version_installed "${LOCAL_VERSION}"; then
if VERSION="$(nvm_resolve_alias "${PROVIDED_VERSION}")"; then if VERSION="$(nvm_resolve_alias "${PROVIDED_VERSION}")"; then
nvm_err "N/A: version \"${PROVIDED_VERSION} -> ${VERSION}\" is not yet installed." nvm_err "N/A: version \"${PROVIDED_VERSION} -> ${VERSION}\" is not yet installed."

View File

@ -0,0 +1,23 @@
#!/bin/sh
set -ex
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
echo "v0.10.28" > .nvmrc
OUTPUT="$(nvm use 2>&1 >/dev/null | awk 'NR==1')"
EXPECTED_OUTPUT='N/A: version "v0.10.28" is not yet installed.'
TESTTT="$(nvm use 2>&1 >/dev/null)"
TESTT="$(nvm use 2>&1)"
TEST="$(nvm use)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|| die "'nvm use' did not output: '$EXPECTED_OUTPUT'; got: '$OUTPUT'; Normal: $TEST; with 2>&1: $TESTT; with /null: $TESTTT"
OUTPUT="$(nvm use 2>&1 >/dev/null | awk 'NR==3')"
EXPECTED_OUTPUT='You need to run "nvm install v0.10.28" to install it before using it.'
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|| die "'nvm use' did not output: '$EXPECTED_OUTPUT'; got: '$OUTPUT'"

View File

@ -19,5 +19,9 @@ for VERSION in "1.0.0" "1.0.1"; do
nvm install "iojs-v$VERSION" nvm install "iojs-v$VERSION"
done done
if [ -f ".nvmrc" ]; then
mv .nvmrc .nvmrc.bak
fi
nvm_make_alias lts/testing 0.10.1 nvm_make_alias lts/testing 0.10.1
nvm_make_alias 'lts/*' lts/testing nvm_make_alias 'lts/*' lts/testing

View File

@ -20,3 +20,9 @@ if [ -d "${NVM_DIR}/.nvm_use_lts_alias_bak" ]; then
mv "${NVM_DIR}/.nvm_use_lts_alias_bak/*" "${NVM_DIR}/alias/lts/" mv "${NVM_DIR}/.nvm_use_lts_alias_bak/*" "${NVM_DIR}/alias/lts/"
rmdir "${NVM_DIR}/.nvm_use_lts_alias_bak" rmdir "${NVM_DIR}/.nvm_use_lts_alias_bak"
fi fi
rm .nvmrc
if [ -f ".nvmrc.bak" ]; then
mv .nvmrc.bak .nvmrc
fi