[Tests] clean up some tests
parent
54d58f88db
commit
940f850f8d
|
@ -3,28 +3,27 @@
|
||||||
die () { echo $@ ; cleanup ; exit 1; }
|
die () { echo $@ ; cleanup ; exit 1; }
|
||||||
|
|
||||||
cleanup() {
|
cleanup() {
|
||||||
rm -rf ../../alias/foo
|
rm -rf "$(nvm_alias_path)/foo"
|
||||||
}
|
}
|
||||||
|
|
||||||
. ../../nvm.sh
|
. ../../nvm.sh
|
||||||
|
|
||||||
echo 'foo' > ../../alias/foo
|
nvm_make_alias foo foo
|
||||||
|
|
||||||
OUTPUT="$(nvm use foo 2>&1)"
|
OUTPUT="$(nvm use foo 2>&1)"
|
||||||
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}<"
|
||||||
|
|
||||||
EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)"
|
EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)"
|
||||||
[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got $EXIT_CODE"
|
[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got ${EXIT_CODE}"
|
||||||
|
|
||||||
OUTPUT="$(nvm use --silent foo 2>&1)"
|
OUTPUT="$(nvm use --silent foo 2>&1)"
|
||||||
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}<"
|
||||||
|
|
||||||
EXIT_CODE="$(nvm use --silent foo 2>/dev/null ; echo $?)"
|
EXIT_CODE="$(nvm use --silent foo 2>/dev/null ; echo $?)"
|
||||||
[ "_$EXIT_CODE" = "_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
|
||||||
|
|
|
@ -1,18 +1,24 @@
|
||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
die () { echo $@ ; exit 1; }
|
cleanup() {
|
||||||
|
unset -f nvm_has_system_node nvm_print_npm_version
|
||||||
|
}
|
||||||
|
die() { echo $@ ; cleanup ; exit 1; }
|
||||||
|
|
||||||
. ../../nvm.sh
|
. ../../nvm.sh
|
||||||
|
|
||||||
nvm_has_system_node() { return 0; }
|
nvm_has_system_node() { return 0; }
|
||||||
nvm_print_npm_version() { return ' (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)"
|
||||||
[ "$(nvm use system 2>&1 | tail -1)" = "${EXPECTED_OUTPUT}" ] || die "Could not use system version of node"
|
OUTPUT="$(nvm use system 2>&1)"
|
||||||
|
[ "${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"
|
[ "$(nvm use --silent system 2>&1 | tail -1)" = "${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() { return ''; }
|
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"
|
[ "$(nvm use system 2>&1 | tail -1)" = "${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"
|
||||||
|
@ -20,3 +26,4 @@ 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"
|
[ "$(nvm use --silent system 2>&1 | tail -1)" = "${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
|
||||||
|
|
Loading…
Reference in New Issue