2015-09-21 19:47:30 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
cleanup () {
|
|
|
|
alias nvm_has='\nvm_has'
|
|
|
|
alias npm='\npm'
|
|
|
|
unset -f nvm_has npm
|
|
|
|
}
|
2016-11-07 03:34:36 +08:00
|
|
|
die () { echo "$@" ; exit 1; }
|
2015-09-21 19:47:30 +08:00
|
|
|
|
2016-11-04 13:15:18 +08:00
|
|
|
\. ../../../nvm.sh
|
2015-09-21 19:47:30 +08:00
|
|
|
|
|
|
|
OUTPUT="$(nvm_die_on_prefix 2>&1)"
|
|
|
|
EXPECTED_OUTPUT="First argument \"delete the prefix\" must be zero or one"
|
|
|
|
EXIT_CODE="$(nvm_die_on_prefix >/dev/null 2>&1; echo $?)"
|
|
|
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix' did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
|
|
|
[ "_$EXIT_CODE" = "_1" ] || die "'nvm_die_on_prefix' did not exit with 1; got "$EXIT_CODE""
|
|
|
|
|
|
|
|
OUTPUT="$(nvm_die_on_prefix 2 2>&1)"
|
|
|
|
EXPECTED_OUTPUT="First argument \"delete the prefix\" must be zero or one"
|
|
|
|
EXIT_CODE="$(nvm_die_on_prefix 2 >/dev/null 2>&1; echo $?)"
|
|
|
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 2' did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
|
|
|
[ "_$EXIT_CODE" = "_1" ] || die "'nvm_die_on_prefix' did not exit with 1; got "$EXIT_CODE""
|
|
|
|
|
|
|
|
OUTPUT="$(nvm_die_on_prefix 0 2>&1)"
|
2020-08-24 13:50:41 +08:00
|
|
|
EXPECTED_OUTPUT='Second argument "nvm command", and third argument "nvm version dir", must both be nonempty'
|
2015-09-21 19:47:30 +08:00
|
|
|
EXIT_CODE="$(nvm_die_on_prefix 0 >/dev/null 2>&1; echo $?)"
|
|
|
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0' did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
|
|
|
[ "_$EXIT_CODE" = "_2" ] || die "'nvm_die_on_prefix 0' did not exit with 2; got '$EXIT_CODE'"
|
|
|
|
|
|
|
|
nvm_has() { return 1; } # ie, npm is not installed
|
2020-08-24 13:50:41 +08:00
|
|
|
OUTPUT="$(nvm_die_on_prefix 0 version_dir foo 2>&1)"
|
2015-09-21 19:47:30 +08:00
|
|
|
[ -z "$OUTPUT" ] || die "nvm_die_on_prefix was not a noop when nvm_has returns 1, got '$OUTPUT'"
|
|
|
|
|
|
|
|
nvm_has() { return 0; }
|
|
|
|
|
|
|
|
npm() {
|
|
|
|
local args
|
|
|
|
args="$@"
|
2016-09-19 04:39:50 +08:00
|
|
|
if [ "_$args" = "_config --loglevel=warn get prefix" ]; then
|
2015-09-21 19:47:30 +08:00
|
|
|
echo "$(nvm_version_dir new)/good prefix"
|
|
|
|
fi
|
|
|
|
}
|
2020-08-24 13:50:41 +08:00
|
|
|
OUTPUT="$(nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" 2>&1)"
|
2015-09-21 19:47:30 +08:00
|
|
|
[ -z "$OUTPUT" ] || die "'nvm_die_on_prefix' was not a noop when prefix is good; got '$OUTPUT'"
|
|
|
|
|
2020-08-24 13:50:41 +08:00
|
|
|
OUTPUT="$(PREFIX=bar nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" 2>&1)"
|
2015-09-21 19:47:37 +08:00
|
|
|
EXPECTED_OUTPUT='nvm is not compatible with the "PREFIX" environment variable: currently set to "bar"
|
|
|
|
Run `unset PREFIX` to unset it.'
|
2020-08-24 13:50:41 +08:00
|
|
|
EXIT_CODE="$(export PREFIX=bar ; nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" >/dev/null 2>&1; echo $?)"
|
2015-09-21 19:47:37 +08:00
|
|
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'PREFIX=bar nvm_die_on_prefix 0 foo' did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
|
|
|
[ "_$EXIT_CODE" = "_3" ] || die "'PREFIX=bar nvm_die_on_prefix 0 foo' did not exit with 3; got '$EXIT_CODE'"
|
|
|
|
|
2020-08-24 13:50:41 +08:00
|
|
|
OUTPUT="$(export NPM_CONFIG_PREFIX=bar ; nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" 2>&1)"
|
2015-09-23 21:25:55 +08:00
|
|
|
EXPECTED_OUTPUT='nvm is not compatible with the "NPM_CONFIG_PREFIX" environment variable: currently set to "bar"
|
|
|
|
Run `unset NPM_CONFIG_PREFIX` to unset it.'
|
2020-08-24 13:50:41 +08:00
|
|
|
EXIT_CODE="$(export NPM_CONFIG_PREFIX=bar ; nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" >/dev/null 2>&1; echo $?)"
|
2015-09-23 21:25:55 +08:00
|
|
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'NPM_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo' did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
|
|
|
[ "_$EXIT_CODE" = "_4" ] || die "'NPM_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo' did not exit with 4; got '$EXIT_CODE'"
|
|
|
|
|
2020-08-24 13:50:41 +08:00
|
|
|
OUTPUT="$(export npm_CONFIG_PREFIX=bar ; nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" 2>&1)"
|
2017-12-05 16:00:18 +08:00
|
|
|
EXPECTED_OUTPUT='nvm is not compatible with the "npm_CONFIG_PREFIX" environment variable: currently set to "bar"
|
|
|
|
Run `unset npm_CONFIG_PREFIX` to unset it.'
|
2020-08-24 13:50:41 +08:00
|
|
|
EXIT_CODE="$(export npm_CONFIG_PREFIX=bar ; nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" >/dev/null 2>&1; echo $?)"
|
2017-12-05 16:00:18 +08:00
|
|
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'npm_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo' did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'"
|
|
|
|
[ "_$EXIT_CODE" = "_4" ] || die "'npm_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo' did not exit with 4; got '$EXIT_CODE'"
|
|
|
|
|
2015-09-21 19:47:30 +08:00
|
|
|
npm() {
|
|
|
|
local args
|
|
|
|
args="$@"
|
2016-09-19 04:39:50 +08:00
|
|
|
if [ "_$args" = "_config --loglevel=warn get prefix" ]; then
|
2015-09-21 19:47:30 +08:00
|
|
|
echo "./bad prefix"
|
|
|
|
fi
|
|
|
|
}
|
2020-08-24 13:50:41 +08:00
|
|
|
OUTPUT="$(nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" 2>&1)"
|
2015-09-21 19:47:30 +08:00
|
|
|
EXPECTED_OUTPUT="nvm is not compatible with the npm config \"prefix\" option: currently set to \"./bad prefix\"
|
|
|
|
Run \`npm config delete prefix\` or \`foo\` to unset it."
|
2020-08-24 13:50:41 +08:00
|
|
|
EXIT_CODE="$(nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" >/dev/null 2>&1; echo $?)"
|
2015-09-21 19:47:30 +08:00
|
|
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_die_on_prefix 0 foo' did not error with '$EXPECTED_OUTPUT' with bad prefix set; got '$OUTPUT'"
|
2015-09-23 21:25:55 +08:00
|
|
|
[ "_$EXIT_CODE" = "_10" ] || die "'nvm_die_on_prefix 0 foo' did not exit with 10 with bad prefix set; got '$EXIT_CODE'"
|
2015-09-21 19:47:30 +08:00
|
|
|
|
|
|
|
cleanup
|