[Fix] `ls-remote`/`install`: properly handle `lts/x` patterns

Jordan Harband 2021-12-16 22:58:06 -08:00
parent 0b4cd8df6c
commit aed1d732d7
No known key found for this signature in database
GPG Key ID: 9F6A681E35EF8B56
2 changed files with 19 additions and 4 deletions

10
nvm.sh
View File

@ -3812,8 +3812,14 @@ nvm() {
PATTERN="${1-}" PATTERN="${1-}"
if [ -z "${NVM_LTS-}" ]; then if [ -z "${NVM_LTS-}" ]; then
case "${PATTERN}" in case "${PATTERN}" in
'lts/*') NVM_LTS='*' ;; 'lts/*')
lts/*) NVM_LTS="${PATTERN##lts/}" ;; NVM_LTS='*'
PATTERN=''
;;
lts/*)
NVM_LTS="${PATTERN##lts/}"
PATTERN=''
;;
esac esac
fi fi
fi fi

View File

@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
set -ex set -e
die () { echo "$@" ; cleanup ; exit 1; } die () { echo "$@" ; cleanup ; exit 1; }
@ -32,9 +32,18 @@ nvm_ls_remote_iojs() {
} }
EXPECTED_OUTPUT_PATH="$PWD/mocks/nvm ls-remote.txt" EXPECTED_OUTPUT_PATH="$PWD/mocks/nvm ls-remote.txt"
OUTPUT="$(nvm ls-remote | sed 's/[ \t]*$//')" OUTPUT="$(nvm ls-remote | sed 's/[ \t]*$//')"
EXPECTED_OUTPUT="$(cat "$EXPECTED_OUTPUT_PATH" | 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 $(echo ">$OUTPUT<") expected $(echo ">$EXPECTED_OUTPUT<")" [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "bare nvm ls-remote did not output expected sorted versions; got $(echo ">$OUTPUT<") expected $(echo ">$EXPECTED_OUTPUT<")"
EXPECTED_OUTPUT_PATH="$PWD/mocks/nvm ls-remote lts.txt"
OUTPUT="$(nvm ls-remote --lts="*" | sed 's/[ \t]*$//')"
EXPECTED_OUTPUT="$(cat "$EXPECTED_OUTPUT_PATH" | sed 's/[ \t]*$//' )"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm ls-remote --lts=* did not output expected sorted versions; got $(echo ">$OUTPUT<") expected $(echo ">$EXPECTED_OUTPUT<")"
EXPECTED_OUTPUT_PATH="$PWD/mocks/nvm ls-remote lts.txt"
OUTPUT="$(nvm ls-remote "lts/*" | sed 's/[ \t]*$//')"
EXPECTED_OUTPUT="$(cat "$EXPECTED_OUTPUT_PATH" | sed 's/[ \t]*$//' )"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm ls-remote lts/* did not output expected sorted versions; got $(echo ">$OUTPUT<") expected $(echo ">$EXPECTED_OUTPUT<")"
cleanup cleanup