diff --git a/nvm.sh b/nvm.sh index ce8bba56a1..2c37a5c901 100755 --- a/nvm.sh +++ b/nvm.sh @@ -1253,7 +1253,9 @@ nvm_alias() { nvm_err 'An alias is required.' return 1 fi - ALIAS="$(nvm_normalize_lts "${ALIAS}")" + if ! ALIAS="$(nvm_normalize_lts "${ALIAS}")"; then + return $? + fi if [ -z "${ALIAS}" ]; then return 2 @@ -1656,7 +1658,9 @@ $VERSION_LIST EOF if [ -n "${LTS-}" ]; then - LTS="$(nvm_normalize_lts "lts/${LTS}")" + if ! LTS="$(nvm_normalize_lts "lts/${LTS}")"; then + return $? + fi LTS="${LTS#lts/}" fi diff --git a/test/fast/Unit tests/nvm install with nonlowercase LTS name b/test/fast/Unit tests/nvm install with nonlowercase LTS name new file mode 100755 index 0000000000..c79b4a0f99 --- /dev/null +++ b/test/fast/Unit tests/nvm install with nonlowercase LTS name @@ -0,0 +1,22 @@ +#!/bin/sh + +die () { echo "$@" ; exit 1; } + +\. ../../../nvm.sh + +REMOTE="${PWD}/mocks/nvm_ls_remote.txt" +nvm_ls_remote() { + cat "${REMOTE}" +} +REMOTE_IOJS="${PWD}/mocks/nvm_ls_remote_iojs.txt" +nvm_ls_remote_iojs() { + cat "${REMOTE_IOJS}" +} +ACTUAL="$(nvm install -b "${VERSION}" 2>&1)" +if [ $? -ne 3 ]; then + die "Expected exit code of 3, got $?" +fi + +EXPECTED='LTS names must be lowercase' + +[ "${ACTUAL}" = "${EXPECTED}" ] || die "Expected >${EXPECTED}<, got >${ACTUAL}<" diff --git a/test/fast/Unit tests/nvm ls-remote b/test/fast/Unit tests/nvm ls-remote index 0c65bfb57f..5b1a4daa98 100755 --- a/test/fast/Unit tests/nvm ls-remote +++ b/test/fast/Unit tests/nvm ls-remote @@ -70,4 +70,10 @@ OUTPUT="$(nvm ls-remote | sed 's/[ \t]*$//')" EXPECTED_OUTPUT="$(cat "${EXPECTED_OUTPUT_PATH}" | sed 's/[ \t]*$//' )" [ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "bare nvm ls-remote did not output expected sorted versions; got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<" +if OUTPUT="$(nvm ls-remote lts/ARGON 2>&1)"; then + die "nvm ls-remote lts/ARGON did not exit nonzero, got '$?'" +fi +EXPECTED_OUTPUT='LTS names must be lowercase' +[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "nvm ls-remote lts/ARGON did not output expected error message; got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<" + cleanup