From e3528b0d9e7d523b7294c9f5f67e416c85207fb8 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Fri, 11 Sep 2015 10:42:47 +0900 Subject: [PATCH] Fix `nvm_ensure_version_installed iojs` to not print an empty string for the version. --- nvm.sh | 4 +++- test/fast/Unit tests/nvm_ensure_version_installed | 7 +++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index 7f69db9..df214e9 100755 --- a/nvm.sh +++ b/nvm.sh @@ -210,7 +210,9 @@ nvm_ensure_version_installed() { if [ $? -eq 0 ]; then echo "N/A: version \"$PROVIDED_VERSION -> $VERSION\" is not yet installed" >&2 else - echo "N/A: version \"$(nvm_ensure_version_prefix "$PROVIDED_VERSION")\" is not yet installed" >&2 + local PREFIXED_VERSION + PREFIXED_VERSION="$(nvm_ensure_version_prefix "$PROVIDED_VERSION")" + echo "N/A: version \"${PREFIXED_VERSION:-$PROVIDED_VERSION}\" is not yet installed" >&2 fi return 1 fi diff --git a/test/fast/Unit tests/nvm_ensure_version_installed b/test/fast/Unit tests/nvm_ensure_version_installed index ed2d996..492cc95 100755 --- a/test/fast/Unit tests/nvm_ensure_version_installed +++ b/test/fast/Unit tests/nvm_ensure_version_installed @@ -20,4 +20,11 @@ EXIT_CODE=$? [ "_$OUTPUT" = "_" ] || die "expected 'nvm_ensure_version_installed 0.1' to have no output, got $OUTPUT" [ "_$EXIT_CODE" = "_0" ] || die "expected 'nvm_ensure_version_installed 0.1' to exit with 0, got $EXIT_CODE" +# Special case for "iojs" +OUTPUT="$(nvm_ensure_version_installed iojs 2>&1)" +EXIT_CODE=$? +EXPECTED_OUTPUT='N/A: version "iojs" is not yet installed' +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "expected 'nvm_ensure_version_installed iojs' to give $EXPECTED_OUTPUT, got $OUTPUT" +[ "_$EXIT_CODE" = "_1" ] || die "expected 'nvm_ensure_version_installed iojs' to exit with 1, got $EXIT_CODE" + cleanup