Skip to content
Myr

[Fix] `nvm_die_on_prefix`: use directory comparison rather than string

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Dylan Armstrong · committed by Jordan Harband · parent 96069da · Browse files · 2 files+28 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+28 added−2 removed

  • tests:+27 added−1 removed
  • other:+1 added−1 removed

2 files+28 added−2 removed

modified:test/fast/Unit tests/nvm_die_on_prefix+27 added-1 removed
1#!/bin/sh23TEST_PWD=$(pwd)4TEST_DIR="$TEST_PWD/nvm_die_on_prefix_tmp"56cleanup () {7 rm -rf "$TEST_DIR"8 alias nvm_has='\nvm_has'9 alias npm='\npm'10 unset -f nvm_has npm11}8die () { echo "$@" ; exit 1; }1213die () {14 echo "$@";15 cleanup;16 exit 1;17}1819[ ! -e "$TEST_DIR" ] && mkdir "$TEST_DIR"2021\. ../../../nvm.sh2223OUTPUT="$(nvm_die_on_prefix 2>&1)"24EXPECTED_OUTPUT="First argument \"delete the prefix\" must be zero or one"
25 unmodified lines
50 if [ "_$args" = "_config --loglevel=warn get prefix" ]; then51 echo "$(nvm_version_dir new)/good prefix"52 fi53}5455OUTPUT="$(nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" 2>&1)"56[ -z "$OUTPUT" ] || die "'nvm_die_on_prefix' was not a noop when prefix is good; got '$OUTPUT'"5758mkdir -p "$(nvm_version_dir new)"59ln -s "$(nvm_version_dir new)" "$TEST_DIR/node"6061npm() {62 local args63 args="$@"64 if [ "_$args" = "_config --loglevel=warn get prefix" ]; then65 echo "$TEST_DIR/node"66 fi67}6869OUTPUT="$(nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" 2>&1)"70[ -z "$OUTPUT" ] || die "'nvm_die_on_prefix' was not a noop when directory is equivalent; got '$OUTPUT'"7172OUTPUT="$(PREFIX=bar nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" 2>&1)"73EXPECTED_OUTPUT='nvm is not compatible with the "PREFIX" environment variable: currently set to "bar"74Run `unset PREFIX` to unset it.'75EXIT_CODE="$(export PREFIX=bar ; nvm_die_on_prefix 0 foo "$(nvm_version_dir new)" >/dev/null 2>&1; echo $?)"
32 unmodified lines
modified:nvm.sh+1 added-1 removed
2229 unmodified lines
2230 local NVM_NPM_PREFIX2231 local NVM_OS2232 NVM_OS="$(nvm_get_os)"2233 NVM_NPM_PREFIX="$(npm config --loglevel=warn get prefix)"2234 if [ "${NVM_VERSION_DIR}" != "${NVM_NPM_PREFIX}" ] && ! (nvm_tree_contains_path "${NVM_VERSION_DIR}" "${NVM_NPM_PREFIX}" >/dev/null 2>&1); then2234 if [ ! "${NVM_VERSION_DIR}" -ef "${NVM_NPM_PREFIX}" ] && ! (nvm_tree_contains_path "${NVM_VERSION_DIR}" "${NVM_NPM_PREFIX}" >/dev/null 2>&1); then2235 if [ "_${NVM_DELETE_PREFIX}" = "_1" ]; then2236 npm config --loglevel=warn delete prefix2237 else2238 nvm deactivate >/dev/null 2>&1
1630 unmodified lines