diff --git a/nvm.sh b/nvm.sh index 9d4b1d61944..dbbe4527cfd 100755 --- a/nvm.sh +++ b/nvm.sh @@ -2922,11 +2922,11 @@ nvm_is_natural_num() { nvm_write_nvmrc() { local VERSION_STRING - VERSION_STRING=$(nvm_version "${1-$VERSION_STRING}") - if [ "$VERSION_STRING" = '∞' ] || [ "$VERSION_STRING" = 'N/A' ]; then + VERSION_STRING=$(nvm_version "${1-}") + if [ "${VERSION_STRING}" = '∞' ] || [ "${VERSION_STRING}" = 'N/A' ]; then return 1 fi - echo "$VERSION_STRING" | tee "$PWD"/.nvmrc > /dev/null || { + echo "${VERSION_STRING}" | tee "$PWD"/.nvmrc > /dev/null || { if [ "${NVM_SILENT:-0}" -ne 1 ]; then nvm_err "Warning: Unable to write version number ($VERSION_STRING) to .nvmrc" fi diff --git a/test/common.sh b/test/common.sh index f5bf6ffbf6b..6972f9deb3c 100644 --- a/test/common.sh +++ b/test/common.sh @@ -53,6 +53,8 @@ make_fake_node() { echo >&2 'fake node is not installed' return 4 } + + echo >&2 "fake node is installed: ${FORMATTED_VERSION}" } make_fake_iojs() { diff --git a/test/fast/Unit tests/Running 'nvm install --save' works as expected' b/test/fast/Unit tests/Running 'nvm install --save' works as expected' index 7f6c565cee3..d583189116e 100755 --- a/test/fast/Unit tests/Running 'nvm install --save' works as expected' +++ b/test/fast/Unit tests/Running 'nvm install --save' works as expected' @@ -8,16 +8,16 @@ TEST_VERSION="v0.2.4" if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi -cleanup () { +cleanup() { nvm cache clear nvm deactivate nvm unalias default - rm -rf ${NVM_DIR}/v* .nvmrc + rm -rf ${NVM_DIR}/v0.2.4 .nvmrc if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi unset -f nvm_ls_remote nvm_ls_remote_iojs } -die () { +die() { echo "$@" cleanup exit 1 @@ -25,19 +25,19 @@ die () { REMOTE="$PWD/mocks/nvm_ls_remote.txt" nvm_ls_remote() { - cat "$REMOTE" + cat "${REMOTE}" } REMOTE_IOJS="$PWD/mocks/nvm_ls_remote_iojs.txt" nvm_ls_remote_iojs() { - cat "$REMOTE_IOJS" + cat "${REMOTE_IOJS}" } -make_fake_node "$TEST_VERSION" +make_fake_node "${TEST_VERSION}" -nvm install --save "$TEST_VERSION" || die "\`nvm install --save $TEST_VERSION\` failed" +nvm install --save "${TEST_VERSION}" || die "\`nvm install --save ${TEST_VERSION}\` failed" OUTPUT="$(cat .nvmrc)" nvm_is_valid_version "$(cat .nvmrc)" \ - || die "\`nvm install --save $TEST_VERSION\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'" + || die "\`nvm install --save ${TEST_VERSION}\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'" cleanup