[Tests] use `-ex` option during tests when possible
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Relates to #1130
authored by Jordan Harband · committed by Jordan Harband · parent 186eb88 · Browse files · 21 files·+115 added−40 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
21 files+115 added−40 removed
- tests:+114 added−39 removed
- other:+1 added−1 removed
Provenance
- Commit
ecbd7d4- Tree
ec1b29b- Author
Jordan Harband <ljharb@gmail.com>- Committer
Jordan Harband <ljharb@gmail.com>- Parent
186eb88
21 files changed+115 added−40 removed
modified:test/fast/Running "nvm alias" should create a file in the alias directory.+5 added-1 removed
1 #!/bin/sh2 3+set -ex4+5 . ../../nvm.sh6+7 nvm alias test v0.1.25-[ "$(cat ../../alias/test)" = "v0.1.2" ]8+9+[ "$(cat "$(nvm_alias_path)/test")" = "v0.1.2" ]modified:test/fast/Running "nvm current" should display current nvm environment.+2 added-1 removed
1 #!/bin/sh2 3+set -ex4+5 die () { echo $@ ; exit 1; }6 7 . ../../nvm.sh8 9 nvm deactivate 2>&110 11 [ "$(nvm current)" = "system" ] || [ "$(nvm current)" = "none" ] || die '"nvm current" did not report "system" or "none" when deactivated'10-modified:test/fast/Running "nvm deactivate" should unset the nvm environment variables.+3 added
1 #!/bin/sh2 3+set -ex4+5 mkdir -p ../../v0.2.36 7 die () { echo $@ ; exit 1; }8 9 [ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&210 11 . ../../nvm.sh12+13 nvm use --delete-prefix v0.2.3 || die "Failed to activate v0.2.3"14 [ `expr "$PATH" : ".*v0.2.3/.*/bin"` != 0 ] || die "PATH not set up properly"15 [ `expr "$NODE_PATH" : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "NODE_PATH should not contain (npm root -g)"16 [ `expr "$NVM_BIN" : ".*v0.2.3/bin"` != 0 ] || die "NODE_BIN should contain bin directory path"8 unmodified linesmodified:test/fast/Running "nvm install" with "--reinstall-packages-from" requires a valid version+13 added-3 removed
1 #!/bin/sh2 3+set -ex4+5 die () { echo $@ ; cleanup ; exit 1; }6 cleanup () {7 rm -rf "${NVM_DIR}/v0.10.4"8 }3 unmodified lines12 mkdir "${NVM_DIR}/v0.10.4"13 14 nvm deactivate >/dev/null 2>&115 16+set +ex # needed for stderr17 INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from=0.11 2>&1)"18+set -ex19 EXPECTED_ERROR_MSG="If --reinstall-packages-from is provided, it must point to an installed version of node."20 [ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \21 || die ""nvm install --reinstall-packages-from" should fail when given an uninstalled version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'"22 23+set +e # TODO: fix24 INSTALL_EXIT_CODE="$(nvm install v0.10.5 --reinstall-packages-from=0.11 >/dev/null 2>&1; echo $?)"20-[ "~$INSTALL_EXIT_CODE" = "~5" ] \21- || die ""nvm install --reinstall-packages-from" should exit with code 5 when given an uninstalled version, got $INSTALL_EXIT_CODE"25+set -e26+[ $INSTALL_EXIT_CODE -eq 5 ] \27+ || die ""nvm install --reinstall-packages-from" should exit with code 5 when given an uninstalled version, got ${INSTALL_EXIT_CODE}"28 29+set +ex # needed for stderr30 INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from=0.10.5 2>&1)"31+set -ex32 EXPECTED_ERROR_MSG="You can't reinstall global packages from the same version of node you're installing."33 [ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \34 || die ""nvm install --reinstall-packages-from" should fail when given the same version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'"35 36+set +e # TODO: fix37 INSTALL_EXIT_CODE="$(nvm install v0.10.5 --reinstall-packages-from=0.10.5 >/dev/null 2>&1; echo $?)"29-[ "~$INSTALL_EXIT_CODE" = "~4" ] \38+set -e39+[ $INSTALL_EXIT_CODE -eq 4 ] \40 || die ""nvm install --reinstall-packages-from" should exit with code 4 when given the same version, got $INSTALL_EXIT_CODE"41 42 cleanupmodified:test/fast/Running "nvm install" with an invalid version fails nicely+7 added-1 removed
1 #!/bin/sh2 3+set -ex4+5 die () { echo $@ ; exit 1; }6 7 . ../../nvm.sh6-[ "$(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"8 9+set +ex # needed for stderr10+OUTPUT="$(nvm install invalid.invalid 2>&1)"11+set -ex12+EXPECTED_OUTPUT="Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions."13+[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "nvm installing an invalid version did not print a nice error message"modified:test/fast/Running "nvm unalias" should remove the alias file.+9 added-2 removed
1 #!/bin/sh2 3-echo v0.1.2 > ../../alias/test3+set -ex4+5+ALIAS_PATH="../../alias"6+7+echo v0.1.2 > "${ALIAS_PATH}/test"8+9 . ../../nvm.sh10+11 nvm unalias test6-! [ -e ../../alias/test ]12+13+! [ -e "${ALIAS_PATH}/test" ]modified:test/fast/Running "nvm uninstall" should remove the appropriate directory.+2 added
1 #!/bin/sh2 3+set -ex4+5 cd ../..6 mkdir v0.0.17 mkdir src/node-v0.0.18 4 unmodified linesmodified:test/fast/Running "nvm uninstall" with incorrect file permissions fails nicely+4 added-2 removed
1 #!/bin/sh2 3+set -ex4+5 cd ../..6 mkdir v0.0.17 mkdir src/node-v0.0.18 9 sudo touch v0.0.1/sudo10 11 . ./nvm.sh12 11-RETURN_MESSAGE="$(nvm uninstall v0.0.1 2>&1)"13+RETURN_MESSAGE="$(nvm uninstall v0.0.1 2>&1 || echo)"14 CHECK_FOR="Cannot uninstall, incorrect permissions on installation folder"15 14-test "${RETURN_MESSAGE#*$CHECK_FOR}" != "$RETURN_MESSAGE" || exit 116+[ "${RETURN_MESSAGE#*$CHECK_FOR}" != "$RETURN_MESSAGE" ] || exit 1modified:test/fast/Running "nvm unload" should unset all function and variables.+5 added-4 removed
1 #!/bin/sh2 3-fail () { echo $@ ; exit 1; }3+set -ex4 5+die () { echo $@ ; exit 1; }6+7 . ../../nvm.sh8 7-type nvm > /dev/null 2>&1 || fail "NVM not loaded"9+type nvm > /dev/null 2>&1 || die "nvm not loaded"10 11 nvm unload12 11-type nvm > /dev/null 2>&1 && fail "NVM not unloaded" || exit 012-13+! type nvm > /dev/null 2>&1 || die "nvm not unloaded"modified:test/fast/Running "nvm use foo" where "foo" is circular aborts+10 added
1 #!/bin/sh2 3+set -ex4+5 die () { echo $@ ; cleanup ; exit 1; }6 7 cleanup() {8 rm -rf "$(nvm_alias_path)/foo"2 unmodified lines11 . ../../nvm.sh12 13 nvm_make_alias foo foo14 15+set +ex # needed for stderr16 OUTPUT="$(nvm use foo 2>&1)"17+set -ex18 EXPECTED_OUTPUT='The alias "foo" leads to an infinite loop. Aborting.'19 [ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \20 || die "'nvm use foo' did not output >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"21 22+set +ex # needed for stderr23 EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)"24+set -ex25 [ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got ${EXIT_CODE}"26 27+set +ex # needed for stderr28 OUTPUT="$(nvm use --silent foo 2>&1)"29+set -ex30 EXPECTED_OUTPUT=''31 [ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \32 || die "'nvm use --silent foo' did not output >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"33 34+set +ex # needed for stderr35 EXIT_CODE="$(nvm use --silent foo 2>/dev/null ; echo $?)"36+set -ex37 [ $EXIT_CODE -eq 8 ] || die "Expected exit code 8 from 'nvm use --silent foo'; got ${EXIT_CODE}"38 39 cleanupmodified:test/fast/Running "nvm use iojs" uses latest io.js version-2 removed
11 unmodified lines12 unset -f make_echo cleanup13 rm -rf "$(nvm_version_path "iojs-${VERSION}")"14 }15 16-set +ex # TODO16 . ../../nvm.sh18-set -ex17 18 nvm deactivate || die "unable to deactivate; current: >$(nvm current)<"19 20 make_fake_iojs "${VERSION}" || die "unable to make_fake_iojs ${VERSION}"15 unmodified linesmodified:test/fast/Running "nvm use system" should work as expected+18 added-3 removed
1 #!/bin/sh2 3+set -ex4+5 cleanup() {6 unset -f nvm_has_system_node nvm_print_npm_version7 }8 die() { echo $@ ; cleanup ; exit 1; }3 unmodified lines12 nvm_has_system_node() { return 0; }13 nvm_print_npm_version() { command printf ' (npm v1.2.3)'; }14 15 EXPECTED_OUTPUT="Now using system version of node: $(node -v)$(nvm_print_npm_version)"16+set +x # since stderr is needed17 OUTPUT="$(nvm use system 2>&1)"18+set -x19 [ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "Could not use system version of node. Got >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"20+21 EXPECTED_OUTPUT=""22+set +x # since stderr is needed23+OUTPUT="$(nvm use --silent system 2>&1 | tail -1)"24+set -x17-[ "$(nvm use --silent system 2>&1 | tail -1)" = "${EXPECTED_OUTPUT}" ] || die "Could not use system version of node or --silent was not silent"25+[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "Could not use system version of node or --silent was not silent"26 27 nvm_has_system_node() { return 1; }28 nvm_print_npm_version() { command printf ''; }29 30 EXPECTED_OUTPUT="System version of node not found."31+set +x # since stderr is needed32+OUTPUT="$(nvm use system 2>&1 | tail -1)"33+set -x23-[ "$(nvm use system 2>&1 | tail -1)" = "${EXPECTED_OUTPUT}" ] || die "Did not report error, system node not found"34+[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "Did not report error, system node not found"35+36 nvm use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found"37 EXPECTED_OUTPUT=""38+set +x # since stderr is needed39+OUTPUT="$(nvm use --silent system 2>&1 | tail -1)"40+set -x26-[ "$(nvm use --silent system 2>&1 | tail -1)" = "${EXPECTED_OUTPUT}" ] || die "Did not report error, system node not found or --silent was not silent"41+[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "Did not report error, system node not found or --silent was not silent"42 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"43 44 cleanupmodified:test/fast/Running "nvm use x" should create and change the "current" symlink+5 added-3 removed
1-#!/usr/bin/env bash1+#!/bin/sh2 3+set -ex4+5 export NVM_SYMLINK_CURRENT=true6 . ../../nvm.sh7 8 rm -rf "${NVM_DIR}/v0.10.29"9 mkdir "${NVM_DIR}/v0.10.29"8-nvm use 0.10.2910+nvm use --delete-prefix 0.10.2911 rmdir "${NVM_DIR}/v0.10.29"12 13 if [ ! -L "${NVM_DIR}/current" ];then14 echo "Expected 'current' symlink to be created!"8 unmodified lines23 fi24 25 rm -rf "${NVM_DIR}/v0.11.13"26 mkdir "${NVM_DIR}/v0.11.13"25-nvm use 0.11.1327+nvm use --delete-prefix 0.11.1328 rmdir "${NVM_DIR}/v0.11.13"29 30 newLink="$(readlink "${NVM_DIR}/current")"31 4 unmodified linesmodified:test/fast/Running "nvm use x" should not create the "current" symlink if $NVM_SYMLINK_CURRENT is false+18 added-17 removed
1-#!/usr/bin/env bash1+#!/bin/sh2 3+set -ex4+5 . ../../nvm.sh6 7 TEST_NODE_VERSION="v0.10.29"8 9 TEST_COUNT=010 TEST_PASSED=011 TEST_FAILED=012 11-function registerExpectedSymlink() {13+registerExpectedSymlink() {14 registerResult ${1}15 }16 15-function registerExpectedNoSymlink() {16- [ ${1} -ne 0 ]17+registerExpectedNoSymlink() {18+ [ $1 -ne 0 ]19 registerResult $?20 }21 20-function registerResult() {21- result=${1}22+registerResult() {23+ result="${1}"24 25 TEST_COUNT=$(($TEST_COUNT + 1))26 27 [ ${result} -eq 0 ] \28 && TEST_PASSED=$(($TEST_PASSED + 1)) \29 || TEST_FAILED=$(($TEST_FAILED + 1))30 }31 30-function cleanup() {31- rm -rf ../../${TEST_NODE_VERSION}32- rm -f ../../current32+cleanup() {33+ rm -rf "${NVM_DIR}/${TEST_NODE_VERSION}"34+ rm -f "${NVM_DIR}/current"35 }36 35-function runNvmUse() {36- mkdir ../../${TEST_NODE_VERSION}37- nvm use ${TEST_NODE_VERSION} > /dev/null 2>&138- rmdir ../../${TEST_NODE_VERSION}37+runNvmUse() {38+ mkdir "${NVM_DIR}/${TEST_NODE_VERSION}"39+ nvm use --delete-prefix "${TEST_NODE_VERSION}" > /dev/null 2>&140+ rmdir "${NVM_DIR}/${TEST_NODE_VERSION}"41 }42 41-function isCurrentSymlinkPresent() {42- [ -L ../../current ]43+isCurrentSymlinkPresent() {44+ [ -L "${NVM_DIR}/current" ]45 }46 47 NVM_SYMLINK_CURRENT=false48 cleanup32 unmodified lines81 registerExpectedNoSymlink $?82 83 cleanup84 83-[ ${TEST_FAILED} -ne 0 ] && echo "${TEST_COUNT} tested, ${TEST_PASSED} passed, ${TEST_FAILED} failed" && exit 1 || true84-85+[ $TEST_FAILED -ne 0 ] && echo "${TEST_COUNT} tested, ${TEST_PASSED} passed, ${TEST_FAILED} failed" && exit 1 || truemodified:test/fast/setup+2 added
1 #!/bin/sh2 3+set -ex4+5 (6 cd ../..7 8 # Back up6 unmodified linesmodified:test/fast/setup_dir+2 added
1 #!/bin/sh2 3+set -ex4+5 (6 cd ../..7 8 # Back up10 unmodified linesmodified:test/fast/Sourcing nvm.sh should make the nvm command available.+3 added
1 #!/bin/sh2 3+set -ex4+5 . ../../nvm.sh6+7 nvmmodified:test/fast/Sourcing nvm.sh should not modify parameters of caller+2 added
1 #!/bin/sh2 3+set -ex4+5 set -- yes6 . ../../nvm.sh7 [ "$1" = yes ]modified:test/fast/teardown+2 added
1 #!/bin/sh2 3+set -ex4+5 # Remove temporary files6 (7 cd ../..8 4 unmodified linesmodified:test/fast/teardown_dir+2 added
1 #!/bin/sh2 3+set -ex4+5 (6 cd ../..7 8 # Restore7 unmodified linesmodified:nvm.sh+1 added-1 removed
2574 unmodified lines2575 nvm_find_nvmrc nvm_find_up nvm_tree_contains_path \2576 nvm_version_greater nvm_version_greater_than_or_equal_to \2577 nvm_print_npm_version nvm_npm_global_modules \2578 nvm_has_system_node nvm_has_system_iojs \2579- nvm_download nvm_get_latest nvm_has nvm_get_latest \2579+ nvm_download nvm_get_latest nvm_has \2580 nvm_supports_source_options nvm_auto nvm_supports_xz \2581 nvm_echo nvm_err nvm_grep \2582 nvm_has_colors nvm_process_parameters > /dev/null 2>&12583 unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_DIR NVM_CD_FLAGS > /dev/null 2>&160 unmodified lines