From c0e6d8f332a7c9aee131c519378b754f479d46ee Mon Sep 17 00:00:00 2001 From: Olivier Martin DTSI/DSI Date: Wed, 3 Aug 2016 12:49:33 +0200 Subject: [PATCH 1/2] [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 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 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. --- nvm.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/nvm.sh b/nvm.sh index 297f5ff..93146da 100644 --- a/nvm.sh +++ b/nvm.sh @@ -486,6 +486,11 @@ nvm_ensure_version_installed() { LOCAL_VERSION="$(nvm_version "${PROVIDED_VERSION}")" EXIT_CODE="$?" 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 VERSION="$(nvm_resolve_alias "${PROVIDED_VERSION}")"; then nvm_err "N/A: version \"${PROVIDED_VERSION} -> ${VERSION}\" is not yet installed." From 27dea683a557793259c3119a63d50eaa5c621453 Mon Sep 17 00:00:00 2001 From: Atsushi Yamamoto Date: Thu, 20 Oct 2016 22:37:29 -0700 Subject: [PATCH 2/2] [Tests] add tests for "make 'nvm use' display '.nvmrc' version" See #1187. --- ...displays .nvmrc version in output messages | 23 +++++++++++++++++++ test/slow/nvm use/setup_dir | 4 ++++ test/slow/nvm use/teardown_dir | 6 +++++ 3 files changed, 33 insertions(+) create mode 100755 test/slow/nvm use/Running 'nvm use' displays .nvmrc version in output messages diff --git a/test/slow/nvm use/Running 'nvm use' displays .nvmrc version in output messages b/test/slow/nvm use/Running 'nvm use' displays .nvmrc version in output messages new file mode 100755 index 0000000..2da38c3 --- /dev/null +++ b/test/slow/nvm use/Running 'nvm use' displays .nvmrc version in output messages @@ -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'" diff --git a/test/slow/nvm use/setup_dir b/test/slow/nvm use/setup_dir index e917f0b..d32b97a 100755 --- a/test/slow/nvm use/setup_dir +++ b/test/slow/nvm use/setup_dir @@ -19,5 +19,9 @@ for VERSION in "1.0.0" "1.0.1"; do nvm install "iojs-v$VERSION" done +if [ -f ".nvmrc" ]; then + mv .nvmrc .nvmrc.bak +fi + nvm_make_alias lts/testing 0.10.1 nvm_make_alias 'lts/*' lts/testing diff --git a/test/slow/nvm use/teardown_dir b/test/slow/nvm use/teardown_dir index 947be61..657de1d 100755 --- a/test/slow/nvm use/teardown_dir +++ b/test/slow/nvm use/teardown_dir @@ -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/" rmdir "${NVM_DIR}/.nvm_use_lts_alias_bak" fi + +rm .nvmrc + +if [ -f ".nvmrc.bak" ]; then + mv .nvmrc.bak .nvmrc +fi