From ac8015c2b7fff6bb96208df6d8abd73409f04a09 Mon Sep 17 00:00:00 2001 From: Brian Mearns Date: Thu, 18 Feb 2016 11:45:54 -0500 Subject: [PATCH] Issue #1015 resolved. This strips trailing whitespace from the version as read from .nvmrc before attempting to use it. Added a test for it, but not too familiar with this type of testing, so not sure how good of a test it is. Also had some trouble running the tests in general, even before I made any changes, I had some issues. So somebody should definitely verify this all before merging. --- nvm.sh | 1 + ...ld strip windows line-endings from nvmrc." | 40 +++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100755 "test/fast/Running \"nvm use\" should strip windows line-endings from nvmrc." diff --git a/nvm.sh b/nvm.sh index b4e871f..dee343f 100755 --- a/nvm.sh +++ b/nvm.sh @@ -141,6 +141,7 @@ nvm_rc_version() { NVMRC_PATH="$(nvm_find_nvmrc)" if [ -e "$NVMRC_PATH" ]; then read -r NVM_RC_VERSION < "$NVMRC_PATH" + NVM_RC_VERSION="$(echo "${NVM_RC_VERSION}" | sed -e 's/[[:space:]]*$//')" echo "Found '$NVMRC_PATH' with version <$NVM_RC_VERSION>" else >&2 echo "No .nvmrc file found" diff --git "a/test/fast/Running \"nvm use\" should strip windows line-endings from nvmrc." "b/test/fast/Running \"nvm use\" should strip windows line-endings from nvmrc." new file mode 100755 index 0000000..0568ff4 --- /dev/null +++ "b/test/fast/Running \"nvm use\" should strip windows line-endings from nvmrc." @@ -0,0 +1,40 @@ +#!/bin/sh + +die () { echo $@ ; cleanup ; exit 1; } + +cleanup() { + rm -rf .nvmrc +} + +. ../../nvm.sh + +# Use a known different version, first. +nvm install v5.6.0 >/dev/null 2>/dev/null +nvm use v5.6.0 >/dev/null 2>/dev/null + +# Verify we're using the version we think. +OUTPUT="$(nvm current)" +EXPECTED_OUTPUT="v5.6.0" +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \ + || die "Expected nvm to be using version $EXPECTED_OUTPUT, but 'nvm current' said $OUTPUT" + +# Write out .nvmrc with windows line-endings. +printf 'v5.5.0\r\n' > .nvmrc + +nvm install >/dev/null 2>/dev/null +EXIT_CODE=$? +[ "_$EXIT_CODE" = "_0" ] \ + || die "Expected 'nvm install' to return a successful exit code; got $EXIT_CODE" + +nvm use >/dev/null 2>/dev/null +EXIT_CODE=$? +[ "_$EXIT_CODE" = "_0" ] \ + || die "Expected 'nvm use' to return a successful exit code; got $EXIT_CODE" + +OUTPUT="$(nvm current)" +EXPECTED_OUTPUT="v5.5.0" +[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \ + || die "Expected nvm to be using version $EXPECTED_OUTPUT from .nvmrc, but 'nvm current' said $OUTPUT" + +cleanup +