Merge pull request #507 from creationix/nvm_ls_current_tests

nvm_ls_current tests
master
Jordan Harband 2014-08-22 01:59:14 -07:00
commit fd9e01b7e6
2 changed files with 29 additions and 1 deletions

2
nvm.sh
View File

@ -201,7 +201,7 @@ nvm_binary_available() {
nvm_ls_current() { nvm_ls_current() {
local NODE_PATH local NODE_PATH
NODE_PATH="$(which node)" NODE_PATH="$(which node 2> /dev/null)"
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo 'none' echo 'none'
elif nvm_tree_contains_path "$NVM_DIR" "$NODE_PATH"; then elif nvm_tree_contains_path "$NVM_DIR" "$NODE_PATH"; then

View File

@ -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"