[Tests] add some basic `nvm use --lts` tests

Jordan Harband 2016-07-03 08:37:03 -07:00
parent 4c010f442e
commit 42fedf6bc9
No known key found for this signature in database
GPG Key ID: 64A196AEE0916D55
5 changed files with 61 additions and 4 deletions

2
nvm.sh
View File

@ -610,7 +610,7 @@ nvm_resolve_alias() {
local SEEN_ALIASES local SEEN_ALIASES
SEEN_ALIASES="$ALIAS" SEEN_ALIASES="$ALIAS"
while true; do while true; do
ALIAS_TEMP="$(nvm_alias "$ALIAS" 2> /dev/null)" ALIAS_TEMP="$(nvm_alias "$ALIAS" 2> /dev/null || echo)"
if [ -z "$ALIAS_TEMP" ]; then if [ -z "$ALIAS_TEMP" ]; then
break break

View File

@ -0,0 +1,22 @@
#!/bin/sh
set -ex
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
nvm deactivate >/dev/null 2>&1 || die 'deactivate failed'
nvm use --lts || die 'nvm use --lts failed'
OUTPUT="$(nvm current)"
EXPECTED_OUTPUT="$(nvm_resolve_alias 'lts/*')"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|| die "'nvm use --lts' + 'nvm current' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
OUTPUT="$(nvm use --silent --lts)"
EXPECTED_OUTPUT=""
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|| die "'nvm use --silent --lts' output was not silenced '$EXPECTED_OUTPUT'; got '$OUTPUT'"

View File

@ -0,0 +1,22 @@
#!/bin/sh
set -ex
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
nvm deactivate 2>&1 >/dev/null || die 'deactivate failed'
nvm use --lts=testing || die 'nvm use --lts=testing failed'
OUTPUT="$(nvm current)"
EXPECTED_OUTPUT="$(nvm_resolve_alias 'lts/testing')"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|| die "'nvm use --lts=testing' + 'nvm current' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
OUTPUT="$(nvm use --silent --lts=testing)"
EXPECTED_OUTPUT=""
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
|| die "'nvm use --silent --lts=testing' output was not silenced '$EXPECTED_OUTPUT'; got '$OUTPUT'"

View File

@ -6,6 +6,10 @@ mkdir -p "${NVM_DIR}/.nvm_use_bak"
if [ -d "${NVM_DIR}/v*" ]; then if [ -d "${NVM_DIR}/v*" ]; then
mv "${NVM_DIR}/v*" "${NVM_DIR}/.nvm_use_bak/" mv "${NVM_DIR}/v*" "${NVM_DIR}/.nvm_use_bak/"
fi fi
mkdir -p "${NVM_DIR}/.nvm_use_lts_alias_bak"
if [ -d "${NVM_DIR}/alias/lts" ]; then
mv "${NVM_DIR}/alias/lts/*" "${NVM_DIR}/.nvm_use_lts_alias_bak/"
fi
for VERSION in "0.8.7" "0.9.1" "0.10.1" "0.11.1"; do for VERSION in "0.8.7" "0.9.1" "0.10.1" "0.11.1"; do
nvm install "v$VERSION" nvm install "v$VERSION"
@ -14,3 +18,6 @@ done
for VERSION in "1.0.0" "1.0.1"; do for VERSION in "1.0.0" "1.0.1"; do
nvm install "iojs-v$VERSION" nvm install "iojs-v$VERSION"
done done
nvm_make_alias lts/testing 0.10.1
nvm_make_alias 'lts/*' lts/testing

View File

@ -10,7 +10,13 @@ for VERSION in "1.0.0" "1.0.1"; do
nvm uninstall "iojs-v$VERSION" nvm uninstall "iojs-v$VERSION"
done done
if [ -d ../../../.nvm_use_bak/* ]; then if [ -d "${NVM_DIR}/.nvm_use_bak/*" ]; then
mv ../../../.nvm_use_bak/* ../../../ mv "${NVM_DIR}/.nvm_use_bak/*" "${NVM_DIR}"
rmdir "${NVM_DIR}/.nvm_use_bak"
fi
if [ -d "${NVM_DIR}/.nvm_use_lts_alias_bak" ]; then
rm -rf "${NVM_DIR}/alias/lts/*"
mv "${NVM_DIR}/.nvm_use_lts_alias_bak/*" "${NVM_DIR}/alias/lts/"
rmdir "${NVM_DIR}/.nvm_use_lts_alias_bak"
fi fi
rmdir ../../../.nvm_use_bak