Skip to content
Myr

Merge pull request #507 from creationix/nvm_ls_current_tests

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

nvm_ls_current tests

authored by Jordan Harband · committed by Jordan Harband · parents 5c7f088, 150aea2 · Browse files · 2 files+29 added−1 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+29 added−1 removed

  • tests:+28 added−0 removed
  • other:+1 added−1 removed

2 files+29 added−1 removed

added:test/fast/Unit tests/nvm_ls_current+28 added
1#!/bin/sh23die () { echo $@ ; exit 1; }45. ../../../nvm.sh67return_zero () { return 0; }89[ "$( (nvm deactivate > /dev/null 2>&1) && nvm_ls_current)" = "system" ] || die 'when deactivated, did not return "system"'1011TEST_PWD=$(pwd)12TEST_DIR="$TEST_PWD/nvm_ls_current_tmp"13rm -rf "$TEST_DIR"14mkdir "$TEST_DIR"15ln -s "$(which which)" "$TEST_DIR/which"16ln -s "$(which dirname)" "$TEST_DIR/dirname"1718[ "$(PATH="$TEST_DIR" nvm_ls_current)" = "none" ] || die 'when node not installed, nvm_ls_current did not return "none"'19[ "@$(PATH="$TEST_DIR" nvm_ls_current 2> /dev/stdout 1> /dev/null)@" = "@@" ] || die 'when node not installed, nvm_ls_current returned error output'2021echo "#!/bin/bash" > "$TEST_DIR/node"22echo "echo 'VERSION FOO!'" > "$TEST_DIR/node"23chmod a+x "$TEST_DIR/node"2425[ "$(alias nvm_tree_contains_path='return_zero' && PATH="$TEST_DIR" nvm_ls_current)" = "VERSION FOO!" ] || die 'when activated, did not return nvm node version'2627rm -rf "$TEST_DIR"28
modified:nvm.sh+1 added-1 removed
199 unmodified lines
200}201202nvm_ls_current() {203 local NODE_PATH204 NODE_PATH="$(which node)"204 NODE_PATH="$(which node 2> /dev/null)"205 if [ $? -ne 0 ]; then206 echo 'none'207 elif nvm_tree_contains_path "$NVM_DIR" "$NODE_PATH"; then208 echo `node -v 2>/dev/null`
603 unmodified lines