Separate `nvm_resolve_alias`'s `nvm_version` behavior into `nvm_resolve_local_alias`.

master
Jordan Harband 2015-02-21 13:51:07 -08:00
parent cd481ff548
commit 7d22e0c458
4 changed files with 98 additions and 9 deletions

28
nvm.sh
View File

@ -425,7 +425,7 @@ nvm_resolve_alias() {
if [ "_$ALIAS" = "_∞" ]; then if [ "_$ALIAS" = "_∞" ]; then
echo "$ALIAS" echo "$ALIAS"
else else
nvm_version "$ALIAS" nvm_ensure_version_prefix "$ALIAS"
fi fi
return 0 return 0
fi fi
@ -434,15 +434,33 @@ nvm_resolve_alias() {
local IMPLICIT local IMPLICIT
IMPLICIT="$(nvm_print_implicit_alias local "$PATTERN" 2> /dev/null)" IMPLICIT="$(nvm_print_implicit_alias local "$PATTERN" 2> /dev/null)"
if [ -n "$IMPLICIT" ]; then if [ -n "$IMPLICIT" ]; then
nvm_version "$IMPLICIT" nvm_ensure_version_prefix "$IMPLICIT"
return $?
fi fi
return 3
fi fi
return 2 return 2
} }
nvm_resolve_local_alias() {
if [ -z "$1" ]; then
return 1
fi
local VERSION
local EXIT_CODE
VERSION="$(nvm_resolve_alias "$1")"
EXIT_CODE=$?
if [ -z "$VERSION" ]; then
echo "N/A"
return $EXIT_CODE
fi
if [ "_$VERSION" != "_∞" ]; then
nvm_version "$VERSION"
else
echo "$VERSION"
fi
}
nvm_iojs_prefix() { nvm_iojs_prefix() {
echo "iojs" echo "iojs"
} }
@ -494,7 +512,7 @@ nvm_ls() {
PATTERN="$PATTERN-" PATTERN="$PATTERN-"
;; ;;
*) *)
if nvm_resolve_alias "$PATTERN"; then if nvm_resolve_local_alias "$PATTERN"; then
return return
fi fi
PATTERN=$(nvm_ensure_version_prefix $PATTERN) PATTERN=$(nvm_ensure_version_prefix $PATTERN)

View File

@ -0,0 +1,36 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../../nvm.sh
ALIAS="$(nvm_resolve_local_alias loopback)"
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias loopback was not ∞; got $ALIAS"
OUTPUT="$(nvm alias loopback)"
EXPECTED_OUTPUT="loopback -> loopback (-> ∞)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias loopback was not $EXPECTED_OUTPUT; got $OUTPUT"
ALIAS="$(nvm_resolve_local_alias one)"
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias one was not ∞; got $ALIAS"
OUTPUT="$(nvm alias one)"
EXPECTED_OUTPUT="one -> two (-> ∞)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias one was not $EXPECTED_OUTPUT; got $OUTPUT"
ALIAS="$(nvm_resolve_local_alias two)"
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias two was not ∞; got $ALIAS"
OUTPUT="$(nvm alias two)"
EXPECTED_OUTPUT="two -> three (-> ∞)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias two was not $EXPECTED_OUTPUT; got $OUTPUT"
ALIAS="$(nvm_resolve_local_alias three)"
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias three was not ∞; got $ALIAS"
OUTPUT="$(nvm alias three)"
EXPECTED_OUTPUT="three -> one (-> ∞)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias three was not $EXPECTED_OUTPUT; got $OUTPUT"
ALIAS="$(nvm_resolve_local_alias four)"
[ "_$ALIAS" = "_∞" ] || die "nvm_resolve_local_alias four was not ∞; got $ALIAS"
OUTPUT="$(nvm alias four)"
EXPECTED_OUTPUT="four -> two (-> ∞)"
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm alias four was not $EXPECTED_OUTPUT; got $OUTPUT"

View File

@ -21,13 +21,13 @@ EXIT_CODE=$(nvm_resolve_alias nonexistent ; echo $?)
[ $EXIT_CODE = "2" ] || die "'nvm_resolve_alias nonexistent' did not return 2; got $EXIT_CODE" [ $EXIT_CODE = "2" ] || die "'nvm_resolve_alias nonexistent' did not return 2; got $EXIT_CODE"
STABLE="$(nvm_resolve_alias stable)" STABLE="$(nvm_resolve_alias stable)"
[ "_$STABLE" = "_v0.0.10" ] || die "'nvm_resolve_alias stable' was not v0.0.10; got $STABLE" [ "_$STABLE" = "_v0.0" ] || die "'nvm_resolve_alias stable' was not v0.0; got $STABLE"
NODE="$(nvm_resolve_alias node)" NODE="$(nvm_resolve_alias node)"
[ "_$NODE" = "_v0.0.10" ] || die "'nvm_resolve_alias node' was not v0.0.10; got $NODE" [ "_$NODE" = "_stable" ] || die "'nvm_resolve_alias node' was not stable; got $NODE"
UNSTABLE="$(nvm_resolve_alias unstable)" UNSTABLE="$(nvm_resolve_alias unstable)"
[ "_$UNSTABLE" = "_v0.1.10" ] || die "'nvm_resolve_alias unstable' was not v0.1.10; got $UNSTABLE" [ "_$UNSTABLE" = "_v0.1" ] || die "'nvm_resolve_alias unstable' was not v0.1; got $UNSTABLE"
IOJS="$(nvm_resolve_alias iojs)" IOJS="$(nvm_resolve_alias iojs)"
[ "_$IOJS" = "_iojs-v0.2.10" ] || die "'nvm_resolve_alias iojs' was not iojs-v0.2.10; got $IOJS" [ "_$IOJS" = "_iojs-v0.2" ] || die "'nvm_resolve_alias iojs' was not iojs-v0.2; got $IOJS"

View File

@ -0,0 +1,35 @@
#!/bin/sh
die () { echo $@ ; exit 1; }
. ../../../nvm.sh
EXIT_CODE=$(nvm_resolve_local_alias ; echo $?)
[ "_$EXIT_CODE" = "_1" ] || die "nvm_resolve_local_alias without an argument did not return 1; got $EXIT_CODE"
for i in $(seq 1 10)
do
STABLE_ALIAS="$(nvm_resolve_local_alias test-stable-$i)"
[ "_$STABLE_ALIAS" = "_v0.0.$i" ] \
|| die "'nvm_resolve_local_alias test-stable-$i' was not v0.0.$i; got $STABLE_ALIAS"
UNSTABLE_ALIAS="$(nvm_resolve_local_alias test-unstable-$i)"
[ "_$UNSTABLE_ALIAS" = "_v0.1.$i" ] \
|| die "'nvm_resolve_local_alias test-unstable-$i' was not v0.1.$i; got $UNSTABLE_ALIAS"
done
OUTPUT="$(nvm_resolve_local_alias nonexistent)"
EXIT_CODE=$(nvm_resolve_local_alias nonexistent > /dev/null 2>&1 ; echo $?)
[ "_$EXIT_CODE" = "_2" ] || die "'nvm_resolve_local_alias nonexistent' did not return 2; got $EXIT_CODE"
[ "_$OUTPUT" = "_N/A" ] || die "'nvm_resolve_local_alias nonexistent' did not output N/A; got $OUTPUT"
STABLE="$(nvm_resolve_local_alias stable)"
[ "_$STABLE" = "_v0.0.10" ] || die "'nvm_resolve_local_alias stable' was not v0.0.10; got $STABLE"
NODE="$(nvm_resolve_local_alias node)"
[ "_$NODE" = "_v0.0.10" ] || die "'nvm_resolve_local_alias node' was not v0.0.10; got $NODE"
UNSTABLE="$(nvm_resolve_local_alias unstable)"
[ "_$UNSTABLE" = "_v0.1.10" ] || die "'nvm_resolve_local_alias unstable' was not v0.1.10; got $UNSTABLE"
IOJS="$(nvm_resolve_local_alias iojs)"
[ "_$IOJS" = "_iojs-v0.2.10" ] || die "'nvm_resolve_local_alias iojs' was not iojs-v0.2.10; got $IOJS"