From 59939d09e8f7b089d47a8976e5d0a02a3cc8a173 Mon Sep 17 00:00:00 2001 From: stelcheck Date: Thu, 28 Aug 2014 22:45:07 +0900 Subject: [PATCH 1/3] * Make the creation of a symlink an overridable default behaviour --- nvm.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nvm.sh b/nvm.sh index e121fff..01585e3 100644 --- a/nvm.sh +++ b/nvm.sh @@ -647,7 +647,9 @@ nvm() { export NODE_PATH export NVM_PATH="$NVM_VERSION_DIR/lib/node" export NVM_BIN="$NVM_VERSION_DIR/bin" - rm -f "$NVM_DIR/current" && ln -s "$NVM_VERSION_DIR" "$NVM_DIR/current" + if [ "$NVM_SYMLINK_CURRENT" = true ] || [ -z "$NVM_SYMLINK_CURRENT" ]; then + rm -f "$NVM_DIR/current" && ln -s "$NVM_VERSION_DIR" "$NVM_DIR/current" + fi echo "Now using node $VERSION" ;; "run" ) From 9306a9b3f02933632ba5a19bedfb66423e4f84f0 Mon Sep 17 00:00:00 2001 From: stelcheck Date: Fri, 29 Aug 2014 14:57:30 +0900 Subject: [PATCH 2/3] * Unit tests --- ... symlink if $NVM_SYMLINK_CURRENT is false" | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100755 "test/fast/Running \"nvm use x\" should not create the \"current\" symlink if $NVM_SYMLINK_CURRENT is false" diff --git "a/test/fast/Running \"nvm use x\" should not create the \"current\" symlink if $NVM_SYMLINK_CURRENT is false" "b/test/fast/Running \"nvm use x\" should not create the \"current\" symlink if $NVM_SYMLINK_CURRENT is false" new file mode 100755 index 0000000..bf64b18 --- /dev/null +++ "b/test/fast/Running \"nvm use x\" should not create the \"current\" symlink if $NVM_SYMLINK_CURRENT is false" @@ -0,0 +1,85 @@ +#!/bin/bash + +. ../../nvm.sh + +TEST_NODE_VERSION="v0.10.29" + +TEST_COUNT=0 +TEST_PASSED=0 +TEST_FAILED=0 + +function registerExpectedSymlink() { + registerResult ${1} +} + +function registerExpectedNoSymlink() { + [ ${1} -ne 0 ] + registerResult $? +} + +function registerResult() { + result=${1} + + TEST_COUNT=$(($TEST_COUNT + 1)) + + [ ${result} -eq 0 ] \ + && TEST_PASSED=$(($TEST_PASSED + 1)) \ + || TEST_FAILED=$(($TEST_FAILED + 1)) +} + +function cleanup() { + rm -rf ../../${TEST_NODE_VERSION} + rm -f ../../current +} + +function runNvmUse() { + mkdir ../../${TEST_NODE_VERSION} + nvm use ${TEST_NODE_VERSION} &> /dev/null + rmdir ../../${TEST_NODE_VERSION} +} + +function isCurrentSymlinkPresent() { + [ -L ../../current ] +} + +NVM_SYMLINK_CURRENT=false +cleanup +runNvmUse +isCurrentSymlinkPresent && echo "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=false!" +registerExpectedNoSymlink $? + +NVM_SYMLINK_CURRENT=true +cleanup +runNvmUse +isCurrentSymlinkPresent || echo "Expected 'current' symlink to be created when NVM_SYMLINK_CURRENT=true!" +registerExpectedSymlink $? + +NVM_SYMLINK_CURRENT=garbagevalue +cleanup +runNvmUse +isCurrentSymlinkPresent && echo "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT contains a string!" +registerExpectedNoSymlink $? + +NVM_SYMLINK_CURRENT=0 +cleanup +runNvmUse +isCurrentSymlinkPresent && echo "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=0!" +registerExpectedNoSymlink $? + +NVM_SYMLINK_CURRENT=1 +cleanup +runNvmUse +isCurrentSymlinkPresent && echo "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=1!" +registerExpectedNoSymlink $? + +unset NVM_SYMLINK_CURRENT +cleanup +runNvmUse +isCurrentSymlinkPresent || echo "Expected 'current' symlink to be created when NVM_SYMLINK_CURRENT has been unset (default behaviour)!" +registerExpectedSymlink $? + +cleanup + +echo "$(basename "$0"): ${TEST_COUNT} tested, ${TEST_PASSED} passed, ${TEST_FAILED} failed" + +[ ${TEST_FAILED} -ne 0 ] && exit 1 From 83a0efb08597c7781d06c01ff6116dcd279203db Mon Sep 17 00:00:00 2001 From: stelcheck Date: Fri, 29 Aug 2014 15:01:15 +0900 Subject: [PATCH 3/3] * We print stats only on failure * || true --- ... the \"current\" symlink if $NVM_SYMLINK_CURRENT is false" | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git "a/test/fast/Running \"nvm use x\" should not create the \"current\" symlink if $NVM_SYMLINK_CURRENT is false" "b/test/fast/Running \"nvm use x\" should not create the \"current\" symlink if $NVM_SYMLINK_CURRENT is false" index bf64b18..8ae7b29 100755 --- "a/test/fast/Running \"nvm use x\" should not create the \"current\" symlink if $NVM_SYMLINK_CURRENT is false" +++ "b/test/fast/Running \"nvm use x\" should not create the \"current\" symlink if $NVM_SYMLINK_CURRENT is false" @@ -80,6 +80,4 @@ registerExpectedSymlink $? cleanup -echo "$(basename "$0"): ${TEST_COUNT} tested, ${TEST_PASSED} passed, ${TEST_FAILED} failed" - -[ ${TEST_FAILED} -ne 0 ] && exit 1 +[ ${TEST_FAILED} -ne 0 ] && echo "${TEST_COUNT} tested, ${TEST_PASSED} passed, ${TEST_FAILED} failed" && exit 1 || true