diff --git a/nvm.sh b/nvm.sh index db16abe7..58f2704d 100755 --- a/nvm.sh +++ b/nvm.sh @@ -3294,7 +3294,9 @@ nvm_print_implicit_alias() { esac local MINOR local STABLE + STABLE='' local UNSTABLE + UNSTABLE='' local MOD local NORMALIZED_VERSION diff --git a/test/fast/Listing versions/Running 'nvm ls' with nounset should not fail b/test/fast/Listing versions/Running 'nvm ls' with nounset should not fail index f6770917..90f0851d 100755 --- a/test/fast/Listing versions/Running 'nvm ls' with nounset should not fail +++ b/test/fast/Listing versions/Running 'nvm ls' with nounset should not fail @@ -6,19 +6,29 @@ die () { echo "$@" ; exit 1; } \. ../../../nvm.sh \. ../../common.sh -make_fake_node v0.12.34 || die 'fake v0.12.34 could not be made' - # Enable no unset variable set -u +# Nothing is installed, so there is no stable version to resolve to +output=$(nvm ls 2>&1 1>/dev/null || true) +test -z "${output}" || die "1: expected empty; got >${output}" + +make_fake_node v0.11.16 || die 'fake v0.11.16 could not be made' + +# Only an unstable version is installed, so `stable` still has nothing to resolve to +output=$(nvm ls 2>&1 1>/dev/null || true) +test -z "${output}" || die "2: expected empty; got >${output}" + +make_fake_node v0.12.34 || die 'fake v0.12.34 could not be made' + # Try an alias that does not exist output=$(nvm ls 99 2>&1 1>/dev/null || true) -test -z "${output}" || die "1: expected empty; got >${output}" +test -z "${output}" || die "3: expected empty; got >${output}" # Try a version that does not exist output=$(nvm ls 0.12.00 2>&1 1>/dev/null || true) -test -z "${output}" || die "2: expected empty; got >${output}" +test -z "${output}" || die "4: expected empty; got >${output}" # Try a version that does exist output=$(nvm ls 0.12.34 2>&1 1>/dev/null || true) -test -z "${output}" || die "3: expected empty; got >${output}" +test -z "${output}" || die "5: expected empty; got >${output}" diff --git a/test/fast/Unit tests/nvm commands ignore option variables set by the caller b/test/fast/Unit tests/nvm commands ignore option variables set by the caller index 08acd927..517e9daf 100755 --- a/test/fast/Unit tests/nvm commands ignore option variables set by the caller +++ b/test/fast/Unit tests/nvm commands ignore option variables set by the caller @@ -54,4 +54,19 @@ VERSION=v20.0.0 [ $? = 127 ] || die 'nvm use without a version or an .nvmrc should fail, rather than use an outer VERSION' unset VERSION +# with nothing installed, `nvm ls stable` has no version to resolve to, so an outer STABLE must not supply one +NVM_DIR="${TMP_DIR}/empty" +mkdir -p "${NVM_DIR}" +OUTPUT="$(nvm ls stable | tr -d ' \n')" +STABLE=v20.0.0 +OUTPUT_WITH_STABLE="$(nvm ls stable | tr -d ' \n')" +[ "_${OUTPUT_WITH_STABLE}" = "_${OUTPUT}" ] || die "nvm ls stable should ignore an outer STABLE; got >${OUTPUT_WITH_STABLE}< instead of >${OUTPUT}<" +unset STABLE + +# likewise for an outer UNSTABLE; `nvm ls unstable` can't show it, since the leaked version isn't installed either +UNSTABLE=v21.0.0 +OUTPUT="$(nvm_print_implicit_alias local unstable)" +[ "_${OUTPUT}" = '_N/A' ] || die "nvm_print_implicit_alias local unstable should ignore an outer UNSTABLE; got >${OUTPUT}<" +unset UNSTABLE + cleanup