Skip to content
Myr

[Fix] `nvm_rc_version`: clarify error when no version and no .nvmrc

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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

authored by Jordan Harband · committed by Jordan Harband · parent a9933f7 · Browse files · 2 files+40 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+40 added−1 removed

  • tests:+39 added−0 removed
  • other:+1 added−1 removed

2 files+40 added−1 removed

added:test/fast/Unit tests/nvm_rc_version errors when no version and no .nvmrc+39 added
1#!/bin/sh23die () { echo "$@" ; cleanup ; exit 1; }45cleanup() {6 cd "${ORIG_PWD}" 2>/dev/null || true7 [ -n "${TMP_DIR-}" ] && rm -rf "${TMP_DIR}"8}910: nvm.sh11\. ../../../nvm.sh1213\. ../../common.sh1415ORIG_PWD="$(pwd)"1617# Run from a fresh, empty directory so no ambient .nvmrc above the test dir18# is found by the upward lookup.19TMP_DIR="$(mktemp -d)"20cd "${TMP_DIR}" || die "could not cd to temp dir"2122# The message must name both halves of the problem: no argument AND no .nvmrc.23try_err nvm_rc_version24EXPECTED='No version provided and no .nvmrc file found'25[ "_${CAPTURED_STDERR}" = "_${EXPECTED}" ] \26 || die "nvm_rc_version did not print >${EXPECTED}<; got >${CAPTURED_STDERR}<"27[ "_${CAPTURED_EXIT_CODE}" = "_1" ] \28 || die "nvm_rc_version expected exit code 1; got ${CAPTURED_EXIT_CODE}"2930# NVM_SILENT suppresses the message but the call still fails.31export NVM_SILENT=132try_err nvm_rc_version33unset NVM_SILENT34[ -z "${CAPTURED_STDERR}" ] \35 || die "NVM_SILENT nvm_rc_version should be silent; got >${CAPTURED_STDERR}<"36[ "_${CAPTURED_EXIT_CODE}" = "_1" ] \37 || die "NVM_SILENT nvm_rc_version expected exit code 1; got ${CAPTURED_EXIT_CODE}"3839cleanup
modified:nvm.sh+1 added-1 removed
620 unmodified lines
621 local NVMRC_PATH622 NVMRC_PATH="$(nvm_find_nvmrc)"623 if [ ! -e "${NVMRC_PATH}" ]; then624 if [ "${NVM_SILENT:-0}" -ne 1 ]; then625 nvm_err "No .nvmrc file found"625 nvm_err "No version provided and no .nvmrc file found"626 fi627 return 1628 fi629
4242 unmodified lines