[Fix] `ls-remote`/`install`: support `lts/-X` patterns in installs

Fixes #2692
Jordan Harband 2021-12-16 23:01:05 -08:00
parent aed1d732d7
commit c4c7690dec
No known key found for this signature in database
GPG Key ID: 9F6A681E35EF8B56
2 changed files with 28 additions and 3 deletions

5
nvm.sh
View File

@ -1465,6 +1465,11 @@ nvm_ls_remote_index_tab() {
$VERSION_LIST
EOF
if [ -n "${LTS-}" ]; then
LTS="$(nvm_normalize_lts "lts/${LTS}")"
LTS="${LTS#lts/}"
fi
VERSIONS="$({ command awk -v lts="${LTS-}" '{
if (!$1) { next }
if (lts && $10 ~ /^\-?$/) { next }

View File

@ -31,19 +31,39 @@ nvm_ls_remote_iojs() {
cat "$REMOTE_IOJS"
}
EXPECTED_OUTPUT_PATH="$PWD/mocks/nvm ls-remote.txt"
MOCKS_DIR="$PWD/mocks"
EXPECTED_OUTPUT_PATH="${MOCKS_DIR}/nvm ls-remote.txt"
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 $(echo ">$OUTPUT<") expected $(echo ">$EXPECTED_OUTPUT<")"
EXPECTED_OUTPUT_PATH="$PWD/mocks/nvm ls-remote lts.txt"
EXPECTED_OUTPUT_PATH="${MOCKS_DIR}/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"
EXPECTED_OUTPUT_PATH="${MOCKS_DIR}/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="${MOCKS_DIR}/nvm ls-remote lts.txt"
OUTPUT="$(nvm ls-remote "lts/-1" | 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<")"
LTS_NAMES_PATH="${MOCKS_DIR}/LTS_names.txt"
LTS_LIST="$(cat "${LTS_NAMES_PATH}" | tail -n +2)"
INDEX=1
for LTS in $LTS_LIST; do
ACTUAL="$(nvm ls-remote "lts/-${INDEX}" | sed 's/[ \t]*$//')"
MESSAGE="for lts/-${INDEX} / ${LTS}"
EXPECTED="$(nvm ls-remote "lts/${LTS}" | sed 's/[ \t]*$//')"
[ "${ACTUAL}" = "${EXPECTED}" ] || die "${MESSAGE}: expected >${EXPECTED}<, got >${ACTUAL}<"
INDEX=$(($INDEX + 1))
done
cleanup