2014-07-15 02:49:49 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
2016-07-07 15:00:59 +08:00
|
|
|
set -ex
|
|
|
|
|
2016-07-07 16:14:37 +08:00
|
|
|
cleanup() {
|
|
|
|
unset -f nvm_has_system_node nvm_print_npm_version
|
|
|
|
}
|
|
|
|
die() { echo $@ ; cleanup ; exit 1; }
|
2014-07-15 02:49:49 +08:00
|
|
|
|
2016-11-04 13:15:18 +08:00
|
|
|
\. ../../nvm.sh
|
2014-07-15 02:49:49 +08:00
|
|
|
|
|
|
|
nvm_has_system_node() { return 0; }
|
2016-07-07 16:14:37 +08:00
|
|
|
nvm_print_npm_version() { command printf ' (npm v1.2.3)'; }
|
|
|
|
|
2015-04-13 01:59:17 +08:00
|
|
|
EXPECTED_OUTPUT="Now using system version of node: $(node -v)$(nvm_print_npm_version)"
|
2016-07-07 15:00:59 +08:00
|
|
|
set +x # since stderr is needed
|
2016-07-07 16:14:37 +08:00
|
|
|
OUTPUT="$(nvm use system 2>&1)"
|
2016-07-07 15:00:59 +08:00
|
|
|
set -x
|
2016-07-07 16:14:37 +08:00
|
|
|
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "Could not use system version of node. Got >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"
|
2016-07-07 15:00:59 +08:00
|
|
|
|
2015-07-10 08:27:35 +08:00
|
|
|
EXPECTED_OUTPUT=""
|
2016-07-07 15:00:59 +08:00
|
|
|
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"
|
2014-07-15 02:49:49 +08:00
|
|
|
|
|
|
|
nvm_has_system_node() { return 1; }
|
2016-07-07 16:14:37 +08:00
|
|
|
nvm_print_npm_version() { command printf ''; }
|
|
|
|
|
2015-04-13 01:59:17 +08:00
|
|
|
EXPECTED_OUTPUT="System version of node not found."
|
2016-07-07 15:00:59 +08:00
|
|
|
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"
|
|
|
|
|
2014-07-15 02:49:49 +08:00
|
|
|
nvm use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found"
|
2015-07-10 08:27:35 +08:00
|
|
|
EXPECTED_OUTPUT=""
|
2016-07-07 15:00:59 +08:00
|
|
|
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"
|
2015-07-10 08:27:35 +08:00
|
|
|
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"
|
2014-07-15 02:49:49 +08:00
|
|
|
|
2016-07-07 16:14:37 +08:00
|
|
|
cleanup
|