Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Make the creation of a symlink an overridable default behaviour #514

Merged
merged 3 commits into from
Aug 30, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion nvm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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" )
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/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

[ ${TEST_FAILED} -ne 0 ] && echo "${TEST_COUNT} tested, ${TEST_PASSED} passed, ${TEST_FAILED} failed" && exit 1 || true