Skip to content

Commit 4249b1c

Browse files
committed
[Fix] nvm_ensure_version_installed: add system support.
Relates to #1238
1 parent 5776cc9 commit 4249b1c

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

nvm.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,13 @@ nvm_version_path() {
289289
nvm_ensure_version_installed() {
290290
local PROVIDED_VERSION
291291
PROVIDED_VERSION="${1-}"
292+
if [ "${PROVIDED_VERSION}" = 'system' ]; then
293+
if nvm_has_system_iojs || nvm_has_system_node; then
294+
return 0
295+
fi
296+
nvm_err "N/A: no system version of node/io.js is installed."
297+
return 1
298+
fi
292299
local LOCAL_VERSION
293300
local EXIT_CODE
294301
LOCAL_VERSION="$(nvm_version "${PROVIDED_VERSION}")"

test/fast/Unit tests/nvm_ensure_version_installed

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
die () { echo "$@" ; cleanup ; exit 1; }
44
cleanup () {
55
rm -rf "$(nvm_version_path v0.1.2)"
6+
unset -f nvm_has_system_node nvm_has_system_iojs
67
}
78

89
\. ../../../nvm.sh
@@ -31,4 +32,31 @@ You need to run "nvm install iojs" to install it before using it.'
3132
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "expected 'nvm_ensure_version_installed iojs' to give $EXPECTED_OUTPUT, got $OUTPUT"
3233
[ "_$EXIT_CODE" = "_1" ] || die "expected 'nvm_ensure_version_installed iojs' to exit with 1, got $EXIT_CODE"
3334

35+
nvm_has_system_node() { return 1; }
36+
nvm_has_system_iojs() { return 1; }
37+
38+
OUTPUT="$(nvm_ensure_version_installed system 2>&1)"
39+
EXIT_CODE=$?
40+
EXPECTED_OUTPUT='N/A: no system version of node/io.js is installed.'
41+
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "expected 'nvm_ensure_version_installed system' with neither installed to give $EXPECTED_OUTPUT, got $OUTPUT"
42+
[ "_$EXIT_CODE" = "_1" ] || die "expected 'nvm_ensure_version_installed system' with neither installed to exit with 1, got $EXIT_CODE"
43+
44+
nvm_has_system_node() { return 0; }
45+
nvm_has_system_iojs() { return 1; }
46+
47+
OUTPUT="$(nvm_ensure_version_installed system 2>&1)"
48+
EXIT_CODE=$?
49+
EXPECTED_OUTPUT=''
50+
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "expected 'nvm_ensure_version_installed system' with node installed to give $EXPECTED_OUTPUT, got $OUTPUT"
51+
[ "_$EXIT_CODE" = "_0" ] || die "expected 'nvm_ensure_version_installed system' with node installed to exit with 0, got $EXIT_CODE"
52+
53+
nvm_has_system_node() { return 1; }
54+
nvm_has_system_iojs() { return 0; }
55+
56+
OUTPUT="$(nvm_ensure_version_installed system 2>&1)"
57+
EXIT_CODE=$?
58+
EXPECTED_OUTPUT=''
59+
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "expected 'nvm_ensure_version_installed system' with iojs installed to give $EXPECTED_OUTPUT, got $OUTPUT"
60+
[ "_$EXIT_CODE" = "_0" ] || die "expected 'nvm_ensure_version_installed system' with iojs installed to exit with 0, got $EXIT_CODE"
61+
3462
cleanup

0 commit comments

Comments
 (0)