Skip to content
Myr

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

3 files+140 added−18 removed

added:test/fast/Unit tests/nvm_remote_versions+78 added
1#!/bin/sh23die () { echo $@ ; cleanup ; exit 1; }45cleanup() {6 unset -f nvm_ls_remote nvm_ls_remote_iojs7}89. ../../../nvm.sh1011OUTPUT="$(nvm_remote_versions stable 2>&1)"12EXPECTED_OUTPUT="Implicit aliases are not supported in nvm_remote_versions."13EXIT_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"1617OUTPUT="$(nvm_remote_versions unstable 2>&1)"18EXPECTED_OUTPUT="Implicit aliases are not supported in nvm_remote_versions."19EXIT_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"2223nvm_ls_remote() {24 echo "N/A"25}26OUTPUT="$(nvm_remote_versions foo)"27EXIT_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"3031nvm_ls_remote_iojs() {32 echo "N/A"33}34OUTPUT="$(nvm_remote_versions iojs-foo)"35EXIT_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"383940nvm_ls_remote() {41 echo "test output"42 echo "more test output"43 echo "pattern received: _$1_"44}45nvm_ls_remote_iojs() {46 echo "test iojs output"47 echo "more iojs test output"48 echo "iojs pattern received: _$1_"49}5051OUTPUT="$(nvm_remote_versions foo)"52EXIT_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"5758OUTPUT="$(nvm_remote_versions node)"59EXIT_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"6364OUTPUT="$(nvm_remote_versions iojs-foo)"65EXIT_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"7071OUTPUT="$(nvm_remote_versions iojs)"72EXIT_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"7677cleanup78
added:test/installation/io.js/nvm install v1 works+20 added
1#!/bin/sh23die () { echo $@ ; exit 1; }45. ../../../nvm.sh67NVM_VERSION="v1"8NVM_PREFIXED_TEST_VERSION="$(nvm ls-remote "$NVM_VERSION" | tail -n1 | sed 's/^[ ]*//;s/[ ]*$//')"9NVM_TEST_VERSION="$(nvm_strip_iojs_prefix "$NVM_PREFIXED_TEST_VERSION")"1011# Remove the stuff we're clobbering.12[ -e ../../../$NVM_TEST_VERSION ] && rm -R ../../../$NVM_TEST_VERSION1314# Install from binary15nvm install "$NVM_VERSION" || die "nvm install $NVM_VERSION failed"1617# Check18[ -d ../../../versions/io.js/$NVM_TEST_VERSION ]19nvm 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 lines
216nvm_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 -n1226232 echo "$VERSION"233 if [ "_$VERSION" = '_N/A' ]; then234 return 3235 fi236}237238nvm_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 esac257258 if [ -z "$VERSIONS" ]; then259 echo "N/A"260 return 3261 else262 echo "$VERSIONS"263 fi264}265266nvm_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 lines
984 else985 shift986 fi987954 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 esac989990 if [ "_$VERSION" = "_N/A" ]; then991 echo "Version '$provided_version' not found - try \`nvm ls-remote\` to browse available versions." >&2992 return 3
354 unmodified lines
1347 fi13481349 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 else
148 unmodified lines
1504 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>&1
24 unmodified lines