diff --git a/nvm.sh b/nvm.sh index 3169711..2042a24 100644 --- a/nvm.sh +++ b/nvm.sh @@ -2576,7 +2576,7 @@ $NVM_LS_REMOTE_POST_MERGED_OUTPUT" | nvm_grep -v "N/A" | command sed '/^$/d')" nvm_version_greater nvm_version_greater_than_or_equal_to \ nvm_print_npm_version nvm_npm_global_modules \ nvm_has_system_node nvm_has_system_iojs \ - nvm_download nvm_get_latest nvm_has nvm_get_latest \ + nvm_download nvm_get_latest nvm_has \ nvm_supports_source_options nvm_auto nvm_supports_xz \ nvm_echo nvm_err nvm_grep \ nvm_has_colors nvm_process_parameters > /dev/null 2>&1 diff --git "a/test/fast/Running \"nvm alias\" should create a file in the alias directory." "b/test/fast/Running \"nvm alias\" should create a file in the alias directory." index 38ba260..8a466bb 100755 --- "a/test/fast/Running \"nvm alias\" should create a file in the alias directory." +++ "b/test/fast/Running \"nvm alias\" should create a file in the alias directory." @@ -1,5 +1,9 @@ #!/bin/sh +set -ex + . ../../nvm.sh + nvm alias test v0.1.2 -[ "$(cat ../../alias/test)" = "v0.1.2" ] + +[ "$(cat "$(nvm_alias_path)/test")" = "v0.1.2" ] diff --git "a/test/fast/Running \"nvm current\" should display current nvm environment." "b/test/fast/Running \"nvm current\" should display current nvm environment." index 5748fd6..db87520 100755 --- "a/test/fast/Running \"nvm current\" should display current nvm environment." +++ "b/test/fast/Running \"nvm current\" should display current nvm environment." @@ -1,5 +1,7 @@ #!/bin/sh +set -ex + die () { echo $@ ; exit 1; } . ../../nvm.sh @@ -7,4 +9,3 @@ die () { echo $@ ; exit 1; } nvm deactivate 2>&1 [ "$(nvm current)" = "system" ] || [ "$(nvm current)" = "none" ] || die '"nvm current" did not report "system" or "none" when deactivated' - diff --git "a/test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." "b/test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." index 0356276..ba51074 100755 --- "a/test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." +++ "b/test/fast/Running \"nvm deactivate\" should unset the nvm environment variables." @@ -1,5 +1,7 @@ #!/bin/sh +set -ex + mkdir -p ../../v0.2.3 die () { echo $@ ; exit 1; } @@ -7,6 +9,7 @@ die () { echo $@ ; exit 1; } [ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&2 . ../../nvm.sh + nvm use --delete-prefix v0.2.3 || die "Failed to activate v0.2.3" [ `expr "$PATH" : ".*v0.2.3/.*/bin"` != 0 ] || die "PATH not set up properly" [ `expr "$NODE_PATH" : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "NODE_PATH should not contain (npm root -g)" diff --git "a/test/fast/Running \"nvm install\" with \"--reinstall-packages-from\" requires a valid version" "b/test/fast/Running \"nvm install\" with \"--reinstall-packages-from\" requires a valid version" index c6d2c33..f7b016d 100755 --- "a/test/fast/Running \"nvm install\" with \"--reinstall-packages-from\" requires a valid version" +++ "b/test/fast/Running \"nvm install\" with \"--reinstall-packages-from\" requires a valid version" @@ -1,5 +1,7 @@ #!/bin/sh +set -ex + die () { echo $@ ; cleanup ; exit 1; } cleanup () { rm -rf "${NVM_DIR}/v0.10.4" @@ -11,22 +13,30 @@ mkdir "${NVM_DIR}/v0.10.4" nvm deactivate >/dev/null 2>&1 +set +ex # needed for stderr INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from=0.11 2>&1)" +set -ex EXPECTED_ERROR_MSG="If --reinstall-packages-from is provided, it must point to an installed version of node." [ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \ || die ""nvm install --reinstall-packages-from" should fail when given an uninstalled version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'" +set +e # TODO: fix INSTALL_EXIT_CODE="$(nvm install v0.10.5 --reinstall-packages-from=0.11 >/dev/null 2>&1; echo $?)" -[ "~$INSTALL_EXIT_CODE" = "~5" ] \ - || die ""nvm install --reinstall-packages-from" should exit with code 5 when given an uninstalled version, got $INSTALL_EXIT_CODE" +set -e +[ $INSTALL_EXIT_CODE -eq 5 ] \ + || die ""nvm install --reinstall-packages-from" should exit with code 5 when given an uninstalled version, got ${INSTALL_EXIT_CODE}" +set +ex # needed for stderr INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from=0.10.5 2>&1)" +set -ex EXPECTED_ERROR_MSG="You can't reinstall global packages from the same version of node you're installing." [ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \ || die ""nvm install --reinstall-packages-from" should fail when given the same version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'" +set +e # TODO: fix INSTALL_EXIT_CODE="$(nvm install v0.10.5 --reinstall-packages-from=0.10.5 >/dev/null 2>&1; echo $?)" -[ "~$INSTALL_EXIT_CODE" = "~4" ] \ +set -e +[ $INSTALL_EXIT_CODE -eq 4 ] \ || die ""nvm install --reinstall-packages-from" should exit with code 4 when given the same version, got $INSTALL_EXIT_CODE" cleanup diff --git "a/test/fast/Running \"nvm install\" with an invalid version fails nicely" "b/test/fast/Running \"nvm install\" with an invalid version fails nicely" index d113890..3d78340 100755 --- "a/test/fast/Running \"nvm install\" with an invalid version fails nicely" +++ "b/test/fast/Running \"nvm install\" with an invalid version fails nicely" @@ -1,7 +1,13 @@ #!/bin/sh +set -ex + die () { echo $@ ; exit 1; } . ../../nvm.sh -[ "$(nvm install invalid.invalid 2>&1)" = "Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions." ] || die "nvm installing an invalid version did not print a nice error message" +set +ex # needed for stderr +OUTPUT="$(nvm install invalid.invalid 2>&1)" +set -ex +EXPECTED_OUTPUT="Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions." +[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "nvm installing an invalid version did not print a nice error message" diff --git "a/test/fast/Running \"nvm unalias\" should remove the alias file." "b/test/fast/Running \"nvm unalias\" should remove the alias file." index f8ed49d..d49ebf2 100755 --- "a/test/fast/Running \"nvm unalias\" should remove the alias file." +++ "b/test/fast/Running \"nvm unalias\" should remove the alias file." @@ -1,6 +1,13 @@ #!/bin/sh -echo v0.1.2 > ../../alias/test +set -ex + +ALIAS_PATH="../../alias" + +echo v0.1.2 > "${ALIAS_PATH}/test" + . ../../nvm.sh + nvm unalias test -! [ -e ../../alias/test ] + +! [ -e "${ALIAS_PATH}/test" ] diff --git "a/test/fast/Running \"nvm uninstall\" should remove the appropriate directory." "b/test/fast/Running \"nvm uninstall\" should remove the appropriate directory." index ba1ddbb..0123ab7 100755 --- "a/test/fast/Running \"nvm uninstall\" should remove the appropriate directory." +++ "b/test/fast/Running \"nvm uninstall\" should remove the appropriate directory." @@ -1,5 +1,7 @@ #!/bin/sh +set -ex + cd ../.. mkdir v0.0.1 mkdir src/node-v0.0.1 diff --git "a/test/fast/Running \"nvm uninstall\" with incorrect file permissions fails nicely" "b/test/fast/Running \"nvm uninstall\" with incorrect file permissions fails nicely" index 1fad640..5fd2638 100755 --- "a/test/fast/Running \"nvm uninstall\" with incorrect file permissions fails nicely" +++ "b/test/fast/Running \"nvm uninstall\" with incorrect file permissions fails nicely" @@ -1,5 +1,7 @@ #!/bin/sh +set -ex + cd ../.. mkdir v0.0.1 mkdir src/node-v0.0.1 @@ -8,7 +10,7 @@ sudo touch v0.0.1/sudo . ./nvm.sh -RETURN_MESSAGE="$(nvm uninstall v0.0.1 2>&1)" +RETURN_MESSAGE="$(nvm uninstall v0.0.1 2>&1 || echo)" CHECK_FOR="Cannot uninstall, incorrect permissions on installation folder" -test "${RETURN_MESSAGE#*$CHECK_FOR}" != "$RETURN_MESSAGE" || exit 1 +[ "${RETURN_MESSAGE#*$CHECK_FOR}" != "$RETURN_MESSAGE" ] || exit 1 diff --git "a/test/fast/Running \"nvm unload\" should unset all function and variables." "b/test/fast/Running \"nvm unload\" should unset all function and variables." index 0f4c50e..3ac3505 100755 --- "a/test/fast/Running \"nvm unload\" should unset all function and variables." +++ "b/test/fast/Running \"nvm unload\" should unset all function and variables." @@ -1,12 +1,13 @@ #!/bin/sh -fail () { echo $@ ; exit 1; } +set -ex + +die () { echo $@ ; exit 1; } . ../../nvm.sh -type nvm > /dev/null 2>&1 || fail "NVM not loaded" +type nvm > /dev/null 2>&1 || die "nvm not loaded" nvm unload -type nvm > /dev/null 2>&1 && fail "NVM not unloaded" || exit 0 - +! type nvm > /dev/null 2>&1 || die "nvm not unloaded" diff --git "a/test/fast/Running \"nvm use foo\" where \"foo\" is circular aborts" "b/test/fast/Running \"nvm use foo\" where \"foo\" is circular aborts" index ce4fea4..023415c 100755 --- "a/test/fast/Running \"nvm use foo\" where \"foo\" is circular aborts" +++ "b/test/fast/Running \"nvm use foo\" where \"foo\" is circular aborts" @@ -1,5 +1,7 @@ #!/bin/sh +set -ex + die () { echo $@ ; cleanup ; exit 1; } cleanup() { @@ -10,20 +12,28 @@ cleanup() { nvm_make_alias foo foo +set +ex # needed for stderr OUTPUT="$(nvm use foo 2>&1)" +set -ex EXPECTED_OUTPUT='The alias "foo" leads to an infinite loop. Aborting.' [ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \ || die "'nvm use foo' did not output >${EXPECTED_OUTPUT}<; got >${OUTPUT}<" +set +ex # needed for stderr EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)" +set -ex [ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got ${EXIT_CODE}" +set +ex # needed for stderr OUTPUT="$(nvm use --silent foo 2>&1)" +set -ex EXPECTED_OUTPUT='' [ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \ || die "'nvm use --silent foo' did not output >${EXPECTED_OUTPUT}<; got >${OUTPUT}<" +set +ex # needed for stderr EXIT_CODE="$(nvm use --silent foo 2>/dev/null ; echo $?)" +set -ex [ $EXIT_CODE -eq 8 ] || die "Expected exit code 8 from 'nvm use --silent foo'; got ${EXIT_CODE}" cleanup diff --git "a/test/fast/Running \"nvm use iojs\" uses latest io.js version" "b/test/fast/Running \"nvm use iojs\" uses latest io.js version" index 1a44d93..6c54203 100755 --- "a/test/fast/Running \"nvm use iojs\" uses latest io.js version" +++ "b/test/fast/Running \"nvm use iojs\" uses latest io.js version" @@ -13,9 +13,7 @@ cleanup() { rm -rf "$(nvm_version_path "iojs-${VERSION}")" } -set +ex # TODO . ../../nvm.sh -set -ex nvm deactivate || die "unable to deactivate; current: >$(nvm current)<" diff --git "a/test/fast/Running \"nvm use system\" should work as expected" "b/test/fast/Running \"nvm use system\" should work as expected" index 46875ac..196353d 100755 --- "a/test/fast/Running \"nvm use system\" should work as expected" +++ "b/test/fast/Running \"nvm use system\" should work as expected" @@ -1,5 +1,7 @@ #!/bin/sh +set -ex + cleanup() { unset -f nvm_has_system_node nvm_print_npm_version } @@ -11,19 +13,32 @@ nvm_has_system_node() { return 0; } nvm_print_npm_version() { command printf ' (npm v1.2.3)'; } EXPECTED_OUTPUT="Now using system version of node: $(node -v)$(nvm_print_npm_version)" +set +x # since stderr is needed OUTPUT="$(nvm use system 2>&1)" +set -x [ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "Could not use system version of node. Got >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<" + EXPECTED_OUTPUT="" -[ "$(nvm use --silent system 2>&1 | tail -1)" = "${EXPECTED_OUTPUT}" ] || die "Could not use system version of node or --silent was not silent" +set +x # since stderr is needed +OUTPUT="$(nvm use --silent system 2>&1 | tail -1)" +set -x +[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "Could not use system version of node or --silent was not silent" nvm_has_system_node() { return 1; } nvm_print_npm_version() { command printf ''; } EXPECTED_OUTPUT="System version of node not found." -[ "$(nvm use system 2>&1 | tail -1)" = "${EXPECTED_OUTPUT}" ] || die "Did not report error, system node not found" +set +x # since stderr is needed +OUTPUT="$(nvm use system 2>&1 | tail -1)" +set -x +[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "Did not report error, system node not found" + nvm use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found" EXPECTED_OUTPUT="" -[ "$(nvm use --silent system 2>&1 | tail -1)" = "${EXPECTED_OUTPUT}" ] || die "Did not report error, system node not found or --silent was not silent" +set +x # since stderr is needed +OUTPUT="$(nvm use --silent system 2>&1 | tail -1)" +set -x +[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "Did not report error, system node not found or --silent was not silent" nvm use --silent system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found or --silent was not silent" cleanup diff --git "a/test/fast/Running \"nvm use x\" should create and change the \"current\" symlink" "b/test/fast/Running \"nvm use x\" should create and change the \"current\" symlink" index 8ddaedc..e600497 100755 --- "a/test/fast/Running \"nvm use x\" should create and change the \"current\" symlink" +++ "b/test/fast/Running \"nvm use x\" should create and change the \"current\" symlink" @@ -1,11 +1,13 @@ -#!/usr/bin/env bash +#!/bin/sh + +set -ex export NVM_SYMLINK_CURRENT=true . ../../nvm.sh rm -rf "${NVM_DIR}/v0.10.29" mkdir "${NVM_DIR}/v0.10.29" -nvm use 0.10.29 +nvm use --delete-prefix 0.10.29 rmdir "${NVM_DIR}/v0.10.29" if [ ! -L "${NVM_DIR}/current" ];then @@ -22,7 +24,7 @@ fi rm -rf "${NVM_DIR}/v0.11.13" mkdir "${NVM_DIR}/v0.11.13" -nvm use 0.11.13 +nvm use --delete-prefix 0.11.13 rmdir "${NVM_DIR}/v0.11.13" newLink="$(readlink "${NVM_DIR}/current")" diff --git "a/test/fast/Running \"nvm use x\" should not create the \"current\" symlink if $NVM_SYMLINK_CURRENT is false" "b/test/fast/Running \"nvm use x\" should not create the \"current\" symlink if $NVM_SYMLINK_CURRENT is false" index 3603e04..b84ebf4 100755 --- "a/test/fast/Running \"nvm use x\" should not create the \"current\" symlink if $NVM_SYMLINK_CURRENT is false" +++ "b/test/fast/Running \"nvm use x\" should not create the \"current\" symlink if $NVM_SYMLINK_CURRENT is false" @@ -1,4 +1,6 @@ -#!/usr/bin/env bash +#!/bin/sh + +set -ex . ../../nvm.sh @@ -8,17 +10,17 @@ TEST_COUNT=0 TEST_PASSED=0 TEST_FAILED=0 -function registerExpectedSymlink() { +registerExpectedSymlink() { registerResult ${1} } -function registerExpectedNoSymlink() { - [ ${1} -ne 0 ] +registerExpectedNoSymlink() { + [ $1 -ne 0 ] registerResult $? } -function registerResult() { - result=${1} +registerResult() { + result="${1}" TEST_COUNT=$(($TEST_COUNT + 1)) @@ -27,19 +29,19 @@ function registerResult() { || TEST_FAILED=$(($TEST_FAILED + 1)) } -function cleanup() { - rm -rf ../../${TEST_NODE_VERSION} - rm -f ../../current +cleanup() { + rm -rf "${NVM_DIR}/${TEST_NODE_VERSION}" + rm -f "${NVM_DIR}/current" } -function runNvmUse() { - mkdir ../../${TEST_NODE_VERSION} - nvm use ${TEST_NODE_VERSION} > /dev/null 2>&1 - rmdir ../../${TEST_NODE_VERSION} +runNvmUse() { + mkdir "${NVM_DIR}/${TEST_NODE_VERSION}" + nvm use --delete-prefix "${TEST_NODE_VERSION}" > /dev/null 2>&1 + rmdir "${NVM_DIR}/${TEST_NODE_VERSION}" } -function isCurrentSymlinkPresent() { - [ -L ../../current ] +isCurrentSymlinkPresent() { + [ -L "${NVM_DIR}/current" ] } NVM_SYMLINK_CURRENT=false @@ -80,5 +82,4 @@ registerExpectedNoSymlink $? cleanup -[ ${TEST_FAILED} -ne 0 ] && echo "${TEST_COUNT} tested, ${TEST_PASSED} passed, ${TEST_FAILED} failed" && exit 1 || true - +[ $TEST_FAILED -ne 0 ] && echo "${TEST_COUNT} tested, ${TEST_PASSED} passed, ${TEST_FAILED} failed" && exit 1 || true diff --git a/test/fast/Sourcing nvm.sh should make the nvm command available. b/test/fast/Sourcing nvm.sh should make the nvm command available. index 24f8efa..9c215d5 100755 --- a/test/fast/Sourcing nvm.sh should make the nvm command available. +++ b/test/fast/Sourcing nvm.sh should make the nvm command available. @@ -1,4 +1,7 @@ #!/bin/sh +set -ex + . ../../nvm.sh + nvm diff --git a/test/fast/Sourcing nvm.sh should not modify parameters of caller b/test/fast/Sourcing nvm.sh should not modify parameters of caller index 67e88cf..cf8b149 100755 --- a/test/fast/Sourcing nvm.sh should not modify parameters of caller +++ b/test/fast/Sourcing nvm.sh should not modify parameters of caller @@ -1,5 +1,7 @@ #!/bin/sh +set -ex + set -- yes . ../../nvm.sh [ "$1" = yes ] diff --git a/test/fast/setup b/test/fast/setup index f98394b..6de3378 100755 --- a/test/fast/setup +++ b/test/fast/setup @@ -1,5 +1,7 @@ #!/bin/sh +set -ex + ( cd ../.. diff --git a/test/fast/setup_dir b/test/fast/setup_dir index 5e2a208..fd36775 100755 --- a/test/fast/setup_dir +++ b/test/fast/setup_dir @@ -1,5 +1,7 @@ #!/bin/sh +set -ex + ( cd ../.. diff --git a/test/fast/teardown b/test/fast/teardown index a1c73df..75a406e 100755 --- a/test/fast/teardown +++ b/test/fast/teardown @@ -1,5 +1,7 @@ #!/bin/sh +set -ex + # Remove temporary files ( cd ../.. diff --git a/test/fast/teardown_dir b/test/fast/teardown_dir index 065269a..9efb49e 100755 --- a/test/fast/teardown_dir +++ b/test/fast/teardown_dir @@ -1,5 +1,7 @@ #!/bin/sh +set -ex + ( cd ../..