Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Aug 24, 2024
1 parent 0ce8f5a commit 37a3f7b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2922,11 +2922,11 @@ nvm_is_natural_num() {

nvm_write_nvmrc() {
local VERSION_STRING
VERSION_STRING=$(nvm_version "${1-$VERSION_STRING}")
if [ "$VERSION_STRING" = '' ] || [ "$VERSION_STRING" = 'N/A' ]; then
VERSION_STRING=$(nvm_version "${1-}")
if [ "${VERSION_STRING}" = '' ] || [ "${VERSION_STRING}" = 'N/A' ]; then
return 1
fi
echo "$VERSION_STRING" | tee "$PWD"/.nvmrc > /dev/null || {
echo "${VERSION_STRING}" | tee "$PWD"/.nvmrc > /dev/null || {
if [ "${NVM_SILENT:-0}" -ne 1 ]; then
nvm_err "Warning: Unable to write version number ($VERSION_STRING) to .nvmrc"
fi
Expand Down
2 changes: 2 additions & 0 deletions test/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ make_fake_node() {
echo >&2 'fake node is not installed'
return 4
}

echo >&2 "fake node is installed: ${FORMATTED_VERSION}"
}

make_fake_iojs() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,36 +8,36 @@ TEST_VERSION="v0.2.4"

if [ -f .nvmrc ]; then mv .nvmrc .nvmrc.orig; fi

cleanup () {
cleanup() {
nvm cache clear
nvm deactivate
nvm unalias default
rm -rf ${NVM_DIR}/v* .nvmrc
rm -rf ${NVM_DIR}/v0.2.4 .nvmrc
if [ -f .nvmrc.orig ]; then mv .nvmrc.orig .nvmrc; fi
unset -f nvm_ls_remote nvm_ls_remote_iojs
}

die () {
die() {
echo "$@"
cleanup
exit 1
}

REMOTE="$PWD/mocks/nvm_ls_remote.txt"
nvm_ls_remote() {
cat "$REMOTE"
cat "${REMOTE}"
}
REMOTE_IOJS="$PWD/mocks/nvm_ls_remote_iojs.txt"
nvm_ls_remote_iojs() {
cat "$REMOTE_IOJS"
cat "${REMOTE_IOJS}"
}

make_fake_node "$TEST_VERSION"
make_fake_node "${TEST_VERSION}"

nvm install --save "$TEST_VERSION" || die "\`nvm install --save $TEST_VERSION\` failed"
nvm install --save "${TEST_VERSION}" || die "\`nvm install --save ${TEST_VERSION}\` failed"
OUTPUT="$(cat .nvmrc)"

nvm_is_valid_version "$(cat .nvmrc)" \
|| die "\`nvm install --save $TEST_VERSION\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"
|| die "\`nvm install --save ${TEST_VERSION}\`+ \`cat .nvmrc\` outputted invalid version: got '${OUTPUT}'"

cleanup

0 comments on commit 37a3f7b

Please sign in to comment.