2014-08-21 16:35:03 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
2015-01-02 14:45:46 +08:00
|
|
|
TEST_PWD=$(pwd)
|
|
|
|
TEST_DIR="$TEST_PWD/nvm_ls_current_tmp"
|
|
|
|
|
2015-02-22 18:16:55 +08:00
|
|
|
cleanup() { rm -rf "$TEST_DIR"; unset -f return_zero; alias node='node' ; unalias node; }
|
2016-11-07 03:34:36 +08:00
|
|
|
die () { echo "$@" ; cleanup ; exit 1; }
|
2014-08-21 16:35:03 +08:00
|
|
|
|
2016-11-04 13:15:18 +08:00
|
|
|
\. ../../../nvm.sh
|
2014-08-21 16:35:03 +08:00
|
|
|
|
|
|
|
return_zero () { return 0; }
|
|
|
|
|
2015-04-05 14:49:43 +08:00
|
|
|
if nvm_has_system_node || nvm_has_system_iojs; then
|
|
|
|
EXPECTED_SYSTEM_NODE="system"
|
|
|
|
else
|
|
|
|
EXPECTED_SYSTEM_NODE="none"
|
|
|
|
fi
|
|
|
|
[ "_$(nvm deactivate > /dev/null 2>&1 ; nvm_ls_current)" = "_$EXPECTED_SYSTEM_NODE" ] || die "when deactivated, did not return $EXPECTED_SYSTEM_NODE"
|
2014-08-21 16:35:03 +08:00
|
|
|
|
|
|
|
rm -rf "$TEST_DIR"
|
|
|
|
mkdir "$TEST_DIR"
|
2020-10-14 00:32:41 +08:00
|
|
|
# Ensure that the system version of which is used, not node_modules/.bin/which
|
|
|
|
ln -s "$(PATH=$(echo $PATH | tr ":" "\n" | grep -v "node_modules/.bin" | tr "\n" ":") command which which)" "$TEST_DIR/which"
|
2015-01-02 12:51:59 +08:00
|
|
|
ln -s "$(command which dirname)" "$TEST_DIR/dirname"
|
2017-11-22 01:53:46 +08:00
|
|
|
ln -s "$(command which printf)" "$TEST_DIR/printf"
|
2014-08-21 16:35:03 +08:00
|
|
|
|
|
|
|
[ "$(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"
|
2020-10-14 00:32:41 +08:00
|
|
|
echo "echo 'VERSION FOO!'" >> "$TEST_DIR/node"
|
2014-08-21 16:35:03 +08:00
|
|
|
chmod a+x "$TEST_DIR/node"
|
|
|
|
|
2020-10-14 00:32:41 +08:00
|
|
|
[ "$(PATH="$TEST_DIR" nvm_ls_current)" = "VERSION FOO!" ] || die 'when activated, did not return nvm node version'
|
2014-08-21 16:35:03 +08:00
|
|
|
|
2015-01-02 14:45:46 +08:00
|
|
|
alias node='node --harmony'
|
2020-10-14 00:32:41 +08:00
|
|
|
[ "$(PATH="$TEST_DIR" nvm_ls_current)" = "VERSION FOO!" ] || die 'when activated and node aliased, did not return nvm node version'
|
2014-08-21 16:35:03 +08:00
|
|
|
|
2015-01-02 14:45:46 +08:00
|
|
|
cleanup
|