From 5b77f7d0233b5be54484943c8976ad403308e4a6 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Wed, 1 Sep 2021 10:06:32 -0700 Subject: [PATCH] [Fix] `nvm ls`/`nvm alias`/`nvm_list_aliases`: zsh: when no LTS aliases, no error Fixes #2575. --- nvm.sh | 1 + .../nvm_list_aliases calls nvm_get_colors | 7 ++----- ..._aliases works with no LTS aliases present | 21 +++++++++++++++++++ 3 files changed, 24 insertions(+), 5 deletions(-) create mode 100755 test/fast/Aliases/nvm_list_aliases works with no LTS aliases present diff --git a/nvm.sh b/nvm.sh index 6985db0..15d1ba8 100644 --- a/nvm.sh +++ b/nvm.sh @@ -957,6 +957,7 @@ nvm_list_aliases() { NVM_ALIAS_DIR="$(nvm_alias_path)" command mkdir -p "${NVM_ALIAS_DIR}/lts" + nvm_is_zsh && unsetopt local_options nomatch ( local ALIAS_PATH for ALIAS_PATH in "${NVM_ALIAS_DIR}/${ALIAS}"*; do diff --git a/test/fast/Aliases/nvm_list_aliases calls nvm_get_colors b/test/fast/Aliases/nvm_list_aliases calls nvm_get_colors index d037cac..21e5127 100755 --- a/test/fast/Aliases/nvm_list_aliases calls nvm_get_colors +++ b/test/fast/Aliases/nvm_list_aliases calls nvm_get_colors @@ -2,10 +2,7 @@ \. ../../../nvm.sh -die () { - echo "nvm_list_aliases did not call nvm_get_colors. Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<" - exit 1 -} +die () { echo "$@" ; exit 1; } set -e @@ -22,4 +19,4 @@ OUTPUT=$(command printf %b $(nvm_list_aliases test-stable-1) | awk '{ print subs EXPECTED_OUTPUT=$(command printf %b "\033[0;95mtest-stable-1" | awk '{ print substr($0, 1, 19); }') echo "\033[0m" -[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die +[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "nvm_list_aliases did not call nvm_get_colors. Expected >${EXPECTED_OUTPUT}<; got >${OUTPUT}<" diff --git a/test/fast/Aliases/nvm_list_aliases works with no LTS aliases present b/test/fast/Aliases/nvm_list_aliases works with no LTS aliases present new file mode 100755 index 0000000..337d1d1 --- /dev/null +++ b/test/fast/Aliases/nvm_list_aliases works with no LTS aliases present @@ -0,0 +1,21 @@ +#!/bin/sh + +\. ../../../nvm.sh + +die () { + mv "$(nvm_alias_path)/_lts.bak" "$(nvm_alias_path)/lts" + echo "$@" + exit 1 +} + +set -e + +nvm_alias_path() { + nvm_echo "../../../alias" +} + +mv "$(nvm_alias_path)/lts" "$(nvm_alias_path)/_lts.bak" + +STDERR_OUTPUT="$(nvm_list_aliases 2>&1 >/dev/null)" + +[ -z "${STDERR_OUTPUT}" ] || die "expected no stderr output, got >${STDERR_OUTPUT}<"