From 273f9d497a1bc9f758931cff0f9b41970ee34b26 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 21 Aug 2014 01:35:03 -0700 Subject: [PATCH 1/2] Adding unit tests for nvm_ls_current. Relates to #487. --- test/fast/Unit tests/nvm_ls_current | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 test/fast/Unit tests/nvm_ls_current diff --git a/test/fast/Unit tests/nvm_ls_current b/test/fast/Unit tests/nvm_ls_current new file mode 100755 index 0000000..c475157 --- /dev/null +++ b/test/fast/Unit tests/nvm_ls_current @@ -0,0 +1,28 @@ +#!/bin/sh + +die () { echo $@ ; exit 1; } + +. ../../../nvm.sh + +return_zero () { return 0; } + +[ "$( (nvm deactivate > /dev/null 2>&1) && nvm_ls_current)" = "system" ] || die 'when deactivated, did not return "system"' + +TEST_PWD=$(pwd) +TEST_DIR="$TEST_PWD/nvm_ls_current_tmp" +rm -rf "$TEST_DIR" +mkdir "$TEST_DIR" +ln -s "$(which which)" "$TEST_DIR/which" +ln -s "$(which dirname)" "$TEST_DIR/dirname" + +[ "$(PATH="$TEST_DIR" nvm_ls_current)" = "none" ] || die 'when node not installed, nvm_ls_current did not return "none"' +[ "@$(PATH="$TEST_DIR" nvm_ls_current 2> /dev/stdout 1> /dev/null)@" = "@@" ] || die 'when node not installed, nvm_ls_current returned error output' + +echo "#!/bin/bash" > "$TEST_DIR/node" +echo "echo 'VERSION FOO!'" > "$TEST_DIR/node" +chmod a+x "$TEST_DIR/node" + +[ "$(alias nvm_tree_contains_path='return_zero' && PATH="$TEST_DIR" nvm_ls_current)" = "VERSION FOO!" ] || die 'when activated, did not return nvm node version' + +rm -rf "$TEST_DIR" + From 150aea21ec8ebff2ebb1cc2153f8f69e5aad1caa Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 21 Aug 2014 16:51:24 -0700 Subject: [PATCH 2/2] Fixes #487. --- nvm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index d588e1a..500e472 100644 --- a/nvm.sh +++ b/nvm.sh @@ -201,7 +201,7 @@ nvm_binary_available() { nvm_ls_current() { local NODE_PATH - NODE_PATH="$(which node)" + NODE_PATH="$(which node 2> /dev/null)" if [ $? -ne 0 ]; then echo 'none' elif nvm_tree_contains_path "$NVM_DIR" "$NODE_PATH"; then