diff --git a/test/fast/Unit tests/nvm_alias LTS-N b/test/fast/Unit tests/nvm_alias LTS-N index b110117a52..bbc634323f 100755 --- a/test/fast/Unit tests/nvm_alias LTS-N +++ b/test/fast/Unit tests/nvm_alias LTS-N @@ -5,14 +5,26 @@ die () { echo "$@" ; cleanup ; exit 1; } cleanup() { unset -f nvm_download + rm -rf "${NVM_DIR}/alias/lts" + mv "${NVM_DIR}/alias/lts-backup" "${NVM_DIR}/alias/lts" } \. ../../../nvm.sh -set -ex - MOCKS_DIR="${PWD}/mocks" +LTS_NAMES_PATH="${MOCKS_DIR}/LTS_names.txt" +LTS_LIST="$(cat "${LTS_NAMES_PATH}" | tail -n +2)" + +mv "${NVM_DIR}/alias/lts" "${NVM_DIR}/alias/lts-backup" ||: +mkdir -p "${NVM_DIR}/alias/lts" + +for LTS in $LTS_LIST; do + cp "${NVM_DIR}/alias/lts-backup/${LTS}" "${NVM_DIR}/alias/lts/" +done + +set -ex + # sample output at the time the test was written TAB_PATH="${MOCKS_DIR}/nodejs.org-dist-index.tab" nvm_download() { @@ -21,8 +33,6 @@ nvm_download() { nvm_ls_remote >/dev/null || die "nvm_ls_remote_failed?!" -LTS_NAMES_PATH="${MOCKS_DIR}/LTS_names.txt" - N=0 while IFS= read -r LTS; do if [ $N -gt 0 ]; then diff --git a/test/fast/Unit tests/nvm_normalize_lts b/test/fast/Unit tests/nvm_normalize_lts index 8f4f20db78..8f68421617 100755 --- a/test/fast/Unit tests/nvm_normalize_lts +++ b/test/fast/Unit tests/nvm_normalize_lts @@ -2,12 +2,29 @@ cleanup() { unset nvm_get_os + rm -rf "${NVM_DIR}/alias/lts" + mv "${NVM_DIR}/alias/lts-backup" "${NVM_DIR}/alias/lts" } die () { cleanup; echo "$@" ; exit 1; } \. ../../../nvm.sh +MOCKS_DIR="../Unit tests/mocks" + +LTS_NAMES_PATH="${MOCKS_DIR}/LTS_names.txt" +LTS_LIST="$(cat "${LTS_NAMES_PATH}" | tail -n +2)" + +STAR="$(cat "${MOCKS_DIR}/lts-star.txt")" + +mv "${NVM_DIR}/alias/lts" "${NVM_DIR}/alias/lts-backup" ||: +mkdir -p "${NVM_DIR}/alias/lts" + +printf '%s\n' "${LTS_LIST}" | while IFS= read -r LTS; do + cp "${NVM_DIR}/alias/lts-backup/${LTS}" "${NVM_DIR}/alias/lts/" +done +echo "${STAR}" > "${NVM_DIR}/alias/lts/*" + ACTUAL="$(nvm_normalize_lts "foo")" EXPECTED='foo' [ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<" @@ -20,15 +37,12 @@ if ACTUAL="$(nvm_normalize_lts lts/ARGON)"; then die "expected failure, got >${ACTUAL}<" fi -MOCKS_DIR="../Unit tests/mocks" -STAR="$(cat "$MOCKS_DIR/lts-star.txt")" - ACTUAL="$(nvm_normalize_lts "${STAR}")" EXPECTED="${STAR}" [ "${ACTUAL}" = "${EXPECTED}" ] || die "expected >${EXPECTED}<, got >${ACTUAL}<" -LTS_NAMES_PATH="${MOCKS_DIR}/LTS_names.txt" -LTS_LIST="$(cat "${LTS_NAMES_PATH}" | tail -n +2)" +# or, back up LTS aliases, copy backups that are in LTS names +# INDEX=1 printf '%s\n' "${LTS_LIST}" | while IFS= read -r LTS; do