mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-04-03 11:34:50 +08:00
[Fix] nvm_ls_remote_combined: propagate iojs remote listing failures
`return $A || $B` only evaluates the first argument, since `return` always succeeds.
The io.js exit code was never checked, silently swallowing remote listing failures.
Bug introduced in ea12784629 / #616.
This commit is contained in:
5
nvm.sh
5
nvm.sh
@@ -878,7 +878,10 @@ ${NVM_LS_REMOTE_POST_MERGED_OUTPUT}" | nvm_grep -v "N/A" | command sed '/^ *$/d'
|
|||||||
# the `sed` is to remove trailing whitespaces (see "weird behavior" ~25 lines up)
|
# the `sed` is to remove trailing whitespaces (see "weird behavior" ~25 lines up)
|
||||||
nvm_echo "${VERSIONS}" | command sed 's/ *$//g'
|
nvm_echo "${VERSIONS}" | command sed 's/ *$//g'
|
||||||
# shellcheck disable=SC2317
|
# shellcheck disable=SC2317
|
||||||
return $NVM_LS_REMOTE_EXIT_CODE || $NVM_LS_REMOTE_IOJS_EXIT_CODE
|
if [ "${NVM_LS_REMOTE_EXIT_CODE}" != '0' ]; then
|
||||||
|
return "${NVM_LS_REMOTE_EXIT_CODE}"
|
||||||
|
fi
|
||||||
|
return "${NVM_LS_REMOTE_IOJS_EXIT_CODE}"
|
||||||
}
|
}
|
||||||
|
|
||||||
nvm_is_valid_version() {
|
nvm_is_valid_version() {
|
||||||
|
|||||||
68
test/fast/Unit tests/nvm_remote_versions propagates iojs failure
Executable file
68
test/fast/Unit tests/nvm_remote_versions propagates iojs failure
Executable file
@@ -0,0 +1,68 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
die () { echo "$@" ; cleanup ; exit 1; }
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
unset -f nvm_ls_remote nvm_ls_remote_iojs
|
||||||
|
}
|
||||||
|
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
|
\. ../../common.sh
|
||||||
|
|
||||||
|
# When nvm_ls_remote succeeds but nvm_ls_remote_iojs fails,
|
||||||
|
# nvm_remote_versions should propagate the iojs failure exit code.
|
||||||
|
nvm_ls_remote() {
|
||||||
|
echo "v0.10.0"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
nvm_ls_remote_iojs() {
|
||||||
|
echo "N/A"
|
||||||
|
return 5
|
||||||
|
}
|
||||||
|
|
||||||
|
try nvm_remote_versions
|
||||||
|
[ "_$CAPTURED_EXIT_CODE" = "_5" ] || die "expected iojs failure exit code 5 to propagate, got $CAPTURED_EXIT_CODE"
|
||||||
|
|
||||||
|
# When nvm_ls_remote fails and nvm_ls_remote_iojs succeeds,
|
||||||
|
# nvm_remote_versions should propagate the node failure exit code.
|
||||||
|
nvm_ls_remote() {
|
||||||
|
echo "v0.10.0"
|
||||||
|
return 7
|
||||||
|
}
|
||||||
|
nvm_ls_remote_iojs() {
|
||||||
|
echo "iojs-v1.0.0"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
try nvm_remote_versions
|
||||||
|
[ "_$CAPTURED_EXIT_CODE" = "_7" ] || die "expected node failure exit code 7 to propagate, got $CAPTURED_EXIT_CODE"
|
||||||
|
|
||||||
|
# When both fail, nvm_remote_versions should propagate the node failure exit code
|
||||||
|
# (since it is checked first).
|
||||||
|
nvm_ls_remote() {
|
||||||
|
echo "v0.10.0"
|
||||||
|
return 3
|
||||||
|
}
|
||||||
|
nvm_ls_remote_iojs() {
|
||||||
|
echo "iojs-v1.0.0"
|
||||||
|
return 4
|
||||||
|
}
|
||||||
|
|
||||||
|
try nvm_remote_versions
|
||||||
|
[ "_$CAPTURED_EXIT_CODE" = "_3" ] || die "expected node failure exit code 3 to take priority, got $CAPTURED_EXIT_CODE"
|
||||||
|
|
||||||
|
# When both succeed, exit code should be 0.
|
||||||
|
nvm_ls_remote() {
|
||||||
|
echo "v0.10.0"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
nvm_ls_remote_iojs() {
|
||||||
|
echo "iojs-v1.0.0"
|
||||||
|
return 0
|
||||||
|
}
|
||||||
|
|
||||||
|
try nvm_remote_versions
|
||||||
|
[ "_$CAPTURED_EXIT_CODE" = "_0" ] || die "expected exit code 0 when both succeed, got $CAPTURED_EXIT_CODE"
|
||||||
|
|
||||||
|
cleanup
|
||||||
Reference in New Issue
Block a user