Skip to content

Commit 452495a

Browse files
committed
implement suggestions for option
1 parent 88d889a commit 452495a

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

nvm.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3587,18 +3587,22 @@ nvm() {
35873587
local NVMRC_SAVE_TEXT
35883588
NVMRC_SAVE_TEXT=''
35893589
if [ "${NVM_WRITE_TO_NVMRC}" -eq 1 ] && [ "${VERSION}" != '' ] && [ "${VERSION}" != 'N/A' ]; then
3590-
echo "$VERSION" | tee "${PWD}"/.nvmrc > /dev/null || nvm_err "WARNING: Unable write version to .nvmrc"
3590+
echo "$VERSION" | tee "${PWD}"/.nvmrc > /dev/null || {
3591+
nvm_err "Unable to write version to .nvmrc, aborted."
3592+
exit 3
3593+
}
35913594
NVMRC_SAVE_TEXT=" (saved to .nvmrc)"
35923595
fi
35933596
if [ "_${VERSION}" = '_system' ]; then
35943597
if nvm_has_system_node && nvm deactivate "${NVM_SILENT_ARG-}" >/dev/null 2>&1; then
35953598
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
3596-
nvm_echo "Now using system version of node: $(node -v 2>/dev/null)$(nvm_print_npm_version)$NVMRC_SAVE_TEXT"
3599+
nvm_echo "Now using system version of node:
3600+
$(node -v 2>/dev/null)$(nvm_print_npm_version)${NVMRC_SAVE_TEXT}"
35973601
fi
35983602
return
35993603
elif nvm_has_system_iojs && nvm deactivate "${NVM_SILENT_ARG-}" >/dev/null 2>&1; then
36003604
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
3601-
nvm_echo "Now using system version of io.js: $(iojs --version 2>/dev/null)$(nvm_print_npm_version)"
3605+
nvm_echo "Now using system version of io.js: $(iojs --version 2>/dev/null)$(nvm_print_npm_version)${NVMRC_SAVE_TEXT}"
36023606
fi
36033607
return
36043608
elif [ "${NVM_SILENT:-0}" -ne 1 ]; then
@@ -3647,9 +3651,9 @@ nvm() {
36473651
NVM_USE_OUTPUT=''
36483652
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
36493653
if nvm_is_iojs_version "${VERSION}"; then
3650-
NVM_USE_OUTPUT="Now using io.js $(nvm_strip_iojs_prefix "${VERSION}")$(nvm_print_npm_version)"
3654+
NVM_USE_OUTPUT="Now using io.js $(nvm_strip_iojs_prefix "${VERSION}")$(nvm_print_npm_version)${NVMRC_SAVE_TEXT}"
36513655
else
3652-
NVM_USE_OUTPUT="Now using node ${VERSION}$(nvm_print_npm_version)$NVMRC_SAVE_TEXT"
3656+
NVM_USE_OUTPUT="Now using node ${VERSION}$(nvm_print_npm_version)${NVMRC_SAVE_TEXT}"
36533657
fi
36543658
fi
36553659
if [ "_${VERSION}" != "_system" ]; then

test/slow/nvm use/Running 'nvm use --save --lts' should work as expected

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
#set -ex
3+
set -ex
44

55
clean () {
66
if [ "$(basename "$(pwd)")" = "tmp" ]; then
@@ -19,12 +19,12 @@ nvm deactivate >/dev/null 2>&1 || die 'deactivate failed'
1919
test_version () {
2020
clean
2121
VERSION=${1-}
22-
nvm install --save "$VERSION" || die "nvm install --save $VERSION failed"
22+
nvm install --save "$VERSION" || die "\`nvm install --save $VERSION\` failed"
2323
OUTPUT="$(cat .nvmrc)"
2424
EXPECTED_OUTPUT=$(nvm_ls_current)
2525

2626
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
27-
|| die "'nvm use use --save $VERSION' + 'cat .nvmrc' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
27+
|| die "\`nvm use use --save $VERSION\`+ \`cat .nvmrc\` did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
2828
}
2929

3030
test_version '--lts'
@@ -46,13 +46,26 @@ test_version
4646
clean
4747
##
4848

49-
nvm alias 'test' node
50-
nvm use 'test' --save || die 'nvm use test --save failed'
49+
nvm alias test node
50+
nvm use test --save || die "\`nvm use test --save\` failed"
5151
OUTPUT="$(cat .nvmrc)"
5252
EXPECTED_OUTPUT=$(nvm_ls_current)
5353
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
54-
|| die "'nvm use use --save $VERSION' + 'cat .nvmrc' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
55-
nvm unalias 'test'
54+
|| die "\`nvm use use --save $VERSION\` + \`cat .nvmrc\` did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'"
55+
nvm unalias test
56+
57+
##
58+
clean
59+
##
60+
61+
mkdir tmp
62+
cd tmp || die 'Unable to access tmp directory';
63+
chmod 0 .
64+
65+
{
66+
(nvm install --save --lts) &&
67+
die "\`nvm install --save --lts\` did not fail with invalid permissions"
68+
} || echo "\`nvm install --save --lts\` failed successfully"
5669

5770
##
5871
clean
@@ -62,7 +75,7 @@ OUTPUT="$(nvm use node --silent --save)"
6275
EXPECTED_OUTPUT=''
6376

6477
[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \
65-
|| die "'nvm use node --silent --save' output was not silenced '$EXPECTED_OUTPUT'; got '$OUTPUT'"
78+
|| die "\`nvm use node --silent --save\` output was not silenced; got '$OUTPUT'"
6679

6780
##
6881

0 commit comments

Comments
 (0)