Skip to content
Myr

Add `nvm_get_minor_version`

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Jordan Harband · committed by Jordan Harband · parent de64a2d · Browse files · 2 files+73 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+73 added−0 removed

  • tests:+45 added−0 removed
  • other:+28 added−0 removed

2 files+73 added−0 removed

added:test/fast/Unit tests/nvm_get_minor_version+45 added
1#!/bin/sh23die () { echo $@ ; exit 1; }45. ../../../nvm.sh67expect () {8 INPUT="$1"9 EXPECTED_OUTPUT="$2"1011 OUTPUT="$(nvm_get_minor_version "$INPUT")"12 [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_get_minor_version $INPUT did not return $EXPECTED_OUTPUT; got $OUTPUT"1314 V_OUTPUT="$(nvm_get_minor_version "v$INPUT")"15 [ "_$V_OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_get_minor_version v$INPUT did not return $EXPECTED_OUTPUT; got $V_OUTPUT"16}1718fail_with () {19 INPUT="$1"20 EXPECTED_CODE="$2"2122 EXIT_CODE="$(nvm_get_minor_version "$INPUT" >/dev/null 2>&1; echo $?)"23 [ "_$EXIT_CODE" = "_$EXPECTED_CODE" ] || die "nvm_get_minor_version "$INPUT" did not fail with code "$EXPECTED_CODE"; got $EXIT_CODE"24}2526expect 1 1.027expect 1. 1.028expect 1.2 1.229expect 1.2. 1.230expect 1.2.3 1.231expect 1.2.3. 1.232expect 1.2.3.4 1.23334fail_with '' 135fail_with '.' 236fail_with '..' 237fail_with v 238fail_with .a 239fail_with .1 240fail_with v.1 241fail_with a.b 242fail_with 1.a 243fail_with a.1 244fail_with v1.a 245fail_with va.1 2
modified:nvm.sh+28 added
993 unmodified lines
994 esac995 echo "$NVM_ARCH"996}997998nvm_get_minor_version() {999 local VERSION1000 VERSION="$1"10011002 if [ -z "$VERSION" ]; then1003 echo 'a version is required' >&21004 return 11005 fi10061007 case "$VERSION" in1008 v | .* | *..* | v*[!.0123456789]* | [!v]*[!.0123456789]* | [!v0123456789]* | v[!0123456789]*)1009 echo 'invalid version number' >&21010 return 21011 ;;1012 esac10131014 local PREFIXED_VERSION1015 PREFIXED_VERSION="$(nvm_format_version "$VERSION")"10161017 local MINOR1018 MINOR="$(echo "$PREFIXED_VERSION" | command grep -e '^v' | command cut -c2- | command cut -d . -f 1,2)"1019 if [ -z "$MINOR" ]; then1020 echo 'invalid version number! (please report this)' >&21021 return 31022 fi1023 echo "$MINOR"1024}10251026nvm_ensure_default_set() {1027 local VERSION1028 VERSION="$1"1029 if [ -z "$VERSION" ]; then
1404 unmodified lines