2014-10-22 16:48:16 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
2016-07-07 15:00:59 +08:00
|
|
|
set -ex
|
|
|
|
|
2016-11-07 03:34:36 +08:00
|
|
|
die () { echo "$@" ; cleanup ; exit 1; }
|
2014-10-22 16:48:16 +08:00
|
|
|
|
|
|
|
cleanup() {
|
2016-07-07 16:14:37 +08:00
|
|
|
rm -rf "$(nvm_alias_path)/foo"
|
2014-10-22 16:48:16 +08:00
|
|
|
}
|
|
|
|
|
2016-11-04 13:15:18 +08:00
|
|
|
\. ../../nvm.sh
|
2014-10-22 16:48:16 +08:00
|
|
|
|
2016-07-07 16:14:37 +08:00
|
|
|
nvm_make_alias foo foo
|
2014-10-22 16:48:16 +08:00
|
|
|
|
2016-07-07 15:00:59 +08:00
|
|
|
set +ex # needed for stderr
|
2014-10-22 16:48:16 +08:00
|
|
|
OUTPUT="$(nvm use foo 2>&1)"
|
2016-07-07 15:00:59 +08:00
|
|
|
set -ex
|
2014-10-22 16:48:16 +08:00
|
|
|
EXPECTED_OUTPUT='The alias "foo" leads to an infinite loop. Aborting.'
|
2016-07-07 16:14:37 +08:00
|
|
|
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \
|
|
|
|
|| die "'nvm use foo' did not output >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
|
2014-10-22 16:48:16 +08:00
|
|
|
|
2016-07-07 15:00:59 +08:00
|
|
|
set +ex # needed for stderr
|
2014-10-22 16:48:16 +08:00
|
|
|
EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)"
|
2016-07-07 15:00:59 +08:00
|
|
|
set -ex
|
2016-07-07 16:14:37 +08:00
|
|
|
[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got ${EXIT_CODE}"
|
2014-10-22 16:48:16 +08:00
|
|
|
|
2016-07-07 15:00:59 +08:00
|
|
|
set +ex # needed for stderr
|
2015-07-10 08:27:35 +08:00
|
|
|
OUTPUT="$(nvm use --silent foo 2>&1)"
|
2016-07-07 15:00:59 +08:00
|
|
|
set -ex
|
2015-07-10 08:27:35 +08:00
|
|
|
EXPECTED_OUTPUT=''
|
2016-07-07 16:14:37 +08:00
|
|
|
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] \
|
|
|
|
|| die "'nvm use --silent foo' did not output >${EXPECTED_OUTPUT}<; got >${OUTPUT}<"
|
2015-07-10 08:27:35 +08:00
|
|
|
|
2016-07-07 15:00:59 +08:00
|
|
|
set +ex # needed for stderr
|
2015-07-10 08:27:35 +08:00
|
|
|
EXIT_CODE="$(nvm use --silent foo 2>/dev/null ; echo $?)"
|
2016-07-07 15:00:59 +08:00
|
|
|
set -ex
|
2016-07-07 16:14:37 +08:00
|
|
|
[ $EXIT_CODE -eq 8 ] || die "Expected exit code 8 from 'nvm use --silent foo'; got ${EXIT_CODE}"
|
2014-10-22 16:48:16 +08:00
|
|
|
|
2016-07-07 16:14:37 +08:00
|
|
|
cleanup
|