diff --git a/nvm.sh b/nvm.sh index b2f0c3bb8b..38eb5b5750 100644 --- a/nvm.sh +++ b/nvm.sh @@ -3657,6 +3657,8 @@ nvm() { local provided_version local has_checked_nvmrc has_checked_nvmrc=0 + local IS_VERSION_FROM_NVMRC + IS_VERSION_FROM_NVMRC=0 # run given version of node local NVM_SILENT @@ -3702,7 +3704,9 @@ nvm() { if [ $has_checked_nvmrc -ne 1 ]; then NVM_SILENT="${NVM_SILENT:-0}" nvm_rc_version && has_checked_nvmrc=1 fi - VERSION="$(nvm_version "${NVM_RC_VERSION}")" ||: + provided_version="${NVM_RC_VERSION}" + IS_VERSION_FROM_NVMRC=1 + VERSION="$(nvm_version "${provided_version}")" ||: unset NVM_RC_VERSION else shift @@ -3724,7 +3728,7 @@ nvm() { VERSION='' fi if [ "_${VERSION}" = "_N/A" ]; then - nvm_ensure_version_installed "${provided_version}" + nvm_ensure_version_installed "${provided_version}" "${IS_VERSION_FROM_NVMRC}" elif [ "${NVM_IOJS}" = true ]; then nvm exec "${NVM_SILENT_ARG-}" "${LTS_ARG-}" "${VERSION}" iojs "$@" else diff --git a/test/slow/nvm run/Running 'nvm run' should pick up .nvmrc version b/test/slow/nvm run/Running 'nvm run' should pick up .nvmrc version index 3273ea04a7..afd0a372f9 100755 --- a/test/slow/nvm run/Running 'nvm run' should pick up .nvmrc version +++ b/test/slow/nvm run/Running 'nvm run' should pick up .nvmrc version @@ -7,6 +7,15 @@ die () { echo "$@" ; exit 1; } echo "0.10.7" > .nvmrc -[ "$(nvm run --version | tail -1)" = "v0.10.7" ] || die "\`nvm run\` failed to run with the .nvmrc version" - [ "$(nvm run --version | head -1)" = "Found '$PWD/.nvmrc' with version <0.10.7>" ] || die "\`nvm run\` failed to print out the \"found in .nvmrc\" message" + + +# running nvm run with .nvmrc should not print the version information when not installed +OUTPUT="$(nvm run --version 2>&1)" +EXIT_CODE=$? +EXPECTED_OUTPUT="Found '$PWD/.nvmrc' with version <0.10.7> +N/A: version \"v0.10.7\" is not yet installed. + +You need to run \`nvm install\` to install and use the node version specified in \`.nvmrc\`." +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "expected 'nvm use' with nvmrc to give $EXPECTED_OUTPUT, got $OUTPUT" +[ "_$EXIT_CODE" = "_1" ] || die "expected 'nvm use' with nvmrc to exit with 1, got $EXIT_CODE" diff --git a/test/slow/nvm use/Running 'nvm use' with npmrc containing not intalled version b/test/slow/nvm use/Running 'nvm use' with nvmrc containing not intalled version similarity index 91% rename from test/slow/nvm use/Running 'nvm use' with npmrc containing not intalled version rename to test/slow/nvm use/Running 'nvm use' with nvmrc containing not intalled version index 3b7aa0f386..122aa96d37 100644 --- a/test/slow/nvm use/Running 'nvm use' with npmrc containing not intalled version +++ b/test/slow/nvm use/Running 'nvm use' with nvmrc containing not intalled version @@ -8,7 +8,7 @@ nvm deactivate 2>&1 >/dev/null || die 'deactivate failed' echo "foo" > .nvmrc -# running nvm use should not print the version information +# running nvm use with .nvmrc should not print the version information OUTPUT="$(nvm use 2>&1)" EXIT_CODE=$? EXPECTED_OUTPUT="Found '$PWD/.nvmrc' with version