[Fix] `nvm_ensure_version_installed`: add `system` support.
Relates to #1238
parent
5776cc952a
commit
4249b1c2bb
7
nvm.sh
7
nvm.sh
|
@ -289,6 +289,13 @@ nvm_version_path() {
|
||||||
nvm_ensure_version_installed() {
|
nvm_ensure_version_installed() {
|
||||||
local PROVIDED_VERSION
|
local PROVIDED_VERSION
|
||||||
PROVIDED_VERSION="${1-}"
|
PROVIDED_VERSION="${1-}"
|
||||||
|
if [ "${PROVIDED_VERSION}" = 'system' ]; then
|
||||||
|
if nvm_has_system_iojs || nvm_has_system_node; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
nvm_err "N/A: no system version of node/io.js is installed."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
local LOCAL_VERSION
|
local LOCAL_VERSION
|
||||||
local EXIT_CODE
|
local EXIT_CODE
|
||||||
LOCAL_VERSION="$(nvm_version "${PROVIDED_VERSION}")"
|
LOCAL_VERSION="$(nvm_version "${PROVIDED_VERSION}")"
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
die () { echo "$@" ; cleanup ; exit 1; }
|
die () { echo "$@" ; cleanup ; exit 1; }
|
||||||
cleanup () {
|
cleanup () {
|
||||||
rm -rf "$(nvm_version_path v0.1.2)"
|
rm -rf "$(nvm_version_path v0.1.2)"
|
||||||
|
unset -f nvm_has_system_node nvm_has_system_iojs
|
||||||
}
|
}
|
||||||
|
|
||||||
\. ../../../nvm.sh
|
\. ../../../nvm.sh
|
||||||
|
@ -31,4 +32,31 @@ You need to run "nvm install iojs" to install it before using it.'
|
||||||
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "expected 'nvm_ensure_version_installed iojs' to give $EXPECTED_OUTPUT, got $OUTPUT"
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "expected 'nvm_ensure_version_installed iojs' to give $EXPECTED_OUTPUT, got $OUTPUT"
|
||||||
[ "_$EXIT_CODE" = "_1" ] || die "expected 'nvm_ensure_version_installed iojs' to exit with 1, got $EXIT_CODE"
|
[ "_$EXIT_CODE" = "_1" ] || die "expected 'nvm_ensure_version_installed iojs' to exit with 1, got $EXIT_CODE"
|
||||||
|
|
||||||
|
nvm_has_system_node() { return 1; }
|
||||||
|
nvm_has_system_iojs() { return 1; }
|
||||||
|
|
||||||
|
OUTPUT="$(nvm_ensure_version_installed system 2>&1)"
|
||||||
|
EXIT_CODE=$?
|
||||||
|
EXPECTED_OUTPUT='N/A: no system version of node/io.js is installed.'
|
||||||
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "expected 'nvm_ensure_version_installed system' with neither installed to give $EXPECTED_OUTPUT, got $OUTPUT"
|
||||||
|
[ "_$EXIT_CODE" = "_1" ] || die "expected 'nvm_ensure_version_installed system' with neither installed to exit with 1, got $EXIT_CODE"
|
||||||
|
|
||||||
|
nvm_has_system_node() { return 0; }
|
||||||
|
nvm_has_system_iojs() { return 1; }
|
||||||
|
|
||||||
|
OUTPUT="$(nvm_ensure_version_installed system 2>&1)"
|
||||||
|
EXIT_CODE=$?
|
||||||
|
EXPECTED_OUTPUT=''
|
||||||
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "expected 'nvm_ensure_version_installed system' with node installed to give $EXPECTED_OUTPUT, got $OUTPUT"
|
||||||
|
[ "_$EXIT_CODE" = "_0" ] || die "expected 'nvm_ensure_version_installed system' with node installed to exit with 0, got $EXIT_CODE"
|
||||||
|
|
||||||
|
nvm_has_system_node() { return 1; }
|
||||||
|
nvm_has_system_iojs() { return 0; }
|
||||||
|
|
||||||
|
OUTPUT="$(nvm_ensure_version_installed system 2>&1)"
|
||||||
|
EXIT_CODE=$?
|
||||||
|
EXPECTED_OUTPUT=''
|
||||||
|
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "expected 'nvm_ensure_version_installed system' with iojs installed to give $EXPECTED_OUTPUT, got $OUTPUT"
|
||||||
|
[ "_$EXIT_CODE" = "_0" ] || die "expected 'nvm_ensure_version_installed system' with iojs installed to exit with 0, got $EXIT_CODE"
|
||||||
|
|
||||||
cleanup
|
cleanup
|
||||||
|
|
Loading…
Reference in New Issue