From 0b5bb5ccd875d82e470568b6465d546346e37778 Mon Sep 17 00:00:00 2001 From: Sehrope Sarkuni Date: Tue, 14 May 2019 08:31:24 -0400 Subject: [PATCH] [Fix] `set -u`: Add default empty value for `$NVM_NO_ALIAS` Adds a default value for NVM_NO_ALIAS so that nvm ls does not error out when run in a bash nounset/-u (no unset vars) environment. --- nvm.sh | 2 +- ... \"nvm ls\" with nounset should not fail." | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100755 "test/fast/Listing versions/Running \"nvm ls\" with nounset should not fail." diff --git a/nvm.sh b/nvm.sh index c68db1e..744bb78 100644 --- a/nvm.sh +++ b/nvm.sh @@ -3161,7 +3161,7 @@ nvm() { esac shift done - if [ -n "${PATTERN-}" ] && [ -n "${NVM_NO_ALIAS}" ]; then + if [ -n "${PATTERN-}" ] && [ -n "${NVM_NO_ALIAS-}" ]; then nvm_err '`--no-alias` is not supported when a pattern is provided.' return 55 fi 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." new file mode 100755 index 0000000..d2bfe9e --- /dev/null +++ "b/test/fast/Listing versions/Running \"nvm ls\" with nounset should not fail." @@ -0,0 +1,23 @@ +#!/bin/sh + +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 + +# 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}" + +# 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}" + +# 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}"