Refactor and create `nvm_remote_versions` and `nvm_remote_version`.
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Fixes #620 - an oh-my-zsh issue where `nvm install v1` didn't work.
authored by Jordan Harband · committed by Jordan Harband · parent 7d113a2 · Browse files · 3 files·+140 added−18 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+140 added−18 removed
- tests:+98 added−0 removed
- other:+42 added−18 removed
Provenance
- Commit
7243bd7- Tree
3328974- Author
Jordan Harband <ljharb@gmail.com>- Committer
Jordan Harband <ljharb@gmail.com>- Parent
7d113a2
3 files changed+140 added−18 removed
added:test/fast/Unit tests/nvm_remote_versions+78 added
1+#!/bin/sh2+3+die () { echo $@ ; cleanup ; exit 1; }4+5+cleanup() {6+ unset -f nvm_ls_remote nvm_ls_remote_iojs7+}8+9+. ../../../nvm.sh10+11+OUTPUT="$(nvm_remote_versions stable 2>&1)"12+EXPECTED_OUTPUT="Implicit aliases are not supported in nvm_remote_versions."13+EXIT_CODE="$(nvm_remote_versions stable >/dev/null 2>&1; echo $?)"14+[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "implicit alias 'stable' did not error out with correct message, got $OUTPUT"15+[ "_$EXIT_CODE" = "_1" ] || die "implicit alias 'stable' did not exit with code 1, got $EXIT_CODE"16+17+OUTPUT="$(nvm_remote_versions unstable 2>&1)"18+EXPECTED_OUTPUT="Implicit aliases are not supported in nvm_remote_versions."19+EXIT_CODE="$(nvm_remote_versions unstable >/dev/null 2>&1; echo $?)"20+[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "implicit alias 'unstable' did not error out with correct message, got $OUTPUT"21+[ "_$EXIT_CODE" = "_1" ] || die "implicit alias 'unstable' did not exit with code 1, got $EXIT_CODE"22+23+nvm_ls_remote() {24+ echo "N/A"25+}26+OUTPUT="$(nvm_remote_versions foo)"27+EXIT_CODE="$(nvm_remote_versions foo >/dev/null 2>&1 ; echo $?)"28+[ "_$OUTPUT" = "_N/A" ] || die "nonexistent version did not report N/A"29+[ "_$EXIT_CODE" = "_3" ] || die "nonexistent version did not exit with code 3, got $EXIT_CODE"30+31+nvm_ls_remote_iojs() {32+ echo "N/A"33+}34+OUTPUT="$(nvm_remote_versions iojs-foo)"35+EXIT_CODE="$(nvm_remote_versions iojs-foo >/dev/null 2>&1 ; echo $?)"36+[ "_$OUTPUT" = "_N/A" ] || die "nonexistent version did not report N/A"37+[ "_$EXIT_CODE" = "_3" ] || die "nonexistent version did not exit with code 3, got $EXIT_CODE"38+39+40+nvm_ls_remote() {41+ echo "test output"42+ echo "more test output"43+ echo "pattern received: _$1_"44+}45+nvm_ls_remote_iojs() {46+ echo "test iojs output"47+ echo "more iojs test output"48+ echo "iojs pattern received: _$1_"49+}50+51+OUTPUT="$(nvm_remote_versions foo)"52+EXIT_CODE="$(nvm_remote_versions foo >/dev/null 2>&1 ; echo $?)"53+[ "_$OUTPUT" = "_$(nvm_ls_remote foo)54+$(nvm_ls_remote_iojs foo)" ] \55+ || die "nvm_remote_versions foo did not return contents of nvm_ls_remote foo combined with nvm_ls_remote_iojs foo; got $OUTPUT"56+[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_versions foo did not exit with 0, got $EXIT_CODE"57+58+OUTPUT="$(nvm_remote_versions node)"59+EXIT_CODE="$(nvm_remote_versions node >/dev/null 2>&1 ; echo $?)"60+[ "_$OUTPUT" = "_$(nvm_ls_remote)" ] \61+ || die "nvm_remote_versions node did not return contents of nvm_ls_remote; got $OUTPUT"62+[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_versions node did not exit with 0, got $EXIT_CODE"63+64+OUTPUT="$(nvm_remote_versions iojs-foo)"65+EXIT_CODE="$(nvm_remote_versions iojs-foo >/dev/null 2>&1 ; echo $?)"66+[ "_$OUTPUT" = "_$(nvm_ls_remote iojs-foo)67+$(nvm_ls_remote_iojs iojs-foo)" ] \68+ || die "nvm_remote_versions iojs-foo did not return contents of nvm_ls_remote iojs-foo combined with nvm_ls_remote_iojs iojs-foo; got $OUTPUT"69+[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_versions iojs-foo did not exit with 0, got $EXIT_CODE"70+71+OUTPUT="$(nvm_remote_versions iojs)"72+EXIT_CODE="$(nvm_remote_versions iojs >/dev/null 2>&1 ; echo $?)"73+[ "_$OUTPUT" = "_$(nvm_ls_remote_iojs)" ] \74+ || die "nvm_remote_versions iojs did not return contents of nvm_ls_remote_iojs; got $OUTPUT"75+[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_versions iojs did not exit with 0, got $EXIT_CODE"76+77+cleanup78+added:test/installation/io.js/nvm install v1 works+20 added
1+#!/bin/sh2+3+die () { echo $@ ; exit 1; }4+5+. ../../../nvm.sh6+7+NVM_VERSION="v1"8+NVM_PREFIXED_TEST_VERSION="$(nvm ls-remote "$NVM_VERSION" | tail -n1 | sed 's/^[ ]*//;s/[ ]*$//')"9+NVM_TEST_VERSION="$(nvm_strip_iojs_prefix "$NVM_PREFIXED_TEST_VERSION")"10+11+# Remove the stuff we're clobbering.12+[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION13+14+# Install from binary15+nvm install "$NVM_VERSION" || die "nvm install $NVM_VERSION failed"16+17+# Check18+[ -d ../../../versions/io.js/$NVM_TEST_VERSION ]19+nvm run $NVM_PREFIXED_TEST_VERSION --version | grep $NVM_TEST_VERSION || die "'nvm run $NVM_PREFIXED_TEST_VERSION --version | grep $NVM_TEST_VERSION' failed"20+modified:nvm.sh+42 added-18 removed
215 unmodified lines216 nvm_remote_version() {217 local PATTERN218 PATTERN="$1"219 local VERSION220- if nvm_is_iojs_version "$PATTERN"; then221- VERSION="$(nvm_ls_remote_iojs "$PATTERN")"220+ if nvm_validate_implicit_alias "$PATTERN" 2> /dev/null ; then221+ VERSIONS="$(nvm_ls_remote "$PATTERN")"222 else223+ case "_$PATTERN" in224+ "_$(nvm_node_prefix)")223- VERSION="$(nvm_ls_remote "$PATTERN")"225+ VERSION="$(nvm_ls_remote stable)"226+ ;;227+ *)228+ VERSION="$(nvm_remote_versions "$PATTERN" | tail -n1)"229+ ;;230+ esac231 fi225- echo "$VERSION" | tail -n1226-232+ echo "$VERSION"233 if [ "_$VERSION" = '_N/A' ]; then234 return 3235 fi236 }237 238+nvm_remote_versions() {239+ local PATTERN240+ PATTERN="$1"241+ if nvm_validate_implicit_alias "$PATTERN" 2> /dev/null ; then242+ echo >&2 "Implicit aliases are not supported in nvm_remote_versions."243+ return 1244+ fi245+ case "_$PATTERN" in246+ "_$(nvm_iojs_prefix)" | "_io.js")247+ VERSIONS="$(nvm_ls_remote_iojs)"248+ ;;249+ "_$(nvm_node_prefix)")250+ VERSIONS="$(nvm_ls_remote)"251+ ;;252+ *)253+ VERSIONS="$(echo "$(nvm_ls_remote "$PATTERN")254+$(nvm_ls_remote_iojs "$PATTERN")" | command grep -v "N/A" | command sed '/^$/d')"255+ ;;256+ esac257+258+ if [ -z "$VERSIONS" ]; then259+ echo "N/A"260+ return 3261+ else262+ echo "$VERSIONS"263+ fi264+}265+266 nvm_normalize_version() {267 echo "$1" | command sed -e 's/^v//' | command awk -F. '{ printf("%d%06d%06d\n", $1,$2,$3); }'268 }269 714 unmodified lines984 else985 shift986 fi987 954- case "_$provided_version" in955- "_$(nvm_iojs_prefix)" | "_io.js")956- VERSION="$(nvm_add_iojs_prefix $(nvm_ls_remote_iojs | tail -n1))"957- ;;958- "_$(nvm_node_prefix)")959- VERSION="$(nvm_ls_remote stable)"960- ;;961- *)962- VERSION="$(nvm_remote_version "$provided_version")"988+ VERSION="$(nvm_remote_version "$provided_version")"963- ;;964- esac989 990 if [ "_$VERSION" = "_N/A" ]; then991 echo "Version '$provided_version' not found - try \`nvm ls-remote\` to browse available versions." >&2992 return 3354 unmodified lines1347 fi1348 1349 local NVM_OUTPUT1350 NVM_OUTPUT="$(echo "$NVM_LS_REMOTE_OUTPUT1327-$NVM_LS_REMOTE_IOJS_OUTPUT" | grep -v "N/A" | sed '/^$/d')"1351+$NVM_LS_REMOTE_IOJS_OUTPUT" | command grep -v "N/A" | sed '/^$/d')"1352 if [ -n "$NVM_OUTPUT" ]; then1353 nvm_print_versions "$NVM_OUTPUT"1354 return $NVM_LS_REMOTE_EXIT_CODE || $NVM_LS_REMOTE_IOJS_EXIT_CODE1355 else148 unmodified lines1504 unset -f nvm nvm_print_versions nvm_checksum \1505 nvm_iojs_prefix nvm_node_prefix \1506 nvm_add_iojs_prefix nvm_strip_iojs_prefix \1507 nvm_is_iojs_version \1484- nvm_ls_remote nvm_ls nvm_remote_version \1508+ nvm_ls_remote nvm_ls nvm_remote_version nvm_remote_versions \1509 nvm_version nvm_rc_version \1510 nvm_version_greater nvm_version_greater_than_or_equal_to \1511 nvm_supports_source_options > /dev/null 2>&11512 unset RC_VERSION NVM_NODEJS_ORG_MIRROR NVM_DIR NVM_CD_FLAGS > /dev/null 2>&124 unmodified lines