Add `nvm_ensure_default_set`
parent
a26ef4f1be
commit
3d764e6833
19
nvm.sh
19
nvm.sh
|
@ -873,6 +873,25 @@ nvm_get_arch() {
|
||||||
echo "$NVM_ARCH"
|
echo "$NVM_ARCH"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nvm_ensure_default_set() {
|
||||||
|
local VERSION
|
||||||
|
VERSION="$1"
|
||||||
|
if [ -z "$VERSION" ]; then
|
||||||
|
echo 'nvm_ensure_default_set: a version is required' >&2
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
if nvm_alias default >/dev/null 2>&1; then
|
||||||
|
# default already set
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
local OUTPUT
|
||||||
|
OUTPUT="$(nvm alias default "$VERSION")"
|
||||||
|
local EXIT_CODE
|
||||||
|
EXIT_CODE="$?"
|
||||||
|
echo "Creating default alias: $OUTPUT"
|
||||||
|
return $EXIT_CODE
|
||||||
|
}
|
||||||
|
|
||||||
nvm_install_iojs_binary() {
|
nvm_install_iojs_binary() {
|
||||||
local PREFIXED_VERSION
|
local PREFIXED_VERSION
|
||||||
PREFIXED_VERSION="$1"
|
PREFIXED_VERSION="$1"
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
die () { echo $@ ; exit 1; }
|
||||||
|
|
||||||
|
. ../../../nvm.sh
|
||||||
|
|
||||||
|
nvm alias default 0.1 >/dev/null || die "'nvm alias default 0.1' failed"
|
||||||
|
|
||||||
|
nvm_ensure_default_set 0.3 || die "'nvm_ensure_default_set' with an existing default alias exits 0"
|
||||||
|
|
||||||
|
nvm unalias default || die "'nvm unalias default' failed"
|
||||||
|
|
||||||
|
OUTPUT="$(nvm_ensure_default_set 0.2)"
|
||||||
|
EXPECTED_OUTPUT="Creating default alias: default -> 0.2 (-> iojs-v0.2.10)"
|
||||||
|
EXIT_CODE="$?"
|
||||||
|
|
||||||
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_ensure_default_set 0.2' did not output '$EXPECTED_OUTPUT', got '$OUTPUT'"
|
||||||
|
[ "_$EXIT_CODE" = "_0" ] || die "'nvm_ensure_default_set 0.2' did not exit with 0, got $EXIT_CODE"
|
|
@ -14,3 +14,4 @@ rm -f "../../../alias/stable"
|
||||||
rm -f "../../../alias/unstable"
|
rm -f "../../../alias/unstable"
|
||||||
rm -f "../../../alias/node"
|
rm -f "../../../alias/node"
|
||||||
rm -f "../../../alias/iojs"
|
rm -f "../../../alias/iojs"
|
||||||
|
rm -f "../../../alias/default"
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
die () { echo $@ ; exit 1; }
|
||||||
|
|
||||||
|
. ../../../nvm.sh
|
||||||
|
|
||||||
|
EXPECTED_OUTPUT="nvm_ensure_default_set: a version is required"
|
||||||
|
OUTPUT="$(nvm_ensure_default_set 2>&1 >/dev/null)"
|
||||||
|
EXIT_CODE="$?"
|
||||||
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_ensure_default_set' did not output "$EXPECTED_OUTPUT", got "$OUTPUT""
|
||||||
|
[ "_$EXIT_CODE" = "_1" ] || die "'nvm_ensure_default_set' did not exit with 1, got "$EXIT_CODE""
|
||||||
|
|
||||||
|
# see test/fast/Aliases for remaining nvm_ensure_default_set tests
|
Loading…
Reference in New Issue