From 644b0c5c7cb760d7cd59ed2f64876e994d96cea1 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Thu, 1 Aug 2024 13:57:22 -0700 Subject: [PATCH] [Fix] `nvm install -b`: when no binary is available, fail and output a clear message --- nvm.sh | 4 ++++ test/fast/Unit tests/nvm install -b | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100755 test/fast/Unit tests/nvm install -b diff --git a/nvm.sh b/nvm.sh index 82d26c00eda..4c8991ec85b 100755 --- a/nvm.sh +++ b/nvm.sh @@ -3558,6 +3558,10 @@ nvm() { EXIT_CODE=$? else EXIT_CODE=-1 + if [ $nosource -eq 1 ]; then + nvm_err "Binary download is not available for ${VERSION}" + EXIT_CODE=999 + fi fi if [ $EXIT_CODE -ne 0 ]; then diff --git a/test/fast/Unit tests/nvm install -b b/test/fast/Unit tests/nvm install -b new file mode 100755 index 00000000000..d6c414dcb47 --- /dev/null +++ b/test/fast/Unit tests/nvm install -b @@ -0,0 +1,16 @@ +#!/bin/sh + +die () { echo "$@" ; exit 1; } + +\. ../../../nvm.sh + +VERSION="0.7.0" + +EXIT_CODE=$(nvm install -b "${VERSION}" ; echo $?) + +[ $EXIT_CODE -eq 999 ] || die "Expected exit code 999, got ${EXIT_CODE}" + +ACTUAL="$(nvm install -b "${VERSION}" 2>&1)" +EXPECTED="Binary download is not available for ${VERSION}" + +diff $ACTUAL $EXPECTED || die