Skip to content
Myr

[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

21 files+115 added−40 removed

modified:test/fast/Running "nvm alias" should create a file in the alias directory.+5 added-1 removed
1#!/bin/sh23set -ex45. ../../nvm.sh67nvm alias test v0.1.25[ "$(cat ../../alias/test)" = "v0.1.2" ]89[ "$(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/sh23set -ex45die () { echo $@ ; exit 1; }67. ../../nvm.sh89nvm deactivate 2>&11011[ "$(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/sh23set -ex45mkdir -p ../../v0.2.367die () { echo $@ ; exit 1; }89[ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&21011. ../../nvm.sh1213nvm 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 lines
modified:test/fast/Running "nvm install" with "--reinstall-packages-from" requires a valid version+13 added-3 removed
1#!/bin/sh23set -ex45die () { echo $@ ; cleanup ; exit 1; }6cleanup () {7 rm -rf "${NVM_DIR}/v0.10.4"8}
3 unmodified lines
12mkdir "${NVM_DIR}/v0.10.4"1314nvm deactivate >/dev/null 2>&11516set +ex # needed for stderr17INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from=0.11 2>&1)"18set -ex19EXPECTED_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'"2223set +e # TODO: fix24INSTALL_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"25set -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}"2829set +ex # needed for stderr30INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from=0.10.5 2>&1)"31set -ex32EXPECTED_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'"3536set +e # TODO: fix37INSTALL_EXIT_CODE="$(nvm install v0.10.5 --reinstall-packages-from=0.10.5 >/dev/null 2>&1; echo $?)"29[ "~$INSTALL_EXIT_CODE" = "~4" ] \38set -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"4142cleanup
modified:test/fast/Running "nvm install" with an invalid version fails nicely+7 added-1 removed
1#!/bin/sh23set -ex45die () { echo $@ ; exit 1; }67. ../../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"89set +ex # needed for stderr10OUTPUT="$(nvm install invalid.invalid 2>&1)"11set -ex12EXPECTED_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/sh23echo v0.1.2 > ../../alias/test3set -ex45ALIAS_PATH="../../alias"67echo v0.1.2 > "${ALIAS_PATH}/test"89. ../../nvm.sh1011nvm unalias test6! [ -e ../../alias/test ]1213! [ -e "${ALIAS_PATH}/test" ]
modified:test/fast/Running "nvm uninstall" should remove the appropriate directory.+2 added
1#!/bin/sh23set -ex45cd ../..6mkdir v0.0.17mkdir src/node-v0.0.18
4 unmodified lines
modified:test/fast/Running "nvm uninstall" with incorrect file permissions fails nicely+4 added-2 removed
1#!/bin/sh23set -ex45cd ../..6mkdir v0.0.17mkdir src/node-v0.0.189sudo touch v0.0.1/sudo1011. ./nvm.sh1211RETURN_MESSAGE="$(nvm uninstall v0.0.1 2>&1)"13RETURN_MESSAGE="$(nvm uninstall v0.0.1 2>&1 || echo)"14CHECK_FOR="Cannot uninstall, incorrect permissions on installation folder"1514test "${RETURN_MESSAGE#*$CHECK_FOR}" != "$RETURN_MESSAGE" || exit 116[ "${RETURN_MESSAGE#*$CHECK_FOR}" != "$RETURN_MESSAGE" ] || exit 1
modified:test/fast/Running "nvm unload" should unset all function and variables.+5 added-4 removed
1#!/bin/sh23fail () { echo $@ ; exit 1; }3set -ex45die () { echo $@ ; exit 1; }67. ../../nvm.sh87type nvm > /dev/null 2>&1 || fail "NVM not loaded"9type nvm > /dev/null 2>&1 || die "nvm not loaded"1011nvm unload1211type nvm > /dev/null 2>&1 && fail "NVM not unloaded" || exit 01213! 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/sh23set -ex45die () { echo $@ ; cleanup ; exit 1; }67cleanup() {8 rm -rf "$(nvm_alias_path)/foo"
2 unmodified lines
11. ../../nvm.sh1213nvm_make_alias foo foo1415set +ex # needed for stderr16OUTPUT="$(nvm use foo 2>&1)"17set -ex18EXPECTED_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}<"2122set +ex # needed for stderr23EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)"24set -ex25[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got ${EXIT_CODE}"2627set +ex # needed for stderr28OUTPUT="$(nvm use --silent foo 2>&1)"29set -ex30EXPECTED_OUTPUT=''31[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \32 || die "'nvm use --silent foo' did not output >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"3334set +ex # needed for stderr35EXIT_CODE="$(nvm use --silent foo 2>/dev/null ; echo $?)"36set -ex37[ $EXIT_CODE -eq 8 ] || die "Expected exit code 8 from 'nvm use --silent foo'; got ${EXIT_CODE}"3839cleanup
modified:test/fast/Running "nvm use iojs" uses latest io.js version-2 removed
11 unmodified lines
12 unset -f make_echo cleanup13 rm -rf "$(nvm_version_path "iojs-${VERSION}")"14}1516set +ex # TODO16. ../../nvm.sh18set -ex1718nvm deactivate || die "unable to deactivate; current: >$(nvm current)<"1920make_fake_iojs "${VERSION}" || die "unable to make_fake_iojs ${VERSION}"
15 unmodified lines
modified:test/fast/Running "nvm use system" should work as expected+18 added-3 removed
1#!/bin/sh23set -ex45cleanup() {6 unset -f nvm_has_system_node nvm_print_npm_version7}8die() { echo $@ ; cleanup ; exit 1; }
3 unmodified lines
12nvm_has_system_node() { return 0; }13nvm_print_npm_version() { command printf ' (npm v1.2.3)'; }1415EXPECTED_OUTPUT="Now using system version of node: $(node -v)$(nvm_print_npm_version)"16set +x # since stderr is needed17OUTPUT="$(nvm use system 2>&1)"18set -x19[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "Could not use system version of node. Got >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"2021EXPECTED_OUTPUT=""22set +x # since stderr is needed23OUTPUT="$(nvm use --silent system 2>&1 | tail -1)"24set -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"2627nvm_has_system_node() { return 1; }28nvm_print_npm_version() { command printf ''; }2930EXPECTED_OUTPUT="System version of node not found."31set +x # since stderr is needed32OUTPUT="$(nvm use system 2>&1 | tail -1)"33set -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"3536nvm use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found"37EXPECTED_OUTPUT=""38set +x # since stderr is needed39OUTPUT="$(nvm use --silent system 2>&1 | tail -1)"40set -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"42nvm use --silent system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found or --silent was not silent"4344cleanup
modified:test/fast/setup+2 added
1#!/bin/sh23set -ex45(6 cd ../..78 # Back up
6 unmodified lines
modified:test/fast/setup_dir+2 added
1#!/bin/sh23set -ex45(6 cd ../..78 # Back up
10 unmodified lines
modified:test/fast/Sourcing nvm.sh should make the nvm command available.+3 added
1#!/bin/sh23set -ex45. ../../nvm.sh67nvm
modified:test/fast/Sourcing nvm.sh should not modify parameters of caller+2 added
1#!/bin/sh23set -ex45set -- yes6. ../../nvm.sh7[ "$1" = yes ]
modified:test/fast/teardown+2 added
1#!/bin/sh23set -ex45# Remove temporary files6(7 cd ../..8
4 unmodified lines
modified:test/fast/teardown_dir+2 added
1#!/bin/sh23set -ex45(6 cd ../..78 # Restore
7 unmodified lines
modified:nvm.sh+1 added-1 removed
2574 unmodified lines
2575 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>&1
60 unmodified lines