2016-07-07 15:00:59 +08:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
set -ex
|
2014-08-29 13:57:30 +08:00
|
|
|
|
|
|
|
. ../../nvm.sh
|
|
|
|
|
|
|
|
TEST_NODE_VERSION="v0.10.29"
|
|
|
|
|
|
|
|
TEST_COUNT=0
|
|
|
|
TEST_PASSED=0
|
|
|
|
TEST_FAILED=0
|
|
|
|
|
2016-07-07 15:00:59 +08:00
|
|
|
registerExpectedSymlink() {
|
2014-08-29 13:57:30 +08:00
|
|
|
registerResult ${1}
|
|
|
|
}
|
|
|
|
|
2016-07-07 15:00:59 +08:00
|
|
|
registerExpectedNoSymlink() {
|
|
|
|
[ $1 -ne 0 ]
|
2014-08-29 13:57:30 +08:00
|
|
|
registerResult $?
|
|
|
|
}
|
|
|
|
|
2016-07-07 15:00:59 +08:00
|
|
|
registerResult() {
|
|
|
|
result="${1}"
|
2014-08-29 13:57:30 +08:00
|
|
|
|
|
|
|
TEST_COUNT=$(($TEST_COUNT + 1))
|
|
|
|
|
|
|
|
[ ${result} -eq 0 ] \
|
|
|
|
&& TEST_PASSED=$(($TEST_PASSED + 1)) \
|
|
|
|
|| TEST_FAILED=$(($TEST_FAILED + 1))
|
|
|
|
}
|
|
|
|
|
2016-07-07 15:00:59 +08:00
|
|
|
cleanup() {
|
|
|
|
rm -rf "${NVM_DIR}/${TEST_NODE_VERSION}"
|
|
|
|
rm -f "${NVM_DIR}/current"
|
2014-08-29 13:57:30 +08:00
|
|
|
}
|
|
|
|
|
2016-07-07 15:00:59 +08:00
|
|
|
runNvmUse() {
|
|
|
|
mkdir "${NVM_DIR}/${TEST_NODE_VERSION}"
|
|
|
|
nvm use --delete-prefix "${TEST_NODE_VERSION}" > /dev/null 2>&1
|
|
|
|
rmdir "${NVM_DIR}/${TEST_NODE_VERSION}"
|
2014-08-29 13:57:30 +08:00
|
|
|
}
|
|
|
|
|
2016-07-07 15:00:59 +08:00
|
|
|
isCurrentSymlinkPresent() {
|
|
|
|
[ -L "${NVM_DIR}/current" ]
|
2014-08-29 13:57:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
NVM_SYMLINK_CURRENT=false
|
|
|
|
cleanup
|
|
|
|
runNvmUse
|
2014-10-15 08:38:42 +08:00
|
|
|
isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=false!"
|
2014-08-29 13:57:30 +08:00
|
|
|
registerExpectedNoSymlink $?
|
|
|
|
|
|
|
|
NVM_SYMLINK_CURRENT=true
|
|
|
|
cleanup
|
|
|
|
runNvmUse
|
2014-10-15 08:38:42 +08:00
|
|
|
isCurrentSymlinkPresent || echo >&2 "Expected 'current' symlink to be created when NVM_SYMLINK_CURRENT=true!"
|
2014-08-29 13:57:30 +08:00
|
|
|
registerExpectedSymlink $?
|
|
|
|
|
|
|
|
NVM_SYMLINK_CURRENT=garbagevalue
|
|
|
|
cleanup
|
|
|
|
runNvmUse
|
2014-10-15 08:38:42 +08:00
|
|
|
isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT contains a string!"
|
2014-08-29 13:57:30 +08:00
|
|
|
registerExpectedNoSymlink $?
|
|
|
|
|
|
|
|
NVM_SYMLINK_CURRENT=0
|
|
|
|
cleanup
|
|
|
|
runNvmUse
|
2014-10-15 08:38:42 +08:00
|
|
|
isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=0!"
|
2014-08-29 13:57:30 +08:00
|
|
|
registerExpectedNoSymlink $?
|
|
|
|
|
|
|
|
NVM_SYMLINK_CURRENT=1
|
|
|
|
cleanup
|
|
|
|
runNvmUse
|
2014-10-15 08:38:42 +08:00
|
|
|
isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=1!"
|
2014-08-29 13:57:30 +08:00
|
|
|
registerExpectedNoSymlink $?
|
|
|
|
|
|
|
|
unset NVM_SYMLINK_CURRENT
|
|
|
|
cleanup
|
|
|
|
runNvmUse
|
2014-10-15 08:38:42 +08:00
|
|
|
isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT has been unset (default behaviour)!"
|
|
|
|
registerExpectedNoSymlink $?
|
2014-08-29 13:57:30 +08:00
|
|
|
|
|
|
|
cleanup
|
|
|
|
|
2016-07-07 15:00:59 +08:00
|
|
|
[ $TEST_FAILED -ne 0 ] && echo "${TEST_COUNT} tested, ${TEST_PASSED} passed, ${TEST_FAILED} failed" && exit 1 || true
|