[Tests] use `-ex` option during tests when possible

Relates to #1130
Jordan Harband 2016-07-07 00:00:59 -07:00
parent 186eb8838d
commit ecbd7d4572
21 changed files with 115 additions and 40 deletions

2
nvm.sh
View File

@ -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_version_greater nvm_version_greater_than_or_equal_to \
nvm_print_npm_version nvm_npm_global_modules \ nvm_print_npm_version nvm_npm_global_modules \
nvm_has_system_node nvm_has_system_iojs \ 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_supports_source_options nvm_auto nvm_supports_xz \
nvm_echo nvm_err nvm_grep \ nvm_echo nvm_err nvm_grep \
nvm_has_colors nvm_process_parameters > /dev/null 2>&1 nvm_has_colors nvm_process_parameters > /dev/null 2>&1

View File

@ -1,5 +1,9 @@
#!/bin/sh #!/bin/sh
set -ex
. ../../nvm.sh . ../../nvm.sh
nvm alias test v0.1.2 nvm alias test v0.1.2
[ "$(cat ../../alias/test)" = "v0.1.2" ]
[ "$(cat "$(nvm_alias_path)/test")" = "v0.1.2" ]

View File

@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
set -ex
die () { echo $@ ; exit 1; } die () { echo $@ ; exit 1; }
. ../../nvm.sh . ../../nvm.sh
@ -7,4 +9,3 @@ die () { echo $@ ; exit 1; }
nvm deactivate 2>&1 nvm deactivate 2>&1
[ "$(nvm current)" = "system" ] || [ "$(nvm current)" = "none" ] || die '"nvm current" did not report "system" or "none" when deactivated' [ "$(nvm current)" = "system" ] || [ "$(nvm current)" = "none" ] || die '"nvm current" did not report "system" or "none" when deactivated'

View File

@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
set -ex
mkdir -p ../../v0.2.3 mkdir -p ../../v0.2.3
die () { echo $@ ; exit 1; } 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 [ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&2
. ../../nvm.sh . ../../nvm.sh
nvm use --delete-prefix v0.2.3 || die "Failed to activate v0.2.3" 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 "$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)" [ `expr "$NODE_PATH" : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "NODE_PATH should not contain (npm root -g)"

View File

@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
set -ex
die () { echo $@ ; cleanup ; exit 1; } die () { echo $@ ; cleanup ; exit 1; }
cleanup () { cleanup () {
rm -rf "${NVM_DIR}/v0.10.4" rm -rf "${NVM_DIR}/v0.10.4"
@ -11,22 +13,30 @@ mkdir "${NVM_DIR}/v0.10.4"
nvm deactivate >/dev/null 2>&1 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)" 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." EXPECTED_ERROR_MSG="If --reinstall-packages-from is provided, it must point to an installed version of node."
[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \ [ "~$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'" || 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="$(nvm install v0.10.5 --reinstall-packages-from=0.11 >/dev/null 2>&1; echo $?)"
[ "~$INSTALL_EXIT_CODE" = "~5" ] \ set -e
|| die ""nvm install --reinstall-packages-from" should exit with code 5 when given an uninstalled version, got $INSTALL_EXIT_CODE" [ $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)" 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." EXPECTED_ERROR_MSG="You can't reinstall global packages from the same version of node you're installing."
[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \ [ "~$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'" || 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="$(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" || die ""nvm install --reinstall-packages-from" should exit with code 4 when given the same version, got $INSTALL_EXIT_CODE"
cleanup cleanup

View File

@ -1,7 +1,13 @@
#!/bin/sh #!/bin/sh
set -ex
die () { echo $@ ; exit 1; } die () { echo $@ ; exit 1; }
. ../../nvm.sh . ../../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"

View File

@ -1,6 +1,13 @@
#!/bin/sh #!/bin/sh
echo v0.1.2 > ../../alias/test set -ex
ALIAS_PATH="../../alias"
echo v0.1.2 > "${ALIAS_PATH}/test"
. ../../nvm.sh . ../../nvm.sh
nvm unalias test nvm unalias test
! [ -e ../../alias/test ]
! [ -e "${ALIAS_PATH}/test" ]

View File

@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
set -ex
cd ../.. cd ../..
mkdir v0.0.1 mkdir v0.0.1
mkdir src/node-v0.0.1 mkdir src/node-v0.0.1

View File

@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
set -ex
cd ../.. cd ../..
mkdir v0.0.1 mkdir v0.0.1
mkdir src/node-v0.0.1 mkdir src/node-v0.0.1
@ -8,7 +10,7 @@ sudo touch v0.0.1/sudo
. ./nvm.sh . ./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" 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

View File

@ -1,12 +1,13 @@
#!/bin/sh #!/bin/sh
fail () { echo $@ ; exit 1; } set -ex
die () { echo $@ ; exit 1; }
. ../../nvm.sh . ../../nvm.sh
type nvm > /dev/null 2>&1 || fail "NVM not loaded" type nvm > /dev/null 2>&1 || die "nvm not loaded"
nvm unload nvm unload
type nvm > /dev/null 2>&1 && fail "NVM not unloaded" || exit 0 ! type nvm > /dev/null 2>&1 || die "nvm not unloaded"

View File

@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
set -ex
die () { echo $@ ; cleanup ; exit 1; } die () { echo $@ ; cleanup ; exit 1; }
cleanup() { cleanup() {
@ -10,20 +12,28 @@ cleanup() {
nvm_make_alias foo foo nvm_make_alias foo foo
set +ex # needed for stderr
OUTPUT="$(nvm use foo 2>&1)" OUTPUT="$(nvm use foo 2>&1)"
set -ex
EXPECTED_OUTPUT='The alias "foo" leads to an infinite loop. Aborting.' EXPECTED_OUTPUT='The alias "foo" leads to an infinite loop. Aborting.'
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \ [ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \
|| die "'nvm use foo' did not output >${EXPECTED_OUTPUT}<; got >${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 $?)" EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)"
set -ex
[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got ${EXIT_CODE}" [ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got ${EXIT_CODE}"
set +ex # needed for stderr
OUTPUT="$(nvm use --silent foo 2>&1)" OUTPUT="$(nvm use --silent foo 2>&1)"
set -ex
EXPECTED_OUTPUT='' EXPECTED_OUTPUT=''
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \ [ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \
|| die "'nvm use --silent foo' did not output >${EXPECTED_OUTPUT}<; got >${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 $?)" 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}" [ $EXIT_CODE -eq 8 ] || die "Expected exit code 8 from 'nvm use --silent foo'; got ${EXIT_CODE}"
cleanup cleanup

View File

@ -13,9 +13,7 @@ cleanup() {
rm -rf "$(nvm_version_path "iojs-${VERSION}")" rm -rf "$(nvm_version_path "iojs-${VERSION}")"
} }
set +ex # TODO
. ../../nvm.sh . ../../nvm.sh
set -ex
nvm deactivate || die "unable to deactivate; current: >$(nvm current)<" nvm deactivate || die "unable to deactivate; current: >$(nvm current)<"

View File

@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
set -ex
cleanup() { cleanup() {
unset -f nvm_has_system_node nvm_print_npm_version 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)'; } nvm_print_npm_version() { command printf ' (npm v1.2.3)'; }
EXPECTED_OUTPUT="Now using system version of node: $(node -v)$(nvm_print_npm_version)" 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)" OUTPUT="$(nvm use system 2>&1)"
set -x
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "Could not use system version of node. Got >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<" [ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "Could not use system version of node. Got >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"
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_has_system_node() { return 1; }
nvm_print_npm_version() { command printf ''; } nvm_print_npm_version() { command printf ''; }
EXPECTED_OUTPUT="System version of node not found." 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" nvm use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found"
EXPECTED_OUTPUT="" 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" 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 cleanup

View File

@ -1,11 +1,13 @@
#!/usr/bin/env bash #!/bin/sh
set -ex
export NVM_SYMLINK_CURRENT=true export NVM_SYMLINK_CURRENT=true
. ../../nvm.sh . ../../nvm.sh
rm -rf "${NVM_DIR}/v0.10.29" rm -rf "${NVM_DIR}/v0.10.29"
mkdir "${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" rmdir "${NVM_DIR}/v0.10.29"
if [ ! -L "${NVM_DIR}/current" ];then if [ ! -L "${NVM_DIR}/current" ];then
@ -22,7 +24,7 @@ fi
rm -rf "${NVM_DIR}/v0.11.13" rm -rf "${NVM_DIR}/v0.11.13"
mkdir "${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" rmdir "${NVM_DIR}/v0.11.13"
newLink="$(readlink "${NVM_DIR}/current")" newLink="$(readlink "${NVM_DIR}/current")"

View File

@ -1,4 +1,6 @@
#!/usr/bin/env bash #!/bin/sh
set -ex
. ../../nvm.sh . ../../nvm.sh
@ -8,17 +10,17 @@ TEST_COUNT=0
TEST_PASSED=0 TEST_PASSED=0
TEST_FAILED=0 TEST_FAILED=0
function registerExpectedSymlink() { registerExpectedSymlink() {
registerResult ${1} registerResult ${1}
} }
function registerExpectedNoSymlink() { registerExpectedNoSymlink() {
[ ${1} -ne 0 ] [ $1 -ne 0 ]
registerResult $? registerResult $?
} }
function registerResult() { registerResult() {
result=${1} result="${1}"
TEST_COUNT=$(($TEST_COUNT + 1)) TEST_COUNT=$(($TEST_COUNT + 1))
@ -27,19 +29,19 @@ function registerResult() {
|| TEST_FAILED=$(($TEST_FAILED + 1)) || TEST_FAILED=$(($TEST_FAILED + 1))
} }
function cleanup() { cleanup() {
rm -rf ../../${TEST_NODE_VERSION} rm -rf "${NVM_DIR}/${TEST_NODE_VERSION}"
rm -f ../../current rm -f "${NVM_DIR}/current"
} }
function runNvmUse() { runNvmUse() {
mkdir ../../${TEST_NODE_VERSION} mkdir "${NVM_DIR}/${TEST_NODE_VERSION}"
nvm use ${TEST_NODE_VERSION} > /dev/null 2>&1 nvm use --delete-prefix "${TEST_NODE_VERSION}" > /dev/null 2>&1
rmdir ../../${TEST_NODE_VERSION} rmdir "${NVM_DIR}/${TEST_NODE_VERSION}"
} }
function isCurrentSymlinkPresent() { isCurrentSymlinkPresent() {
[ -L ../../current ] [ -L "${NVM_DIR}/current" ]
} }
NVM_SYMLINK_CURRENT=false NVM_SYMLINK_CURRENT=false
@ -80,5 +82,4 @@ registerExpectedNoSymlink $?
cleanup 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

View File

@ -1,4 +1,7 @@
#!/bin/sh #!/bin/sh
set -ex
. ../../nvm.sh . ../../nvm.sh
nvm nvm

View File

@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
set -ex
set -- yes set -- yes
. ../../nvm.sh . ../../nvm.sh
[ "$1" = yes ] [ "$1" = yes ]

View File

@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
set -ex
( (
cd ../.. cd ../..

View File

@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
set -ex
( (
cd ../.. cd ../..

View File

@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
set -ex
# Remove temporary files # Remove temporary files
( (
cd ../.. cd ../..

View File

@ -1,5 +1,7 @@
#!/bin/sh #!/bin/sh
set -ex
( (
cd ../.. cd ../..