add descriptive error message an replace test stub

This commit is contained in:
Tobias Gurtzick 2017-08-27 00:45:44 +02:00
parent 127eb414da
commit 4cdbdaead8
No known key found for this signature in database
GPG Key ID: 6C56E4E3D2EAC901
2 changed files with 3 additions and 4 deletions

1
nvm.sh
View File

@ -2112,6 +2112,7 @@ nvm_die_on_prefix() {
if [ -f "${npmrc}/.npmrc" ]; then if [ -f "${npmrc}/.npmrc" ]; then
NVM_NPM_PREFIX=$(grep ^prefix= "${npmrc}"/.npmrc | sed s/prefix=\\\(.*\\\)$/\\1/) NVM_NPM_PREFIX=$(grep ^prefix= "${npmrc}"/.npmrc | sed s/prefix=\\\(.*\\\)$/\\1/)
if ! [ -z "$NVM_NPM_PREFIX" ]; then if ! [ -z "$NVM_NPM_PREFIX" ]; then
nvm_err "Incompatible prefix setting prefix=${npmrc} found in the config file ${npmrc}/.npmrc"
break break
fi fi
fi fi

View File

@ -57,12 +57,10 @@ EXIT_CODE="$(NPM_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo >/dev/null 2>&1; echo
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'NPM_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo' did not error with '$EXPECTED_OUTPUT'; got '$OUTPUT'" [ "_$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'" [ "_$EXIT_CODE" = "_4" ] || die "'NPM_CONFIG_PREFIX=bar nvm_die_on_prefix 0 foo' did not exit with 4; got '$EXIT_CODE'"
npm() { sed() {
local args local args
args="$@" args="$@"
if [ "_$args" = "_config --loglevel=warn get prefix" ]; then
echo "./bad prefix" echo "./bad prefix"
fi
} }
OUTPUT="$(nvm_die_on_prefix 0 foo 2>&1)" OUTPUT="$(nvm_die_on_prefix 0 foo 2>&1)"
EXPECTED_OUTPUT="nvm is not compatible with the npm config \"prefix\" option: currently set to \"./bad prefix\" EXPECTED_OUTPUT="nvm is not compatible with the npm config \"prefix\" option: currently set to \"./bad prefix\"