mirror of
https://github.com/nvm-sh/nvm.git
synced 2026-06-19 20:52:15 +08:00
[Fix] nvm_rc_version: clarify error when no version and no .nvmrc
Previously the message read "No .nvmrc file found", which obscured the fact that the user also did not pass a version. The new wording names both halves of the actual problem. Refs #3755
This commit is contained in:
2
nvm.sh
2
nvm.sh
@@ -622,7 +622,7 @@ nvm_rc_version() {
|
|||||||
NVMRC_PATH="$(nvm_find_nvmrc)"
|
NVMRC_PATH="$(nvm_find_nvmrc)"
|
||||||
if [ ! -e "${NVMRC_PATH}" ]; then
|
if [ ! -e "${NVMRC_PATH}" ]; then
|
||||||
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
|
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
|
||||||
nvm_err "No .nvmrc file found"
|
nvm_err "No version provided and no .nvmrc file found"
|
||||||
fi
|
fi
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|||||||
39
test/fast/Unit tests/nvm_rc_version errors when no version and no .nvmrc
Executable file
39
test/fast/Unit tests/nvm_rc_version errors when no version and no .nvmrc
Executable file
@@ -0,0 +1,39 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
die () { echo "$@" ; cleanup ; exit 1; }
|
||||||
|
|
||||||
|
cleanup() {
|
||||||
|
cd "${ORIG_PWD}" 2>/dev/null || true
|
||||||
|
[ -n "${TMP_DIR-}" ] && rm -rf "${TMP_DIR}"
|
||||||
|
}
|
||||||
|
|
||||||
|
: nvm.sh
|
||||||
|
\. ../../../nvm.sh
|
||||||
|
|
||||||
|
\. ../../common.sh
|
||||||
|
|
||||||
|
ORIG_PWD="$(pwd)"
|
||||||
|
|
||||||
|
# Run from a fresh, empty directory so no ambient .nvmrc above the test dir
|
||||||
|
# is found by the upward lookup.
|
||||||
|
TMP_DIR="$(mktemp -d)"
|
||||||
|
cd "${TMP_DIR}" || die "could not cd to temp dir"
|
||||||
|
|
||||||
|
# The message must name both halves of the problem: no argument AND no .nvmrc.
|
||||||
|
try_err nvm_rc_version
|
||||||
|
EXPECTED='No version provided and no .nvmrc file found'
|
||||||
|
[ "_${CAPTURED_STDERR}" = "_${EXPECTED}" ] \
|
||||||
|
|| die "nvm_rc_version did not print >${EXPECTED}<; got >${CAPTURED_STDERR}<"
|
||||||
|
[ "_${CAPTURED_EXIT_CODE}" = "_1" ] \
|
||||||
|
|| die "nvm_rc_version expected exit code 1; got ${CAPTURED_EXIT_CODE}"
|
||||||
|
|
||||||
|
# NVM_SILENT suppresses the message but the call still fails.
|
||||||
|
export NVM_SILENT=1
|
||||||
|
try_err nvm_rc_version
|
||||||
|
unset NVM_SILENT
|
||||||
|
[ -z "${CAPTURED_STDERR}" ] \
|
||||||
|
|| die "NVM_SILENT nvm_rc_version should be silent; got >${CAPTURED_STDERR}<"
|
||||||
|
[ "_${CAPTURED_EXIT_CODE}" = "_1" ] \
|
||||||
|
|| die "NVM_SILENT nvm_rc_version expected exit code 1; got ${CAPTURED_EXIT_CODE}"
|
||||||
|
|
||||||
|
cleanup
|
||||||
Reference in New Issue
Block a user