From 42fedf6bc9b22917325ebff7d57c89d6fa8b1754 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Sun, 3 Jul 2016 08:37:03 -0700 Subject: [PATCH] [Tests] add some basic `nvm use --lts` tests --- nvm.sh | 2 +- ...\"nvm use --lts\" uses latest LTS version" | 22 +++++++++++++++++++ ...lts=foo\" uses latest \"foo\" LTS version" | 22 +++++++++++++++++++ test/slow/nvm use/setup_dir | 7 ++++++ test/slow/nvm use/teardown_dir | 12 +++++++--- 5 files changed, 61 insertions(+), 4 deletions(-) create mode 100755 "test/slow/nvm use/Running \"nvm use --lts\" uses latest LTS version" create mode 100755 "test/slow/nvm use/Running \"nvm use --lts=foo\" uses latest \"foo\" LTS version" diff --git a/nvm.sh b/nvm.sh index cd0d630..1f5f9be 100644 --- a/nvm.sh +++ b/nvm.sh @@ -610,7 +610,7 @@ nvm_resolve_alias() { local SEEN_ALIASES SEEN_ALIASES="$ALIAS" 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 break diff --git "a/test/slow/nvm use/Running \"nvm use --lts\" uses latest LTS version" "b/test/slow/nvm use/Running \"nvm use --lts\" uses latest LTS version" new file mode 100755 index 0000000..fc82a7b --- /dev/null +++ "b/test/slow/nvm use/Running \"nvm use --lts\" uses latest LTS version" @@ -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'" diff --git "a/test/slow/nvm use/Running \"nvm use --lts=foo\" uses latest \"foo\" LTS version" "b/test/slow/nvm use/Running \"nvm use --lts=foo\" uses latest \"foo\" LTS version" new file mode 100755 index 0000000..73bdd65 --- /dev/null +++ "b/test/slow/nvm use/Running \"nvm use --lts=foo\" uses latest \"foo\" LTS version" @@ -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'" diff --git a/test/slow/nvm use/setup_dir b/test/slow/nvm use/setup_dir index 20fa239..767ab55 100755 --- a/test/slow/nvm use/setup_dir +++ b/test/slow/nvm use/setup_dir @@ -6,6 +6,10 @@ mkdir -p "${NVM_DIR}/.nvm_use_bak" if [ -d "${NVM_DIR}/v*" ]; then mv "${NVM_DIR}/v*" "${NVM_DIR}/.nvm_use_bak/" 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 nvm install "v$VERSION" @@ -14,3 +18,6 @@ done for VERSION in "1.0.0" "1.0.1"; do nvm install "iojs-v$VERSION" done + +nvm_make_alias lts/testing 0.10.1 +nvm_make_alias 'lts/*' lts/testing diff --git a/test/slow/nvm use/teardown_dir b/test/slow/nvm use/teardown_dir index eeda337..a1543e5 100755 --- a/test/slow/nvm use/teardown_dir +++ b/test/slow/nvm use/teardown_dir @@ -10,7 +10,13 @@ for VERSION in "1.0.0" "1.0.1"; do nvm uninstall "iojs-v$VERSION" done -if [ -d ../../../.nvm_use_bak/* ]; then - mv ../../../.nvm_use_bak/* ../../../ +if [ -d "${NVM_DIR}/.nvm_use_bak/*" ]; then + 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 -rmdir ../../../.nvm_use_bak