Compare commits

..

2 Commits

Author SHA1 Message Date
Jordan Harband
5d977d8a8c
[Fix]: nvm ls, nvm alias, nvm install: error when an LTS name is invalid 2024-09-04 13:55:11 -07:00
Jordan Harband
3834cb709e
[Fix] nvm_normalize_lts: error when an LTS name is not lowercase 2024-09-04 13:54:41 -07:00
4 changed files with 23 additions and 38 deletions

8
nvm.sh
View File

@ -3425,20 +3425,17 @@ nvm() {
;;
esac
local EXIT_CODE
VERSION="$(NVM_VERSION_ONLY=true NVM_LTS="${LTS-}" nvm_remote_version "${provided_version}")"
EXIT_CODE="$?"
if [ "${VERSION}" = 'N/A' ] || [ $EXIT_CODE -ne 0 ]; then
if [ "${VERSION}" = 'N/A' ]; then
local LTS_MSG
local REMOTE_CMD
if [ "${LTS-}" = '*' ]; then
LTS_MSG='(with LTS filter) '
REMOTE_CMD='nvm ls-remote --lts'
elif [ -n "${LTS-}" ]; then
LTS_MSG="(with LTS filter '${LTS}') "
REMOTE_CMD="nvm ls-remote --lts=${LTS}"
nvm_err "Version with LTS filter '${LTS}' not found - try \`${REMOTE_CMD}\` to browse available versions."
return 3
else
REMOTE_CMD='nvm ls-remote'
fi
@ -3503,6 +3500,7 @@ nvm() {
FLAVOR="$(nvm_node_prefix)"
fi
local EXIT_CODE
EXIT_CODE=0
if nvm_is_version_installed "${VERSION}"; then

View File

@ -5,31 +5,18 @@ 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_download() {
if [ "$*" = "-L -s $(nvm_get_mirror node std)/index.tab -o -" ]; then
cat "${REMOTE}"
elif [ "$*" = "-L -s $(nvm_get_mirror iojs)/index.tab -o -" ]; then
cat "${REMOTE_IOJS}"
else
nvm_err "unknown nvm_download call: $*"
return 42
fi
nvm_ls_remote_iojs() {
cat "${REMOTE_IOJS}"
}
nvm_install_binary() {
return 42
}
nvm_install_source() {
return 42
}
ACTUAL="$(nvm install lts/ARGON 2>&1)"
EXIT_CODE=$?
[ $EXIT_CODE -eq 3 ] || die "Expected exit code of 3, got ${EXIT_CODE}"
if [ $? -ne 3 ]; then
die "Expected exit code of 3, got $?"
fi
EXPECTED="LTS names must be lowercase
Version with LTS filter 'ARGON' not found - try \`nvm ls-remote --lts=ARGON\` to browse available versions."
EXPECTED='LTS names must be lowercase'
[ "${ACTUAL}" = "${EXPECTED}" ] || die "Expected >${EXPECTED}<, got >${ACTUAL}<"

View File

@ -1,5 +1,7 @@
#!/bin/sh
set -e
die () { echo "$@" ; cleanup ; exit 1; }
cleanup() {
@ -54,14 +56,6 @@ printf '%s\n' "${LTS_LIST}" | while IFS= read -r LTS; do
INDEX=$(($INDEX + 1))
done
OUTPUT="$(nvm ls-remote lts/ARGON 2>&1)"
EXIT_CODE=$?
[ $EXIT_CODE -eq 3 ] || die "nvm ls-remote lts/ARGON did not exit 3, got '${EXIT_CODE}'"
EXPECTED_OUTPUT="LTS names must be lowercase
N/A"
[ "_${OUTPUT}" = "_${EXPECTED_OUTPUT}" ] || die "nvm ls-remote lts/ARGON did not output expected error message; got >${OUTPUT}< expected >${EXPECTED_OUTPUT}<"
REMOTE="${PWD}/mocks/nvm_ls_remote.txt"
nvm_ls_remote() {
cat "${REMOTE}"
@ -76,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

View File

@ -10,16 +10,16 @@ nvm unalias default >/dev/null 2>&1 || die 'unable to unalias default'
set +ex # needed for stderr
OUTPUT="$(nvm install --lts 3 2>&1)"
EXIT_CODE="$?"
set -ex
EXIT_CODE="$(nvm install --lts 3 >/dev/null 2>&1 && echo $? || echo $?)"
EXPECTED_OUTPUT="Version '3' (with LTS filter) not found - try \`nvm ls-remote --lts\` to browse available versions."
[ "${EXIT_CODE}" = 3 ] || die "\`nvm install --lts 3\` did not exit with 3, got >${EXIT_CODE}<"
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm install --lts 3\` output >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"
set +ex # needed for stderr
OUTPUT="$(nvm install --lts=argon 3 2>&1)"
EXIT_CODE="$?"
set -x
set -ex
EXIT_CODE="$(nvm install --lts=argon 3 >/dev/null 2>&1 && echo $? || echo $?)"
EXPECTED_OUTPUT="Version '3' (with LTS filter 'argon') not found - try \`nvm ls-remote --lts=argon\` to browse available versions."
[ "${EXIT_CODE}" = 3 ] || die "\`nvm install --lts=argon 3\` did not exit with 3, got >${EXIT_CODE}<"
[ "${OUTPUT}" = "${EXPECTED_OUTPUT}" ] || die "\`nvm install --lts=argon 3\` output >${OUTPUT}<, expected >${EXPECTED_OUTPUT}<"