From b6c357989d31bedb9ae92cb0bf80434887f58f6e Mon Sep 17 00:00:00 2001 From: smikes Date: Sun, 7 Dec 2014 08:34:23 -0800 Subject: [PATCH 01/21] add github dependency on bats --- package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/package.json b/package.json index b25380b..88bde89 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,7 @@ }, "homepage": "https://github.com/creationix/nvm", "devDependencies": { + "bats": "git://github.com/sstephenson/bats", "replace": "~0.3.0", "semver": "~4.1.0", "urchin": "~0.0.4" From 459fca11c56888fe35ee4ddaa45e1ff65dc0fe38 Mon Sep 17 00:00:00 2001 From: smikes Date: Sun, 7 Dec 2014 11:27:37 -0800 Subject: [PATCH 02/21] bats: initial conversion, fast tests only --- test/bats/aliases-circular.bats | 64 ++ test/bats/fast-raw.bats | 1767 +++++++++++++++++++++++++++++++ test/bats/fast.bats | 32 + 3 files changed, 1863 insertions(+) create mode 100644 test/bats/aliases-circular.bats create mode 100644 test/bats/fast-raw.bats create mode 100644 test/bats/fast.bats diff --git a/test/bats/aliases-circular.bats b/test/bats/aliases-circular.bats new file mode 100644 index 0000000..a63ae9d --- /dev/null +++ b/test/bats/aliases-circular.bats @@ -0,0 +1,64 @@ +#!/usr/bin/env bats + +NVM_SRC_DIR="${BATS_TEST_DIRNAME}/../.." + +setup() { + echo 'setup' >&2 + NVM_DIR="${BATS_TMPDIR}" + cd "${NVM_DIR}" + rm -Rf src alias v* + mkdir src alias + + echo loopback > alias/loopback + echo two > alias/one + echo three > alias/two + echo one > alias/three + + echo two > alias/four +} + +teardown() { + echo 'teardown' >&2 + NVM_DIR="${BATS_TMPDIR}" + cd "${NVM_DIR}" + rm -Rf src alias v* +} + +@test './Aliases/circular/nvm_resolve_alias' { + load "${NVM_SRC_DIR}/nvm.sh" + + die () { echo $@ ; exit 1; } + + run nvm_resolve_alias loopback + [ "$output" -eq "∞" ] + + run nvm alias loopback + [ "$output" -eq "loopback -> loopback (-> ∞)" ] + + ALIAS="$(nvm_resolve_alias one)" + [ "_$ALIAS" = "_∞" ] + OUTPUT="$(nvm alias one)" + EXPECTED_OUTPUT="one -> two (-> ∞)" + [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] + + ALIAS="$(nvm_resolve_alias two)" + [ "_$ALIAS" = "_∞" ] + OUTPUT="$(nvm alias two)" + EXPECTED_OUTPUT="two -> three (-> ∞)" + [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] + + ALIAS="$(nvm_resolve_alias three)" + [ "_$ALIAS" = "_∞" ] + OUTPUT="$(nvm alias three)" + EXPECTED_OUTPUT="three -> one (-> ∞)" + [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] + + ALIAS="$(nvm_resolve_alias four)" + [ "_$ALIAS" = "_∞" ] + OUTPUT="$(nvm alias four)" + EXPECTED_OUTPUT="four -> two (-> ∞)" + [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] + + true +} + diff --git a/test/bats/fast-raw.bats b/test/bats/fast-raw.bats new file mode 100644 index 0000000..54f7295 --- /dev/null +++ b/test/bats/fast-raw.bats @@ -0,0 +1,1767 @@ +#!/usr/bin/env bats + +NVM_SRC_DIR="${BATS_TEST_DIRNAME}/../.." +load "${NVM_SRC_DIR}/nvm.sh" + +setup() { + echo 'setup' >&2 + NVM_DIR="${BATS_TMPDIR}" + cd "${NVM_DIR}" + rm -Rf src alias v* + mkdir src alias +} + +teardown() { + echo 'teardown' >&2 + NVM_DIR="${BATS_TMPDIR}" + cd "${NVM_DIR}" + rm -Rf src alias v* +} + +@test './Aliases/nvm_resolve_alias' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#EXIT_CODE=$(nvm_resolve_alias ; echo $?) +#[ $EXIT_CODE = "1" ] || die "nvm_resolve_alias without an argument did not return 1; got $EXIT_CODE" +# +#for i in $(seq 1 10) +# do +# STABLE_ALIAS="$(nvm_resolve_alias test-stable-$i)" +# [ "_$STABLE_ALIAS" = "_v0.0.$i" ] \ +# || die "'nvm_resolve_alias test-stable-$i' was not v0.0.$i; got $STABLE_ALIAS" +# UNSTABLE_ALIAS="$(nvm_resolve_alias test-unstable-$i)" +# [ "_$UNSTABLE_ALIAS" = "_v0.1.$i" ] \ +# || die "'nvm_resolve_alias test-unstable-$i' was not v0.1.$i; got $UNSTABLE_ALIAS" +#done +# +#EXIT_CODE=$(nvm_resolve_alias nonexistent ; echo $?) +#[ $EXIT_CODE = "2" ] || die "'nvm_resolve_alias nonexistent' did not return 2; got $EXIT_CODE" +# +#STABLE="$(nvm_resolve_alias stable)" +#[ "_$STABLE" = "_v0.0.10" ] || die "'nvm_resolve_alias stable' was not v0.0.10; got $STABLE" +# +#UNSTABLE="$(nvm_resolve_alias unstable)" +#[ "_$UNSTABLE" = "_v0.1.10" ] || die "'nvm_resolve_alias unstable' was not v0.1.10; got $UNSTABLE" +# +} + +@test './Aliases/Running "nvm alias " should list but one alias.' { +##!/bin/sh +# +#. ../../../nvm.sh +#[ $(nvm alias test-stable-1 | wc -l) = '2' ] +} + +@test './Aliases/Running "nvm alias" lists implicit aliases when they do not exist' { +##!/bin/sh +# +#. ../../../nvm.sh +# +#die () { echo $@ ; exit 1; } +# +#NVM_ALIAS_OUTPUT=$(nvm alias) +# +#EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)" +#STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e "^stable -> $EXPECTED_STABLE (-> $STABLE_VERSION) (default)$" \ +# || die "nvm alias did not contain the default local stable node version" +# +#EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)" +#UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e "^unstable -> $EXPECTED_UNSTABLE (-> $UNSTABLE_VERSION) (default)$" \ +# || die "nvm alias did not contain the default local unstable node version" +# +} + +@test './Aliases/Running "nvm alias" lists manual aliases instead of implicit aliases when present' { +##!/bin/sh +# +#. ../../../nvm.sh +# +#die () { echo $@ ; cleanup ; exit 1; } +#cleanup () { +# rm -rf ../../../alias/stable +# rm -rf ../../../alias/unstable +# rm -rf ../../../v0.8.1 +# rm -rf ../../../v0.9.1 +#} +# +#mkdir ../../../v0.8.1 +#mkdir ../../../v0.9.1 +# +#EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)" +#STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")" +# +#EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)" +#UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")" +# +#[ "_$STABLE_VERSION" != "_$UNSTABLE_VERSION" ] \ +# || die "stable and unstable versions are the same!" +# +#nvm alias stable "$EXPECTED_UNSTABLE" +#nvm alias unstable "$EXPECTED_STABLE" +# +#NVM_ALIAS_OUTPUT=$(nvm alias) +# +#echo "$NVM_ALIAS_OUTPUT" | \grep -e "^stable -> $EXPECTED_UNSTABLE (-> $UNSTABLE_VERSION)$" \ +# || die "nvm alias did not contain the overridden 'stable' alias" +# +#echo "$NVM_ALIAS_OUTPUT" | \grep -e "^unstable -> $EXPECTED_STABLE (-> $STABLE_VERSION)$" \ +# || die "nvm alias did not contain the overridden 'unstable' alias" +# +#cleanup +# +} + +@test './Aliases/Running "nvm alias" should list all aliases.' { +##!/bin/sh +# +#. ../../../nvm.sh +# +#die () { echo $@ ; exit 1; } +# +#NVM_ALIAS_OUTPUT=$(nvm alias) +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-1 -> 0.0.1 (-> v0.0.1)$' \ +# || die "did not find test-stable-1 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-2 -> 0.0.2 (-> v0.0.2)$' \ +# || die "did not find test-stable-2 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-3 -> 0.0.3 (-> v0.0.3)$' \ +# || die "did not find test-stable-3 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-4 -> 0.0.4 (-> v0.0.4)$' \ +# || die "did not find test-stable-4 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-5 -> 0.0.5 (-> v0.0.5)$' \ +# || die "did not find test-stable-5 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-6 -> 0.0.6 (-> v0.0.6)$' \ +# || die "did not find test-stable-6 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-7 -> 0.0.7 (-> v0.0.7)$' \ +# || die "did not find test-stable-7 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-8 -> 0.0.8 (-> v0.0.8)$' \ +# || die "did not find test-stable-8 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-9 -> 0.0.9 (-> v0.0.9)$' \ +# || die "did not find test-stable-9 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-10 -> 0.0.10 (-> v0.0.10)$' \ +# || die "did not find test-stable-10 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-1 -> 0.1.1 (-> v0.1.1)$' \ +# || die "did not find test-unstable-1 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-2 -> 0.1.2 (-> v0.1.2)$' \ +# || die "did not find test-unstable-2 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-3 -> 0.1.3 (-> v0.1.3)$' \ +# || die "did not find test-unstable-3 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-4 -> 0.1.4 (-> v0.1.4)$' \ +# || die "did not find test-unstable-4 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-5 -> 0.1.5 (-> v0.1.5)$' \ +# || die "did not find test-unstable-5 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-6 -> 0.1.6 (-> v0.1.6)$' \ +# || die "did not find test-unstable-6 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-7 -> 0.1.7 (-> v0.1.7)$' \ +# || die "did not find test-unstable-7 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-8 -> 0.1.8 (-> v0.1.8)$' \ +# || die "did not find test-unstable-8 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-9 -> 0.1.9 (-> v0.1.9)$' \ +# || die "did not find test-unstable-9 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-10 -> 0.1.10 (-> v0.1.10)$' \ +# || die "did not find test-unstable-10 alias" +# +} + +@test './Aliases/setup' { +##!/bin/sh +# +#for i in $(seq 1 10) +# do +# echo 0.0.$i > ../../../alias/test-stable-$i +# mkdir -p ../../../v0.0.$i +# echo 0.1.$i > ../../../alias/test-unstable-$i +# mkdir -p ../../../v0.1.$i +#done +} + +@test './Aliases/teardown' { +##!/bin/sh +# +#for i in $(seq 1 10) +# do +# rm -f "../../../alias/test-stable-$i" +# rm -rf "../../../v0.0.$i" +# rm -f "../../../alias/test-unstable-$i" +# rm -rf "../../../v0.1.$i" +#done +# +#rm -f "../../../alias/stable" +#rm -f "../../../alias/unstable" +# +} + +@test './Listing versions/Running "nvm ls 0.0.2" should display only version 0.0.2.' { +##!/bin/sh +# +#mkdir ../../../v0.0.2 +#mkdir ../../../v0.0.20 +# +#. ../../../nvm.sh +# +#die () { echo $@ ; exit 1; } +# +## The result should contain only the appropriate version numbers. +# +#nvm ls 0.0.2 | grep 'v0.0.2' > /dev/null +#if [ $? -eq 0 ]; then +# echo '"nvm ls 0.0.2" contained v0.0.2' +#fi +# +#nvm ls 0.0.2 | grep 'v0.0.20' > /dev/null +#if [ $? -eq 0 ]; then +# die '"nvm ls 0.0.2" contained v0.0.20' +#fi +# +} + +@test './Listing versions/Running "nvm ls 0.2" should display only 0.2.x versions.' { +##!/bin/sh +# +#mkdir ../../../v0.1.3 +#mkdir ../../../v0.2.3 +#mkdir ../../../v0.20.3 +# +#. ../../../nvm.sh +# +#die () { echo $@ ; exit 1; } +# +## The result should contain only the appropriate version numbers. +# +#nvm ls 0.1 | grep 'v0.2.3' > /dev/null +#if [ $? -eq 0 ]; then +# echo '"nvm ls 0.1" contained v0.2.3' +#fi +# +#nvm ls 0.1 | grep 'v0.20.3' > /dev/null +#if [ $? -eq 0 ]; then +# die '"nvm ls 0.1" contained v0.20.3' +#fi +# +#nvm ls 0.1 | grep 'v0.1.3' > /dev/null +#if [ $? -ne 0 ]; then +# die '"nvm ls 0.1" did not contain v0.1.3' +#fi +# +#nvm ls 0.2 | grep 'v0.2.3' > /dev/null +#if [ $? -ne 0 ]; then +# die '"nvm ls 0.2" did not contain v0.2.3' +#fi +# +#nvm ls 0.2 | grep 'v0.20.3' > /dev/null +#if [ $? -eq 0 ]; then +# die '"nvm ls 0.2" contained v0.20.3' +#fi +# +#nvm ls 0.2 | grep 'v0.2.3' > /dev/null +#if [ $? -ne 0 ]; then +# die '"nvm ls 0.2" did not contain v0.2.3' +#fi +} + +@test './Listing versions/Running "nvm ls foo" should return a nonzero exit code when not found' { +# #!/bin/sh +# +#. ../../../nvm.sh +# +#nvm ls nonexistent_version +#[ "$?" = "3" ] +# +} + +@test './Listing versions/Running "nvm ls node" should return a nonzero exit code when not found' { +# #!/bin/sh +# +#. ../../../nvm.sh +# +#nvm ls node +#[ "$?" = "3" ] +# +} + +@test './Listing versions/Running "nvm ls stable" and "nvm ls unstable" should return the appropriate implicit alias' { +# #!/bin/sh +# +#. ../../../nvm.sh +# +#die () { echo $@ ; exit 1; } +# +#mkdir ../../../v0.2.3 +#mkdir ../../../v0.3.3 +# +#EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)" +#STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")" +# +#EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)" +#UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")" +# +#nvm ls stable | \grep "$STABLE_VERSION" >/dev/null \ +# || die "expected 'nvm ls stable' to give $STABLE_VERSION, got $(nvm ls stable)" +# +#nvm ls unstable | \grep "$UNSTABLE_VERSION" >/dev/null \ +# || die "expected 'nvm ls unstable' to give $UNSTABLE_VERSION, got $(nvm ls unstable)" +# +#mkdir ../../../v0.1.2 +#nvm alias stable 0.1 +# +#nvm ls stable | \grep -v "$STABLE_VERSION" >/dev/null \ +# || die "'nvm ls stable' contained $STABLE_VERSION instead of v0.1.2" +#nvm ls stable | \grep v0.1.2 >/dev/null \ +# || die "'nvm ls stable' did not contain v0.1.2" +# +} + +@test './Listing versions/Running "nvm ls system" should include "system" when appropriate' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#mkdir -p ../../../v0.0.1 +#mkdir -p ../../../v0.0.3 +#mkdir -p ../../../v0.0.9 +#mkdir -p ../../../v0.3.1 +#mkdir -p ../../../v0.3.3 +#mkdir -p ../../../v0.3.9 +# +#nvm_has_system_node() { return 0; } +#nvm ls system | grep system 2>&1 > /dev/null +#[ $? -eq 0 ] || die '"nvm ls system" did not contain "system" when system node is present' +# +#nvm_has_system_node() { return 1; } +#nvm ls system | grep system 2>&1 > /dev/null +#[ $? -ne 0 ] || die '"nvm ls system" contained "system" when system node is not present' +# +} + +@test './Listing versions/Running "nvm ls" should display all installed versions.' { +##!/bin/sh +# +#. ../../../nvm.sh +# +#mkdir ../../../v0.0.1 +#mkdir ../../../v0.0.3 +#mkdir ../../../v0.0.9 +#mkdir ../../../v0.3.1 +#mkdir ../../../v0.3.3 +#mkdir ../../../v0.3.9 +# +## The result should contain the version numbers. +#nvm ls | grep v0.0.1 && +#nvm ls | grep v0.0.3 && +#nvm ls | grep v0.0.9 && +#nvm ls | grep v0.3.1 && +#nvm ls | grep v0.3.3 && +#nvm ls | grep v0.3.9 +} + +@test './Listing versions/Running "nvm ls" should filter out ".nvm"' { +##!/bin/sh +# +#mkdir ../../../v0.1.3 +#mkdir ../../../v0.2.3 +# +#. ../../../nvm.sh +# +#[ -z `nvm ls | grep '^ *\.'` ] +## The result should contain only the appropriate version numbers. +} + +@test './Listing versions/Running "nvm ls" should filter out "versions"' { +##!/bin/sh +# +#mkdir ../../../v0.1.3 +#mkdir ../../../v0.2.3 +#mkdir ../../../versions +# +#. ../../../nvm.sh +# +#[ -z "$(nvm ls | \grep 'versions')" ] +## The result should contain only the appropriate version numbers. +# +} + +@test './Listing versions/Running "nvm ls" should include "system" when appropriate' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#mkdir -p ../../../v0.0.1 +#mkdir -p ../../../v0.0.3 +#mkdir -p ../../../v0.0.9 +#mkdir -p ../../../v0.3.1 +#mkdir -p ../../../v0.3.3 +#mkdir -p ../../../v0.3.9 +# +#nvm_has_system_node() { return 0; } +#nvm ls | grep system 2>&1 > /dev/null +#[ $? -eq 0 ] || die '"nvm ls" did not contain "system" when system node is present' +# +#nvm_has_system_node() { return 1; } +#nvm ls | grep system 2>&1 > /dev/null +#[ $? -ne 0 ] || die '"nvm ls" contained "system" when system node is not present' +# +} + +@test './Listing versions/Running "nvm ls" should list versions in the "versions" directory' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#mkdir -p ../../../versions/v0.12.1 +#mkdir ../../../v0.1.3 +# +#. ../../../nvm.sh +# +#nvm ls 0.12 | grep v0.12.1 || die '"nvm ls" did not list a version in the versions/ directory' +#nvm ls 0.1 | grep v0.1.3 || die '"nvm ls" did not list a version not in the versions/ directory' +# +} + +@test './Listing versions/Running "nvm ls" with node-like versioning vx.x.x should only list a matched version' { +##!/bin/sh +# +#mkdir ../../../v0.1.2 +# +#. ../../../nvm.sh +# +#nvm ls v0.1 | grep v0.1.2 && +#nvm ls v0.1.2 | grep v0.1.2 && +#nvm ls v0.1. | grep v0.1.2 && +#nvm ls v0.1.1 | grep N/A +# +} + +@test './Listing versions/teardown' { +#rmdir ../../../v0.0.1 >/dev/null 2>&1 +#rmdir ../../../v0.0.2 >/dev/null 2>&1 +#rmdir ../../../v0.0.3 >/dev/null 2>&1 +#rmdir ../../../v0.0.9 >/dev/null 2>&1 +#rmdir ../../../v0.0.20 >/dev/null 2>&1 +#rmdir ../../../v0.1.2 >/dev/null 2>&1 +#rmdir ../../../v0.1.3 >/dev/null 2>&1 +#rmdir ../../../v0.2.3 >/dev/null 2>&1 +#rmdir ../../../v0.3.1 >/dev/null 2>&1 +#rmdir ../../../v0.3.3 >/dev/null 2>&1 +#rmdir ../../../v0.3.9 >/dev/null 2>&1 +#rmdir ../../../v0.20.3 >/dev/null 2>&1 +#rmdir ../../../versions >/dev/null 2>&1 +#unalias nvm_has_system_node >/dev/null 2>&1 +#rm -f ../../../alias/stable >/dev/null 2>&1 +#rm -f ../../../alias/unstable >/dev/null 2>&1 +# +} + +@test './Running "nvm alias" should create a file in the alias directory.' { +##!/bin/sh +# +#. ../../nvm.sh +#nvm alias test v0.1.2 +#[ "$(cat ../../alias/test)" = "v0.1.2" ] +} + +@test './Running "nvm current" should display current nvm environment.' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../nvm.sh +# +#nvm deactivate 2>&1 +# +#[ "$(nvm current)" = "system" ] || [ "$(nvm current)" = "none" ] || die '"nvm current" did not report "system" or "none" when deactivated' +# +} + +@test './Running "nvm deactivate" should unset the nvm environment variables.' { +##!/bin/sh +# +#mkdir -p ../../v0.2.3 +# +#die () { echo $@ ; exit 1; } +# +#[ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&2 +# +#. ../../nvm.sh +#nvm use v0.2.3 || die "Failed to activate v0.2.3" +#[ `expr "$PATH" : ".*v0.2.3/.*/bin"` != 0 ] || die "PATH not set up properly" +#[ `expr "$NODE_PATH" : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "NODE_PATH should not contain (npm root -g)" +## ^ note: NODE_PATH should not contain `npm root -g` since globals should not be requireable +# +#nvm deactivate || die "Failed to deactivate v0.2.3" +#[ `expr "$PATH" : ".*v0.2.3/.*/bin"` = 0 ] || die "PATH not cleaned properly" +#[ `expr "$NODE_PATH" : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "NODE_PATH not cleaned properly" +} + +@test './Running "nvm install" with "--reinstall-packages-from" requires a valid version' { +##!/bin/sh +# +#die () { echo $@ ; cleanup ; exit 1; } +#cleanup () { +# rm -rf ../../v0.10.4 +#} +# +#mkdir ../../v0.10.4 +# +#. ../../nvm.sh +# +#nvm deactivate >/dev/null 2>&1 +# +#INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from=0.11 2>&1)" +#EXPECTED_ERROR_MSG="If --reinstall-packages-from is provided, it must point to an installed version of node." +#[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \ +# || die ""nvm install --reinstall-packages-from" should fail when given an uninstalled version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'" +# +#INSTALL_EXIT_CODE="$(nvm install v0.10.5 --reinstall-packages-from=0.11 >/dev/null 2>&1; echo $?)" +#[ "~$INSTALL_EXIT_CODE" = "~5" ] \ +# || die ""nvm install --reinstall-packages-from" should exit with code 5 when given an uninstalled version, got $INSTALL_EXIT_CODE" +# +#INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from=0.10.5 2>&1)" +#EXPECTED_ERROR_MSG="You can't reinstall global packages from the same version of node you're installing." +#[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \ +# || die ""nvm install --reinstall-packages-from" should fail when given the same version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'" +# +#INSTALL_EXIT_CODE="$(nvm install v0.10.5 --reinstall-packages-from=0.10.5 >/dev/null 2>&1; echo $?)" +#[ "~$INSTALL_EXIT_CODE" = "~4" ] \ +# || die ""nvm install --reinstall-packages-from" should exit with code 4 when given the same version, got $INSTALL_EXIT_CODE" +# +} + +@test './Running "nvm install" with an invalid version fails nicely' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../nvm.sh +#[ "$(nvm install invalid.invalid 2>&1)" = "Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions." ] || die "nvm installing an invalid version did not print a nice error message" +# +} + +@test './Running "nvm unalias" should remove the alias file.' { +##!/bin/sh +# +#echo v0.1.2 > ../../alias/test +#. ../../nvm.sh +#nvm unalias test +#! [ -e ../../alias/test ] +} + +@test './Running "nvm uninstall" should remove the appropriate directory.' { +##!/bin/sh +# +#cd ../.. +#mkdir v0.0.1 +#mkdir src/node-v0.0.1 +# +#. ./nvm.sh +#nvm uninstall v0.0.1 +# +#[ ! -d 'v0.0.1' ] && [ ! -d 'src/node-v0.0.1' ] +} + +@test './Running "nvm unload" should unset all function and variables.' { +##!/bin/sh +# +#fail () { echo $@ ; exit 1; } +# +#. ../../nvm.sh +# +#type nvm > /dev/null 2>&1 || fail "NVM not loaded" +# +#nvm unload +# +#type nvm > /dev/null 2>&1 && fail "NVM not unloaded" || exit 0 +# +} + +@test './Running "nvm use foo" where "foo" is circular aborts' { +##!/bin/sh +# +#die () { echo $@ ; cleanup ; exit 1; } +# +#cleanup() { +# rm -rf ../../alias/foo +#} +# +#. ../../nvm.sh +# +#echo 'foo' > ../../alias/foo +# +#OUTPUT="$(nvm use foo 2>&1)" +#EXPECTED_OUTPUT='The alias "foo" leads to an infinite loop. Aborting.' +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \ +# || die "'nvm use foo' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'" +# +#EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)" +#[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got $EXIT_CODE" +# +#cleanup; +# +} + +@test './Running "nvm use system" should work as expected' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../nvm.sh +# +#nvm_has_system_node() { return 0; } +#[ "$(nvm use system 2>&1 | tail -n1)" = "Now using system version of node: $(node -v)." ] || die "Could not use system version of node" +# +#nvm_has_system_node() { return 1; } +#[ "$(nvm use system 2>&1 | tail -n1)" = "System version of node not found." ] || die "Did not report error, system node not found" +#nvm use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found" +# +} + +@test './Running "nvm use x" should create and change the "current" symlink' { +##!/bin/bash +# +#export NVM_SYMLINK_CURRENT=true +#. ../../nvm.sh +# +#rm -rf ../../v0.10.29 +#mkdir ../../v0.10.29 +#nvm use 0.10.29 +#rmdir ../../v0.10.29 +# +#if [ ! -L ../../current ];then +# echo "Expected 'current' symlink to be created!" +# exit 1 +#fi +# +#oldLink="$(readlink ../../current)" +# +#if [ "$(basename $oldLink)" != 'v0.10.29' ];then +# echo "Expected 'current' to point to v0.10.29 but was $oldLink" +# exit 1 +#fi +# +#rm -rf ../../v0.11.13 +#mkdir ../../v0.11.13 +#nvm use 0.11.13 +#rmdir ../../v0.11.13 +# +#newLink="$(readlink ../../current)" +# +#if [ "$(basename $newLink)" != 'v0.11.13' ];then +# echo "Expected 'current' to point to v0.11.13 but was $newLink" +# exit 1 +#fi +} + +@test './Running "nvm use x" should not create the "current" symlink if $NVM_SYMLINK_CURRENT is false' { +##!/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 2>&1 +# rmdir ../../${TEST_NODE_VERSION} +#} +# +#function isCurrentSymlinkPresent() { +# [ -L ../../current ] +#} +# +#NVM_SYMLINK_CURRENT=false +#cleanup +#runNvmUse +#isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=false!" +#registerExpectedNoSymlink $? +# +#NVM_SYMLINK_CURRENT=true +#cleanup +#runNvmUse +#isCurrentSymlinkPresent || echo >&2 "Expected 'current' symlink to be created when NVM_SYMLINK_CURRENT=true!" +#registerExpectedSymlink $? +# +#NVM_SYMLINK_CURRENT=garbagevalue +#cleanup +#runNvmUse +#isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT contains a string!" +#registerExpectedNoSymlink $? +# +#NVM_SYMLINK_CURRENT=0 +#cleanup +#runNvmUse +#isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=0!" +#registerExpectedNoSymlink $? +# +#NVM_SYMLINK_CURRENT=1 +#cleanup +#runNvmUse +#isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=1!" +#registerExpectedNoSymlink $? +# +#unset NVM_SYMLINK_CURRENT +#cleanup +#runNvmUse +#isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT has been unset (default behaviour)!" +#registerExpectedNoSymlink $? +# +#cleanup +# +#[ ${TEST_FAILED} -ne 0 ] && echo "${TEST_COUNT} tested, ${TEST_PASSED} passed, ${TEST_FAILED} failed" && exit 1 || true +# +} + +@test './setup' { +##!/bin/sh +# +#( +# cd ../.. +# +# # Back up +# +# type setopt >/dev/null 2>&1 && setopt NULL_GLOB +# type shopt >/dev/null 2>&1 && shopt -s nullglob +# rm -Rf v* src alias +# mkdir src alias +#) +} + +@test './setup_dir' { +##!/bin/sh +# +#( +# cd ../.. +# +# # Back up +# +# mkdir -p bak +# for SRC in v* src alias; do +# [ -e "$SRC" ] && mv "$SRC" bak +# done +# if [ -d versions ]; then +# mv versions bak +# fi +# true +#) +} + +@test './Sourcing nvm.sh should make the nvm command available.' { +##!/bin/sh +# +#. ../../nvm.sh +#nvm +} + +@test './teardown' { +##!/bin/sh +# +## Remove temporary files +#( +# cd ../.. +# +# type setopt >/dev/null 2>&1 && setopt NULL_GLOB +# type shopt >/dev/null 2>&1 && shopt -s nullglob +# rm -fR v* src alias +#) +} + +@test './teardown_dir' { +##!/bin/sh +# +#( +# cd ../.. +# +# # Restore +# if [ -d bak ] +# then +# mv bak/* . > /dev/null 2>&1 || sleep 0s +# rmdir bak +# fi +# mkdir -p src alias +#) +} + +@test './Unit tests/nvm_alias' { +##!/bin/sh +# +#die () { echo $@ ; cleanup ; exit 1; } +# +#cleanup () { +# rm -rf ../../../alias/test +#} +# +#. ../../../nvm.sh +# +#OUTPUT="$(nvm_alias 2>&1)" +#EXPECTED_OUTPUT='An alias is required.' +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_alias' produced wrong output; got $OUTPUT" +# +#EXIT_CODE="$(nvm_alias >/dev/null 2>&1 ; echo $?)" +#[ "_$EXIT_CODE" = "_1" ] || die "'nvm_alias' exited with $EXIT_CODE, expected 1" +# +#rm -rf ../../../alias/nonexistent +# +#OUTPUT="$(nvm_alias nonexistent 2>&1)" +#EXPECTED_OUTPUT='Alias does not exist.' +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_alias nonexistent' produced wrong output; got $OUTPUT" +# +#EXIT_CODE="$(nvm_alias nonexistent >/dev/null 2>&1 ; echo $?)" +#[ "_$EXIT_CODE" = "_2" ] || die "'nvm_alias nonexistent' exited with $EXIT_CODE, expected 2" +# +#EXPECTED_OUTPUT="0.10" +#nvm alias test "$EXPECTED_OUTPUT" || die "'nvm alias test $EXPECTED_OUTPUT' failed" +#OUTPUT="$(nvm_alias test)" +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_alias test' produced wrong output; got $OUTPUT" +# +#cleanup +# +} + +@test './Unit tests/nvm_checksum' { +##!/bin/sh +# +#cleanup () { +# rm tmp/emptyfile tmp/testfile +# rmdir tmp +#} +#die () { echo $@ ; cleanup; exit 1; } +# +#. ../../../nvm.sh +# +#mkdir -p tmp +#touch tmp/emptyfile +#echo -n "test" > tmp/testfile +# +#nvm_checksum tmp/emptyfile "da39a3ee5e6b4b0d3255bfef95601890afd80709" || die "nvm_checksum on an empty file did not match the SHA1 digest of the empty string" +#nvm_checksum tmp/testfile "da39a3ee5e6b4b0d3255bfef95601890afd80709" && die "nvm_checksum allowed a bad checksum" +# +#cleanup +} + +@test './Unit tests/nvm_find_up' { +##!/bin/sh +# +#die () { echo $@ ; cleanup ; exit 1; } +#setup() { +# cleanup +# mkdir -p tmp_nvm_find_up/a/b/c/d +# touch tmp_nvm_find_up/test +# touch tmp_nvm_find_up/a/b/c/test +#} +#cleanup () { +# rm -rf tmp_nvm_find_up +#} +# +#. ../../../nvm.sh +# +#setup +# +#TEST_DIR="$PWD" +# +#[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up" ] || die "failed to find 1 dir up" +#[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up" ] || die "failed to find 2 dirs up" +#[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b/c nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up/a/b/c" ] || die "failed to find in current dir" +#[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b/c/d nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up/a/b/c" ] || die "failed to find 1 level up from current dir" +# +#cleanup +# +} + +@test './Unit tests/nvm_format_version' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#OUTPUT="$(nvm_format_version 0.1.2)" +#EXPECTED_OUTPUT="v0.1.2" +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_format_version 0.1.2 did not return $EXPECTED_OUTPUT; got $OUTPUT" +# +#OUTPUT="$(nvm_format_version 0.1)" +#EXPECTED_OUTPUT="v0.1.0" +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_format_version 0.1.0 did not return $EXPECTED_OUTPUT; got $OUTPUT" +# +} + +@test './Unit tests/nvm_has' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#nvm_has cat && type cat > /dev/null || die 'nvm_has locates "cat" properly' +# +#[ "~$(nvm_has foobarbaz 2>&1)" = "~" ] || die "nvm_has does not suppress error output" +# +#! nvm_has foobarbaz && ! type foobarbaz >/dev/null 2>&1 || die "nvm_has does not return a nonzero exit code when not found" +# +} + +@test './Unit tests/nvm_has_system_node' { +##!/bin/sh +# +#cleanup () { +# rm ../../../v0.1.2/node +# rmdir ../../../v0.1.2 +#} +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#mkdir ../../../v0.1.2 +#touch ../../../v0.1.2/node +# +#nvm use 0.1.2 +# +#if command -v node; then +# nvm_has_system_node +#else +# ! nvm_has_system_node +#fi +# +#nvm deactivate /dev/null 2>&1 +# +#if command -v node; then +# nvm_has_system_node +#else +# ! nvm_has_system_node +#fi +# +} + +@test './Unit tests/nvm_ls_current' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#return_zero () { return 0; } +# +#[ "$(nvm deactivate > /dev/null 2>&1 ; nvm_ls_current)" = "system" ] || die 'when deactivated, did not return "system"' +# +#TEST_PWD=$(pwd) +#TEST_DIR="$TEST_PWD/nvm_ls_current_tmp" +#rm -rf "$TEST_DIR" +#mkdir "$TEST_DIR" +#ln -s "$(which which)" "$TEST_DIR/which" +#ln -s "$(which dirname)" "$TEST_DIR/dirname" +# +#[ "$(PATH="$TEST_DIR" nvm_ls_current)" = "none" ] || die 'when node not installed, nvm_ls_current did not return "none"' +#[ "@$(PATH="$TEST_DIR" nvm_ls_current 2> /dev/stdout 1> /dev/null)@" = "@@" ] || die 'when node not installed, nvm_ls_current returned error output' +# +#echo "#!/bin/bash" > "$TEST_DIR/node" +#echo "echo 'VERSION FOO!'" > "$TEST_DIR/node" +#chmod a+x "$TEST_DIR/node" +# +#[ "$(alias nvm_tree_contains_path='return_zero' && PATH="$TEST_DIR" nvm_ls_current)" = "VERSION FOO!" ] || die 'when activated, did not return nvm node version' +# +#rm -rf "$TEST_DIR" +# +} + +@test './Unit tests/nvm_ls_remote' { +##!/bin/sh +# +#die () { echo $@ ; cleanup ; exit 1; } +# +#cleanup() { +# unset -f nvm_download +#} +# +#. ../../../nvm.sh +# +## sample output at the time the test was written +#nvm_download() { +# echo 'foo "v0.10.0' +# echo 'foo "v0.10.0' +# echo 'foo "v0.10.1' +# echo 'foo "v0.10.1' +# echo 'foo "v0.10.10' +# echo 'foo "v0.10.10' +# echo 'foo "v0.10.11' +# echo 'foo "v0.10.11' +# echo 'foo "v0.10.12' +# echo 'foo "v0.10.12' +# echo 'foo "v0.10.13' +# echo 'foo "v0.10.13' +# echo 'foo "v0.10.14' +# echo 'foo "v0.10.14' +# echo 'foo "v0.10.15' +# echo 'foo "v0.10.15' +# echo 'foo "v0.10.16' +# echo 'foo "v0.10.16' +# echo 'foo "v0.10.16' +# echo 'foo "v0.10.16' +# echo 'foo "v0.10.17' +# echo 'foo "v0.10.17' +# echo 'foo "v0.10.18' +# echo 'foo "v0.10.18' +# echo 'foo "v0.10.19' +# echo 'foo "v0.10.19' +# echo 'foo "v0.10.2' +# echo 'foo "v0.10.2' +# echo 'foo "v0.10.20' +# echo 'foo "v0.10.20' +# echo 'foo "v0.10.21' +# echo 'foo "v0.10.21' +# echo 'foo "v0.10.22' +# echo 'foo "v0.10.22' +# echo 'foo "v0.10.23' +# echo 'foo "v0.10.23' +# echo 'foo "v0.10.24' +# echo 'foo "v0.10.24' +# echo 'foo "v0.10.25' +# echo 'foo "v0.10.25' +# echo 'foo "v0.10.26' +# echo 'foo "v0.10.26' +# echo 'foo "v0.10.27' +# echo 'foo "v0.10.27' +# echo 'foo "v0.10.28' +# echo 'foo "v0.10.28' +# echo 'foo "v0.10.29' +# echo 'foo "v0.10.29' +# echo 'foo "v0.10.3' +# echo 'foo "v0.10.3' +# echo 'foo "v0.10.30' +# echo 'foo "v0.10.30' +# echo 'foo "v0.10.31' +# echo 'foo "v0.10.31' +# echo 'foo "v0.10.32' +# echo 'foo "v0.10.32' +# echo 'foo "v0.10.4' +# echo 'foo "v0.10.4' +# echo 'foo "v0.10.5' +# echo 'foo "v0.10.5' +# echo 'foo "v0.10.6' +# echo 'foo "v0.10.6' +# echo 'foo "v0.10.7' +# echo 'foo "v0.10.7' +# echo 'foo "v0.10.8' +# echo 'foo "v0.10.8' +# echo 'foo "v0.10.9' +# echo 'foo "v0.10.9' +# echo 'foo "v0.11.0' +# echo 'foo "v0.11.0' +# echo 'foo "v0.11.1' +# echo 'foo "v0.11.1' +# echo 'foo "v0.11.10' +# echo 'foo "v0.11.10' +# echo 'foo "v0.11.11' +# echo 'foo "v0.11.11' +# echo 'foo "v0.11.12' +# echo 'foo "v0.11.12' +# echo 'foo "v0.11.13' +# echo 'foo "v0.11.13' +# echo 'foo "v0.11.14' +# echo 'foo "v0.11.14' +# echo 'foo "v0.11.2' +# echo 'foo "v0.11.2' +# echo 'foo "v0.11.3' +# echo 'foo "v0.11.3' +# echo 'foo "v0.11.4' +# echo 'foo "v0.11.4' +# echo 'foo "v0.11.5' +# echo 'foo "v0.11.5' +# echo 'foo "v0.11.6' +# echo 'foo "v0.11.6' +# echo 'foo "v0.11.7' +# echo 'foo "v0.11.7' +# echo 'foo "v0.11.8' +# echo 'foo "v0.11.8' +# echo 'foo "v0.11.9' +# echo 'foo "v0.11.9' +# echo 'foo "v0.5.1' +# echo 'foo "v0.5.1' +# echo 'foo "v0.5.10' +# echo 'foo "v0.5.10' +# echo 'foo "v0.5.2' +# echo 'foo "v0.5.2' +# echo 'foo "v0.5.3' +# echo 'foo "v0.5.3' +# echo 'foo "v0.5.4' +# echo 'foo "v0.5.4' +# echo 'foo "v0.5.5' +# echo 'foo "v0.5.5' +# echo 'foo "v0.5.6' +# echo 'foo "v0.5.6' +# echo 'foo "v0.5.7' +# echo 'foo "v0.5.7' +# echo 'foo "v0.5.8' +# echo 'foo "v0.5.8' +# echo 'foo "v0.5.9' +# echo 'foo "v0.5.9' +# echo 'foo "v0.6.0' +# echo 'foo "v0.6.0' +# echo 'foo "v0.6.1' +# echo 'foo "v0.6.1' +# echo 'foo "v0.6.10' +# echo 'foo "v0.6.10' +# echo 'foo "v0.6.11' +# echo 'foo "v0.6.11' +# echo 'foo "v0.6.12' +# echo 'foo "v0.6.12' +# echo 'foo "v0.6.13' +# echo 'foo "v0.6.13' +# echo 'foo "v0.6.14' +# echo 'foo "v0.6.14' +# echo 'foo "v0.6.15' +# echo 'foo "v0.6.15' +# echo 'foo "v0.6.16' +# echo 'foo "v0.6.16' +# echo 'foo "v0.6.17' +# echo 'foo "v0.6.17' +# echo 'foo "v0.6.18' +# echo 'foo "v0.6.18' +# echo 'foo "v0.6.19' +# echo 'foo "v0.6.19' +# echo 'foo "v0.6.2' +# echo 'foo "v0.6.2' +# echo 'foo "v0.6.20' +# echo 'foo "v0.6.20' +# echo 'foo "v0.6.21' +# echo 'foo "v0.6.21' +# echo 'foo "v0.6.3' +# echo 'foo "v0.6.3' +# echo 'foo "v0.6.4' +# echo 'foo "v0.6.4' +# echo 'foo "v0.6.5' +# echo 'foo "v0.6.5' +# echo 'foo "v0.6.6' +# echo 'foo "v0.6.6' +# echo 'foo "v0.6.7' +# echo 'foo "v0.6.7' +# echo 'foo "v0.6.8' +# echo 'foo "v0.6.8' +# echo 'foo "v0.6.9' +# echo 'foo "v0.6.9' +# echo 'foo "v0.7.0' +# echo 'foo "v0.7.0' +# echo 'foo "v0.7.1' +# echo 'foo "v0.7.1' +# echo 'foo "v0.7.10' +# echo 'foo "v0.7.10' +# echo 'foo "v0.7.11' +# echo 'foo "v0.7.11' +# echo 'foo "v0.7.12' +# echo 'foo "v0.7.12' +# echo 'foo "v0.7.2' +# echo 'foo "v0.7.2' +# echo 'foo "v0.7.3' +# echo 'foo "v0.7.3' +# echo 'foo "v0.7.4' +# echo 'foo "v0.7.4' +# echo 'foo "v0.7.5' +# echo 'foo "v0.7.5' +# echo 'foo "v0.7.6' +# echo 'foo "v0.7.6' +# echo 'foo "v0.7.7' +# echo 'foo "v0.7.7' +# echo 'foo "v0.7.8' +# echo 'foo "v0.7.8' +# echo 'foo "v0.7.9' +# echo 'foo "v0.7.9' +# echo 'foo "v0.8.0' +# echo 'foo "v0.8.0' +# echo 'foo "v0.8.1' +# echo 'foo "v0.8.1' +# echo 'foo "v0.8.10' +# echo 'foo "v0.8.10' +# echo 'foo "v0.8.11' +# echo 'foo "v0.8.11' +# echo 'foo "v0.8.12' +# echo 'foo "v0.8.12' +# echo 'foo "v0.8.13' +# echo 'foo "v0.8.13' +# echo 'foo "v0.8.14' +# echo 'foo "v0.8.14' +# echo 'foo "v0.8.15' +# echo 'foo "v0.8.15' +# echo 'foo "v0.8.16' +# echo 'foo "v0.8.16' +# echo 'foo "v0.8.17' +# echo 'foo "v0.8.17' +# echo 'foo "v0.8.18' +# echo 'foo "v0.8.18' +# echo 'foo "v0.8.19' +# echo 'foo "v0.8.19' +# echo 'foo "v0.8.2' +# echo 'foo "v0.8.2' +# echo 'foo "v0.8.20' +# echo 'foo "v0.8.20' +# echo 'foo "v0.8.21' +# echo 'foo "v0.8.21' +# echo 'foo "v0.8.22' +# echo 'foo "v0.8.22' +# echo 'foo "v0.8.23' +# echo 'foo "v0.8.23' +# echo 'foo "v0.8.24' +# echo 'foo "v0.8.24' +# echo 'foo "v0.8.25' +# echo 'foo "v0.8.25' +# echo 'foo "v0.8.26' +# echo 'foo "v0.8.26' +# echo 'foo "v0.8.27' +# echo 'foo "v0.8.27' +# echo 'foo "v0.8.28' +# echo 'foo "v0.8.28' +# echo 'foo "v0.8.3' +# echo 'foo "v0.8.3' +# echo 'foo "v0.8.4' +# echo 'foo "v0.8.4' +# echo 'foo "v0.8.5' +# echo 'foo "v0.8.5' +# echo 'foo "v0.8.6' +# echo 'foo "v0.8.6' +# echo 'foo "v0.8.7' +# echo 'foo "v0.8.7' +# echo 'foo "v0.8.8' +# echo 'foo "v0.8.8' +# echo 'foo "v0.8.9' +# echo 'foo "v0.8.9' +# echo 'foo "v0.9.0' +# echo 'foo "v0.9.0' +# echo 'foo "v0.9.1' +# echo 'foo "v0.9.1' +# echo 'foo "v0.9.10' +# echo 'foo "v0.9.10' +# echo 'foo "v0.9.11' +# echo 'foo "v0.9.11' +# echo 'foo "v0.9.12' +# echo 'foo "v0.9.12' +# echo 'foo "v0.9.2' +# echo 'foo "v0.9.2' +# echo 'foo "v0.9.3' +# echo 'foo "v0.9.3' +# echo 'foo "v0.9.4' +# echo 'foo "v0.9.4' +# echo 'foo "v0.9.5' +# echo 'foo "v0.9.5' +# echo 'foo "v0.9.6' +# echo 'foo "v0.9.6' +# echo 'foo "v0.9.7' +# echo 'foo "v0.9.7' +# echo 'foo "v0.9.8' +# echo 'foo "v0.9.8' +# echo 'foo "v0.9.9' +# echo 'foo "v0.9.9' +# echo 'foo "v0.1.100' +# echo 'foo "v0.1.100' +# echo 'foo "v0.1.101' +# echo 'foo "v0.1.101' +# echo 'foo "v0.1.102' +# echo 'foo "v0.1.102' +# echo 'foo "v0.1.103' +# echo 'foo "v0.1.103' +# echo 'foo "v0.1.104' +# echo 'foo "v0.1.104' +# echo 'foo "v0.1.14' +# echo 'foo "v0.1.14' +# echo 'foo "v0.1.15' +# echo 'foo "v0.1.15' +# echo 'foo "v0.1.16' +# echo 'foo "v0.1.16' +# echo 'foo "v0.1.17' +# echo 'foo "v0.1.17' +# echo 'foo "v0.1.18' +# echo 'foo "v0.1.18' +# echo 'foo "v0.1.19' +# echo 'foo "v0.1.19' +# echo 'foo "v0.1.20' +# echo 'foo "v0.1.20' +# echo 'foo "v0.1.21' +# echo 'foo "v0.1.21' +# echo 'foo "v0.1.22' +# echo 'foo "v0.1.22' +# echo 'foo "v0.1.23' +# echo 'foo "v0.1.23' +# echo 'foo "v0.1.24' +# echo 'foo "v0.1.24' +# echo 'foo "v0.1.25' +# echo 'foo "v0.1.25' +# echo 'foo "v0.1.26' +# echo 'foo "v0.1.26' +# echo 'foo "v0.1.27' +# echo 'foo "v0.1.27' +# echo 'foo "v0.1.28' +# echo 'foo "v0.1.28' +# echo 'foo "v0.1.29' +# echo 'foo "v0.1.29' +# echo 'foo "v0.1.30' +# echo 'foo "v0.1.30' +# echo 'foo "v0.1.31' +# echo 'foo "v0.1.31' +# echo 'foo "v0.1.32' +# echo 'foo "v0.1.32' +# echo 'foo "v0.1.33' +# echo 'foo "v0.1.33' +# echo 'foo "v0.1.90' +# echo 'foo "v0.1.90' +# echo 'foo "v0.1.91' +# echo 'foo "v0.1.91' +# echo 'foo "v0.1.92' +# echo 'foo "v0.1.92' +# echo 'foo "v0.1.93' +# echo 'foo "v0.1.93' +# echo 'foo "v0.1.94' +# echo 'foo "v0.1.94' +# echo 'foo "v0.1.95' +# echo 'foo "v0.1.95' +# echo 'foo "v0.1.96' +# echo 'foo "v0.1.96' +# echo 'foo "v0.1.97' +# echo 'foo "v0.1.97' +# echo 'foo "v0.1.98' +# echo 'foo "v0.1.98' +# echo 'foo "v0.1.99' +# echo 'foo "v0.1.99' +# echo 'foo "v0.10.14' +# echo 'foo "v0.10.14' +# echo 'foo "v0.2.0' +# echo 'foo "v0.2.0' +# echo 'foo "v0.2.1' +# echo 'foo "v0.2.1' +# echo 'foo "v0.2.2' +# echo 'foo "v0.2.2' +# echo 'foo "v0.2.3' +# echo 'foo "v0.2.3' +# echo 'foo "v0.2.4' +# echo 'foo "v0.2.4' +# echo 'foo "v0.2.5' +# echo 'foo "v0.2.5' +# echo 'foo "v0.2.6' +# echo 'foo "v0.2.6' +# echo 'foo "v0.3.0' +# echo 'foo "v0.3.0' +# echo 'foo "v0.3.1' +# echo 'foo "v0.3.1' +# echo 'foo "v0.3.2' +# echo 'foo "v0.3.2' +# echo 'foo "v0.3.3' +# echo 'foo "v0.3.3' +# echo 'foo "v0.3.4' +# echo 'foo "v0.3.4' +# echo 'foo "v0.3.5' +# echo 'foo "v0.3.5' +# echo 'foo "v0.3.6' +# echo 'foo "v0.3.6' +# echo 'foo "v0.3.7' +# echo 'foo "v0.3.7' +# echo 'foo "v0.3.8' +# echo 'foo "v0.3.8' +# echo 'foo "v0.4.0' +# echo 'foo "v0.4.0' +# echo 'foo "v0.4.1' +# echo 'foo "v0.4.1' +# echo 'foo "v0.4.10' +# echo 'foo "v0.4.10' +# echo 'foo "v0.4.11' +# echo 'foo "v0.4.11' +# echo 'foo "v0.4.12' +# echo 'foo "v0.4.12' +# echo 'foo "v0.4.2' +# echo 'foo "v0.4.2' +# echo 'foo "v0.4.3' +# echo 'foo "v0.4.3' +# echo 'foo "v0.4.4' +# echo 'foo "v0.4.4' +# echo 'foo "v0.4.5' +# echo 'foo "v0.4.5' +# echo 'foo "v0.4.6' +# echo 'foo "v0.4.6' +# echo 'foo "v0.4.7' +# echo 'foo "v0.4.7' +# echo 'foo "v0.4.8' +# echo 'foo "v0.4.8' +# echo 'foo "v0.4.9' +# echo 'foo "v0.4.9' +# echo 'foo "v0.5.0' +# echo 'foo "v0.5.0' +# echo 'foo "v0.6.1' +# echo 'foo "v0.6.1' +# echo 'foo "v0.6.10' +# echo 'foo "v0.6.10' +# echo 'foo "v0.6.11' +# echo 'foo "v0.6.11' +# echo 'foo "v0.6.12' +# echo 'foo "v0.6.12' +# echo 'foo "v0.6.13' +# echo 'foo "v0.6.13' +# echo 'foo "v0.6.2' +# echo 'foo "v0.6.2' +# echo 'foo "v0.6.3' +# echo 'foo "v0.6.3' +# echo 'foo "v0.6.4' +# echo 'foo "v0.6.4' +# echo 'foo "v0.6.5' +# echo 'foo "v0.6.5' +# echo 'foo "v0.6.6' +# echo 'foo "v0.6.6' +# echo 'foo "v0.6.7' +# echo 'foo "v0.6.7' +# echo 'foo "v0.6.8' +# echo 'foo "v0.6.8' +# echo 'foo "v0.6.9' +# echo 'foo "v0.6.9' +#} +# +#OUTPUT="$(nvm_ls_remote foo)" +#EXIT_CODE="$(nvm_ls_remote foo >/dev/null 2>&1 ; echo $?)" +#[ "_$OUTPUT" = "_N/A" ] || die "nonexistent version did not report N/A" +#[ "_$EXIT_CODE" = "_3" ] || die "nonexistent version did not exit with code 3, got $EXIT_CODE" +# +#OUTPUT="$(nvm_ls_remote)" +#EXPECTED_OUTPUT="$(nvm_download | \egrep -o 'v[0-9]+\.[0-9]+\.[0-9]+' | sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n)" +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "bare nvm_ls_remote did not output expected sorted versions; got $(echo "$OUTPUT") expected $(echo "$EXPECTED_OUTPUT")" +# +#OUTPUT="$(nvm_ls_remote 0.3)" +#EXPECTED_OUTPUT="v0.3.0 +#v0.3.1 +#v0.3.2 +#v0.3.3 +#v0.3.4 +#v0.3.5 +#v0.3.6 +#v0.3.7 +#v0.3.8" +# +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_ls_remote 0.3 did not output 0.3.x versions; got $OUTPUT" +# +## Sanity checks +#OUTPUT="$(nvm_print_implicit_alias remote stable)" +#EXPECTED_OUTPUT="0.10" +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_print_implicit_alias remote stable did not output $EXPECTED_OUTPUT; got $OUTPUT" +# +#OUTPUT="$(nvm_print_implicit_alias remote unstable)" +#EXPECTED_OUTPUT="0.11" +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_print_implicit_alias remote unstable did not output $EXPECTED_OUTPUT; got $OUTPUT" +# +#OUTPUT="$(nvm_ls_remote stable)" +#EXPECTED_OUTPUT="v0.10.32" +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_ls_remote stable did not output $EXPECTED_OUTPUT; got $OUTPUT" +# +#OUTPUT="$(nvm_ls_remote unstable)" +#EXPECTED_OUTPUT="v0.11.14" +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_ls_remote unstable did not output $EXPECTED_OUTPUT; got $OUTPUT" +# +#cleanup +# +} + +@test './Unit tests/nvm_num_version_groups' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#[ "~$(nvm_num_version_groups)" = "~0" ] || die "no args should give 0" +#[ "~$(nvm_num_version_groups a)" = "~1" ] || die "one letter should give 1" +# +#[ "~$(nvm_num_version_groups 1)" = "~1" ] || die "1 should give 1" +#[ "~$(nvm_num_version_groups v1)" = "~1" ] || die "v1 should give 1" +#[ "~$(nvm_num_version_groups v1.)" = "~1" ] || die "v1. should give 1" +# +#[ "~$(nvm_num_version_groups 1.2)" = "~2" ] || die "1.2 should give 2" +#[ "~$(nvm_num_version_groups v1.2)" = "~2" ] || die "v1.2 should give 2" +#[ "~$(nvm_num_version_groups v1.2.)" = "~2" ] || die "v1.2. should give 2" +# +#[ "~$(nvm_num_version_groups 1.2.3)" = "~3" ] || die "1.2.3 should give 3" +#[ "~$(nvm_num_version_groups v1.2.3)" = "~3" ] || die "v1.2.3 should give 3" +#[ "~$(nvm_num_version_groups v1.2.3.)" = "~3" ] || die "v1.2.3. should give 3" +# +} + +@test './Unit tests/nvm_prepend_path' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#TEST_PATH=/usr/bin:/usr/local/bin +# +#NEW_PATH=`nvm_prepend_path "$TEST_PATH" "$NVM_DIR/v0.2.5/bin"` +# +#[ "$NEW_PATH" = "$NVM_DIR/v0.2.5/bin:/usr/bin:/usr/local/bin" ] || die "Not correctly prepended: $NEW_PATH " +# +# +#EMPTY_PATH= +# +#NEW_PATH=`nvm_prepend_path "$EMPTY_PATH" "$NVM_DIR/v0.2.5/bin"` +# +#[ "$NEW_PATH" = "$NVM_DIR/v0.2.5/bin" ] || die "Not correctly prepended: $NEW_PATH " +} + +@test './Unit tests/nvm_print_implicit_alias errors' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#EXPECTED_FIRST_MSG="nvm_print_implicit_alias must be specified with local or remote as the first argument." +#[ "_$(nvm_print_implicit_alias 2>&1)" = "_$EXPECTED_FIRST_MSG" ] \ +# || die "nvm_print_implicit_alias did not require local|remote as first argument" +#[ "_$(nvm_print_implicit_alias foo 2>&1)" = "_$EXPECTED_FIRST_MSG" ] \ +# || die "nvm_print_implicit_alias did not require local|remote as first argument" +# +#FIRST_EXIT_CODE="$(nvm_print_implicit_alias > /dev/null 2>&1 ; echo $?)" +#[ "_$FIRST_EXIT_CODE" = "_1" ] \ +# || die "nvm_print_implicit_alias without local|remote had wrong exit code: expected 1, got $FIRST_EXIT_CODE" +# +#EXPECTED_SECOND_MSG="Only implicit aliases 'stable' and 'unstable' are supported." +#[ "_$(nvm_print_implicit_alias local 2>&1)" = "_$EXPECTED_SECOND_MSG" ] \ +# || die "nvm_print_implicit_alias did not require stable|unstable as second argument" +#[ "_$(nvm_print_implicit_alias local foo 2>&1)" = "_$EXPECTED_SECOND_MSG" ] \ +# || die "nvm_print_implicit_alias did not require stable|unstable as second argument" +# +#SECOND_EXIT_CODE="$(nvm_print_implicit_alias local > /dev/null 2>&1 ; echo $?)" +#[ "_$SECOND_EXIT_CODE" = "_2" ] \ +# || die "nvm_print_implicit_alias without stable|unstable had wrong exit code: expected 2, got $SECOND_EXIT_CODE" +# +} + +@test './Unit tests/nvm_print_implicit_alias success' { +##!/bin/sh +# +#die () { echo $@ ; cleanup ; exit 1; } +#cleanup() { +# rm -rf ../../../v0.2.3 +# rm -rf ../../../v0.3.4 +# rm -rf ../../../v0.4.6 +# rm -rf ../../../v0.5.7 +# rm -rf ../../../v0.7.7 +# unset -f nvm_ls_remote +#} +# +#. ../../../nvm.sh +# +#mkdir ../../../v0.2.3 +#mkdir ../../../v0.3.4 +#mkdir ../../../v0.4.6 +#mkdir ../../../v0.5.7 +#mkdir ../../../v0.7.7 +# +#LATEST_STABLE="$(nvm_print_implicit_alias local stable)" +#[ "_$LATEST_STABLE" = "_0.4" ] || die "local stable is not latest even minor: expected 0.4, got $LATEST_STABLE" +# +#LATEST_UNSTABLE="$(nvm_print_implicit_alias local unstable)" +#[ "_$LATEST_UNSTABLE" = "_0.7" ] || die "local unstable is not latest odd minor: expected 0.7, got $LATEST_UNSTABLE" +# +#nvm_ls_remote() { +# echo "v0.4.3" +# echo "v0.5.4" +# echo "v0.6.6" +# echo "v0.7.7" +# echo "v0.9.7" +# echo "v0.4.3" +# echo "v0.5.4" +# echo "v0.6.6" +# echo "v0.7.7" +# echo "v0.9.7" +#} +# +#LATEST_STABLE="$(nvm_print_implicit_alias remote stable)" +#[ "_$LATEST_STABLE" = "_0.6" ] || die "remote stable is not latest even minor: expected 0.6, got $LATEST_STABLE" +# +#LATEST_UNSTABLE="$(nvm_print_implicit_alias remote unstable)" +#[ "_$LATEST_UNSTABLE" = "_0.9" ] || die "remote unstable is not latest odd minor: expected 0.9, got $LATEST_UNSTABLE" +# +#cleanup +# +} + +@test './Unit tests/nvm_remote_version' { +##!/bin/sh +# +#die () { echo $@ ; cleanup ; exit 1; } +# +#cleanup() { +# unset -f nvm_ls_remote +#} +# +#. ../../../nvm.sh +# +#nvm_ls_remote() { +# echo "N/A" +#} +# +#OUTPUT="$(nvm_remote_version foo)" +#EXIT_CODE="$(nvm_remote_version foo >/dev/null 2>&1 ; echo $?)" +# +#[ "_$OUTPUT" = "_N/A" ] || die "nonexistent version did not report N/A" +#[ "_$EXIT_CODE" = "_3" ] || die "nonexistent version did not exit with code 3, got $EXIT_CODE" +# +#nvm_ls_remote() { +# echo "test output" +# echo "more test output" +# echo "pattern received: _$1_" +#} +# +#OUTPUT="$(nvm_remote_version foo)" +#EXIT_CODE="$(nvm_remote_version foo >/dev/null 2>&1 ; echo $?)" +# +#[ "_$OUTPUT" = "_pattern received: _foo_" ] \ +# || die "nvm_remote_version foo did not return last line only of nvm_ls_remote foo; got $OUTPUT" +#[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version foo did not exit with 0, got $EXIT_CODE" +# +#cleanup +# +} + +@test './Unit tests/nvm_strip_path' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#TEST_PATH=$NVM_DIR/v0.10.5/bin:/usr/bin:$NVM_DIR/v0.11.5/bin:$NVM_DIR/v0.9.5/bin:/usr/local/bin:$NVM_DIR/v0.2.5/bin +# +#STRIPPED_PATH=`nvm_strip_path "$TEST_PATH" "/bin"` +# +#[ "$STRIPPED_PATH" = "/usr/bin:/usr/local/bin" ] || die "Not correctly stripped: $STRIPPED_PATH " +} + +@test './Unit tests/nvm_tree_contains_path' { +##!/bin/sh +# +#cleanup () { +# rm tmp/node +# rmdir tmp +# rm tmp2/node +# rmdir tmp2 +#} +#die () { echo $@ ; cleanup; exit 1; } +# +#. ../../../nvm.sh +# +#mkdir -p tmp +#touch tmp/node +#mkdir -p tmp2 +#touch tmp2/node +# +#[ "$(nvm_tree_contains_path 2>&1)" = "both the tree and the node path are required" ] || die 'incorrect error message with no args' +#[ "$(nvm_tree_contains_path > /dev/null 2>&1 ; echo $?)" = "2" ] || die 'incorrect error code with no args' +#[ "$(nvm_tree_contains_path tmp 2>&1)" = "both the tree and the node path are required" ] || die 'incorrect error message with one arg' +#[ "$(nvm_tree_contains_path > /dev/null 2>&1 ; echo $?)" = "2" ] || die 'incorrect error code with one arg' +# +#nvm_tree_contains_path tmp tmp/node || die '"tmp" should contain "tmp/node"' +# +#nvm_tree_contains_path tmp tmp2/node && die '"tmp" should not contain "tmp2/node"' +# +#nvm_tree_contains_path tmp2 tmp2/node || die '"tmp2" should contain "tmp2/node"' +# +#nvm_tree_contains_path tmp2 tmp/node && die '"tmp2" should not contain "tmp/node"' +# +#cleanup +# +} + +@test './Unit tests/nvm_validate_implicit_alias' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#EXPECTED_MSG="Only implicit aliases 'stable' and 'unstable' are supported." +#[ "_$(nvm_validate_implicit_alias 2>&1)" = "_$EXPECTED_MSG" ] \ +# || die "nvm_validate_implicit_alias did not require stable|unstable" +#[ "_$(nvm_validate_implicit_alias foo 2>&1)" = "_$EXPECTED_MSG" ] \ +# || die "nvm_validate_implicit_alias did not require stable|unstable" +# +#EXIT_CODE="$(nvm_validate_implicit_alias >/dev/null 2>&1 ; echo $?)" +#[ "_$EXIT_CODE" = "_1" ] \ +# || die "nvm_validate_implicit_alias without stable|unstable had wrong exit code: expected 1, got $EXIT_CODE" +# +#nvm_validate_implicit_alias stable || die "nvm_validate_implicit_alias stable did not exit 0" +#nvm_validate_implicit_alias unstable || die "nvm_validate_implicit_alias unstable did not exit 0" +# +} + +@test './Unit tests/nvm_version_dir' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#[ "$(nvm_version_dir)" = "$NVM_DIR/versions" ] || die '"nvm_version_dir" did not return new dir path' +#[ "$(nvm_version_dir new)" = "$(nvm_version_dir)" ] || die '"nvm_version_dir new" did not return new dir path' +#[ "$(nvm_version_dir old)" = "$NVM_DIR" ] || die '"nvm_version_dir old" did not return old dir path' +#[ "$(nvm_version_dir foo 2>&1)" = "unknown version dir" ] || die '"nvm_version_dir foo" did not error out' +# +} + +@test './Unit tests/nvm_version_greater' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#nvm_version_greater 0.10.0 0.2.12 || die '"nvm_version_greater 0.10.0 0.2.12" did not return true' +# +#if nvm_version_greater 0.10.0 0.20.12; then +# die '"nvm_version_greater 0.10.0 0.20.12" returned true' +#fi +# +#if nvm_version_greater 0.10.0 0.10.0; then +# die '"nvm_version_greater" returned false for the same two versions' +#fi +# +} + +@test './Unit tests/nvm_version_path' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#[ "$(nvm_version_path foo)" = "$NVM_DIR/foo" ] || die '"nvm_version_path foo" did not return correct location' +#[ "$(nvm_version_path 2>&1)" = "version is required" ] || die '"nvm_version_path" did not error out' +#[ "$(nvm_version_path v0.11.0)" = "$NVM_DIR/v0.11.0" ] || die 'old version has the wrong path' +#[ "$(nvm_version_path v0.12.0)" = "$NVM_DIR/versions/v0.12.0" ] || die 'new version has the wrong path' +# +} + diff --git a/test/bats/fast.bats b/test/bats/fast.bats new file mode 100644 index 0000000..cd7d559 --- /dev/null +++ b/test/bats/fast.bats @@ -0,0 +1,32 @@ +#!/usr/bin/env bats + +NVM_SRC_DIR="${BATS_TEST_DIRNAME}/../.." +load "${NVM_SRC_DIR}/nvm.sh" + +setup() { + echo 'setup' >&2 + NVM_DIR="${BATS_TMPDIR}" + cd "${NVM_DIR}" + rm -Rf src alias v* + mkdir src alias +} + +teardown() { + echo 'teardown' >&2 + NVM_DIR="${BATS_TMPDIR}" + cd "${NVM_DIR}" + rm -Rf src alias v* +} + +@test "'nvm' command defined in environment" { + run nvm + [ "$status" -eq 0 ] +} + +@test "Running 'nvm alias' should create a file in the alias directory." { + run nvm alias test v0.1.2 + [ "$status" -eq 0 ] + result=$(cat "alias/test") + [ "$result" = "v0.1.2" ] +} + From a052705c612504bd39650fa1977c1fe0f3af884f Mon Sep 17 00:00:00 2001 From: smikes Date: Sun, 7 Dec 2014 11:27:55 -0800 Subject: [PATCH 03/21] initial editorconfig --- .editorconfig | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .editorconfig diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0dda7bf --- /dev/null +++ b/.editorconfig @@ -0,0 +1,10 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +[**/*.bats] +indent_size = 4 +indent_style = space \ No newline at end of file From b503a98b5b447a468311aeb5a5d2cfd2e0305e75 Mon Sep 17 00:00:00 2001 From: smikes Date: Sun, 7 Dec 2014 11:28:10 -0800 Subject: [PATCH 04/21] bats: add npm script --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 88bde89..40fec67 100644 --- a/package.json +++ b/package.json @@ -11,7 +11,8 @@ "test/slow": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=slow test-$shell", "test/install_script": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=install_script test-$shell", "test/installation": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=installation test-$shell", - "test/sourcing": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=sourcing test-$shell" + "test/sourcing": "shell=$(basename -- $(ps -o comm= $(ps -o ppid= -p $PPID)) | sed 's/^-//'); make TEST_SUITE=sourcing test-$shell", + "bats": "bats test/bats" }, "repository": { "type": "git", From 0852f2e7799ba58e3bea50cd993d0e4ce2bd9051 Mon Sep 17 00:00:00 2001 From: smikes Date: Sun, 7 Dec 2014 11:28:28 -0800 Subject: [PATCH 05/21] ignore: add emacs backup files --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 852b572..aaf0a69 100644 --- a/.gitignore +++ b/.gitignore @@ -13,3 +13,5 @@ npm-debug.log .DS_Store current + +*~ From 7e0fc2ea727fc5921c4e5fa2faf6f625c6907c96 Mon Sep 17 00:00:00 2001 From: smikes Date: Sun, 7 Dec 2014 11:55:02 -0800 Subject: [PATCH 06/21] aliases-circular: steal test helper from rbenv and use it --- test/bats/aliases-circular.bats | 46 +++++------- test/bats/test_helper.bash | 127 ++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+), 26 deletions(-) create mode 100644 test/bats/test_helper.bash diff --git a/test/bats/aliases-circular.bats b/test/bats/aliases-circular.bats index a63ae9d..e10fadc 100644 --- a/test/bats/aliases-circular.bats +++ b/test/bats/aliases-circular.bats @@ -1,5 +1,7 @@ #!/usr/bin/env bats +load test_helper + NVM_SRC_DIR="${BATS_TEST_DIRNAME}/../.." setup() { @@ -30,35 +32,27 @@ teardown() { die () { echo $@ ; exit 1; } run nvm_resolve_alias loopback - [ "$output" -eq "∞" ] - + assert_success "∞" run nvm alias loopback - [ "$output" -eq "loopback -> loopback (-> ∞)" ] + assert_success "loopback -> loopback (-> ∞)" - ALIAS="$(nvm_resolve_alias one)" - [ "_$ALIAS" = "_∞" ] - OUTPUT="$(nvm alias one)" - EXPECTED_OUTPUT="one -> two (-> ∞)" - [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] + run nvm_resolve_alias one + assert_success "∞" + run nvm alias one + assert_success "one -> two (-> ∞)" - ALIAS="$(nvm_resolve_alias two)" - [ "_$ALIAS" = "_∞" ] - OUTPUT="$(nvm alias two)" - EXPECTED_OUTPUT="two -> three (-> ∞)" - [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] + run nvm_resolve_alias two + assert_success "∞" + run nvm alias two + assert_success "two -> three (-> ∞)" - ALIAS="$(nvm_resolve_alias three)" - [ "_$ALIAS" = "_∞" ] - OUTPUT="$(nvm alias three)" - EXPECTED_OUTPUT="three -> one (-> ∞)" - [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] + run nvm_resolve_alias three + assert_success "∞" + run nvm alias three + assert_success "three -> one (-> ∞)" - ALIAS="$(nvm_resolve_alias four)" - [ "_$ALIAS" = "_∞" ] - OUTPUT="$(nvm alias four)" - EXPECTED_OUTPUT="four -> two (-> ∞)" - [ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] - - true + run nvm_resolve_alias four + assert_success "∞" + run nvm alias four + assert_success "four -> two (-> ∞)" } - diff --git a/test/bats/test_helper.bash b/test/bats/test_helper.bash new file mode 100644 index 0000000..be36d22 --- /dev/null +++ b/test/bats/test_helper.bash @@ -0,0 +1,127 @@ +# test_helper.bash stolen from rbenv +# +#unset RBENV_VERSION +#unset RBENV_DIR + +if enable -f "${BATS_TEST_DIRNAME}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then + RBENV_TEST_DIR="$(realpath "$BATS_TMPDIR")/rbenv" +else + if [ -n "$RBENV_NATIVE_EXT" ]; then + echo "rbenv: failed to load \`realpath' builtin" >&2 + exit 1 + fi + RBENV_TEST_DIR="${BATS_TMPDIR}/rbenv" +fi + +# guard against executing this block twice due to bats internals +if [ "$RBENV_ROOT" != "${RBENV_TEST_DIR}/root" ]; then + export RBENV_ROOT="${RBENV_TEST_DIR}/root" + export HOME="${RBENV_TEST_DIR}/home" + + PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin + PATH="${RBENV_TEST_DIR}/bin:$PATH" + PATH="${BATS_TEST_DIRNAME}/../libexec:$PATH" + PATH="${BATS_TEST_DIRNAME}/libexec:$PATH" + PATH="${RBENV_ROOT}/shims:$PATH" + export PATH +fi + +teardown() { + rm -rf "$RBENV_TEST_DIR" +} + +flunk() { + { if [ "$#" -eq 0 ]; then cat - + else echo "$@" + fi + } | sed "s:${RBENV_TEST_DIR}:TEST_DIR:g" >&2 + return 1 +} + +assert_success() { + if [ "$status" -ne 0 ]; then + flunk "command failed with exit status $status" + elif [ "$#" -gt 0 ]; then + assert_output "$1" + fi +} + +assert_failure() { + if [ "$status" -eq 0 ]; then + flunk "expected failed exit status" + elif [ "$#" -gt 0 ]; then + assert_output "$1" + fi +} + +assert_equal() { + if [ "$1" != "$2" ]; then + { echo "expected: $1" + echo "actual: $2" + } | flunk + fi +} + +assert_output() { + local expected + if [ $# -eq 0 ]; then expected="$(cat -)" + else expected="$1" + fi + assert_equal "$expected" "$output" +} + +assert_line() { + if [ "$1" -ge 0 ] 2>/dev/null; then + assert_equal "$2" "${lines[$1]}" + else + local line + for line in "${lines[@]}"; do + if [ "$line" = "$1" ]; then return 0; fi + done + flunk "expected line \`$1'" + fi +} + +refute_line() { + if [ "$1" -ge 0 ] 2>/dev/null; then + local num_lines="${#lines[@]}" + if [ "$1" -lt "$num_lines" ]; then + flunk "output has $num_lines lines" + fi + else + local line + for line in "${lines[@]}"; do + if [ "$line" = "$1" ]; then + flunk "expected to not find line \`$line'" + fi + done + fi +} + +assert() { + if ! "$@"; then + flunk "failed: $@" + fi +} + +# Output a modified PATH that ensures that the given executable is not present, +# but in which system utils necessary for rbenv operation are still available. +path_without() { + local exe="$1" + local path="${PATH}:" + local found alt util + for found in $(which -a "$exe"); do + found="${found%/*}" + if [ "$found" != "${RBENV_ROOT}/shims" ]; then + alt="${RBENV_TEST_DIR}/$(echo "${found#/}" | tr '/' '-')" + mkdir -p "$alt" + for util in bash head cut readlink greadlink; do + if [ -x "${found}/$util" ]; then + ln -s "${found}/$util" "${alt}/$util" + fi + done + path="${path/${found}:/${alt}:}" + fi + done + echo "${path%:}" +} From 0592908fe76327e9dd91401baf0b941350ef6297 Mon Sep 17 00:00:00 2001 From: smikes Date: Sun, 7 Dec 2014 11:55:33 -0800 Subject: [PATCH 07/21] aliases.bats: alias tests --- test/bats/aliases.bats | 171 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 171 insertions(+) create mode 100644 test/bats/aliases.bats diff --git a/test/bats/aliases.bats b/test/bats/aliases.bats new file mode 100644 index 0000000..906804c --- /dev/null +++ b/test/bats/aliases.bats @@ -0,0 +1,171 @@ +#!/usr/bin/env bats + +load test_helper + +NVM_SRC_DIR="${BATS_TEST_DIRNAME}/../.." +NVM_DIR="${BATS_TMPDIR}" +load "${NVM_SRC_DIR}/nvm.sh" + +setup() { + echo 'setup' >&2 + cd "${NVM_DIR}" + rm -Rf src alias v* + mkdir src alias + for i in $(seq 1 10) + do + echo 0.0.$i > alias/test-stable-$i + mkdir -p v0.0.$i + echo 0.1.$i > alias/test-unstable-$i + mkdir -p v0.1.$i + done +} + +teardown() { + echo 'teardown' >&2 + cd "${NVM_DIR}" + rm -Rf src alias v* +} + +@test './Aliases/nvm_resolve_alias' { + + run nvm_resolve_alias + [ "$status" -eq 1 ] + + for i in $(seq 1 10) + do + run nvm_resolve_alias test-stable-$i + assert_success "v0.0.$i" + + run nvm_resolve_alias test-unstable-$i + assert_success "v0.1.$i" + done + + run nvm_resolve_alias nonexistent + assert_failure + + run nvm_resolve_alias stable + assert_success "v0.0.10" + + run nvm_resolve_alias unstable + assert_success "v0.1.10" +} + +@test './Aliases/Running "nvm alias " should list but one alias.' { +##!/bin/sh +# +#. ../../../nvm.sh +#[ $(nvm alias test-stable-1 | wc -l) = '2' ] +} + +@test './Aliases/Running "nvm alias" lists implicit aliases when they do not exist' { +##!/bin/sh +# +#. ../../../nvm.sh +# +#die () { echo $@ ; exit 1; } +# +#NVM_ALIAS_OUTPUT=$(nvm alias) +# +#EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)" +#STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e "^stable -> $EXPECTED_STABLE (-> $STABLE_VERSION) (default)$" \ +# || die "nvm alias did not contain the default local stable node version" +# +#EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)" +#UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e "^unstable -> $EXPECTED_UNSTABLE (-> $UNSTABLE_VERSION) (default)$" \ +# || die "nvm alias did not contain the default local unstable node version" +# +} + +@test './Aliases/Running "nvm alias" lists manual aliases instead of implicit aliases when present' { +##!/bin/sh +# +#. ../../../nvm.sh +# +#die () { echo $@ ; cleanup ; exit 1; } +#cleanup () { +# rm -rf ../../../alias/stable +# rm -rf ../../../alias/unstable +# rm -rf ../../../v0.8.1 +# rm -rf ../../../v0.9.1 +#} +# +#mkdir ../../../v0.8.1 +#mkdir ../../../v0.9.1 +# +#EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)" +#STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")" +# +#EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)" +#UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")" +# +#[ "_$STABLE_VERSION" != "_$UNSTABLE_VERSION" ] \ +# || die "stable and unstable versions are the same!" +# +#nvm alias stable "$EXPECTED_UNSTABLE" +#nvm alias unstable "$EXPECTED_STABLE" +# +#NVM_ALIAS_OUTPUT=$(nvm alias) +# +#echo "$NVM_ALIAS_OUTPUT" | \grep -e "^stable -> $EXPECTED_UNSTABLE (-> $UNSTABLE_VERSION)$" \ +# || die "nvm alias did not contain the overridden 'stable' alias" +# +#echo "$NVM_ALIAS_OUTPUT" | \grep -e "^unstable -> $EXPECTED_STABLE (-> $STABLE_VERSION)$" \ +# || die "nvm alias did not contain the overridden 'unstable' alias" +# +#cleanup +# +} + +@test './Aliases/Running "nvm alias" should list all aliases.' { +##!/bin/sh +# +#. ../../../nvm.sh +# +#die () { echo $@ ; exit 1; } +# +#NVM_ALIAS_OUTPUT=$(nvm alias) +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-1 -> 0.0.1 (-> v0.0.1)$' \ +# || die "did not find test-stable-1 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-2 -> 0.0.2 (-> v0.0.2)$' \ +# || die "did not find test-stable-2 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-3 -> 0.0.3 (-> v0.0.3)$' \ +# || die "did not find test-stable-3 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-4 -> 0.0.4 (-> v0.0.4)$' \ +# || die "did not find test-stable-4 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-5 -> 0.0.5 (-> v0.0.5)$' \ +# || die "did not find test-stable-5 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-6 -> 0.0.6 (-> v0.0.6)$' \ +# || die "did not find test-stable-6 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-7 -> 0.0.7 (-> v0.0.7)$' \ +# || die "did not find test-stable-7 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-8 -> 0.0.8 (-> v0.0.8)$' \ +# || die "did not find test-stable-8 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-9 -> 0.0.9 (-> v0.0.9)$' \ +# || die "did not find test-stable-9 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-10 -> 0.0.10 (-> v0.0.10)$' \ +# || die "did not find test-stable-10 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-1 -> 0.1.1 (-> v0.1.1)$' \ +# || die "did not find test-unstable-1 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-2 -> 0.1.2 (-> v0.1.2)$' \ +# || die "did not find test-unstable-2 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-3 -> 0.1.3 (-> v0.1.3)$' \ +# || die "did not find test-unstable-3 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-4 -> 0.1.4 (-> v0.1.4)$' \ +# || die "did not find test-unstable-4 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-5 -> 0.1.5 (-> v0.1.5)$' \ +# || die "did not find test-unstable-5 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-6 -> 0.1.6 (-> v0.1.6)$' \ +# || die "did not find test-unstable-6 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-7 -> 0.1.7 (-> v0.1.7)$' \ +# || die "did not find test-unstable-7 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-8 -> 0.1.8 (-> v0.1.8)$' \ +# || die "did not find test-unstable-8 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-9 -> 0.1.9 (-> v0.1.9)$' \ +# || die "did not find test-unstable-9 alias" +#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-10 -> 0.1.10 (-> v0.1.10)$' \ +# || die "did not find test-unstable-10 alias" +# +} + From 7f0667013e3f5b8d7f84382c1002a83749e1cd05 Mon Sep 17 00:00:00 2001 From: smikes Date: Mon, 8 Dec 2014 06:40:46 -0800 Subject: [PATCH 08/21] convert two more tests --- test/bats/aliases.bats | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/test/bats/aliases.bats b/test/bats/aliases.bats index 906804c..bfe2bca 100644 --- a/test/bats/aliases.bats +++ b/test/bats/aliases.bats @@ -51,13 +51,21 @@ teardown() { } @test './Aliases/Running "nvm alias " should list but one alias.' { -##!/bin/sh -# -#. ../../../nvm.sh -#[ $(nvm alias test-stable-1 | wc -l) = '2' ] + run nvm alias test-stable-1 + assert_success + + local num_lines="${#lines[@]}" + assert_equal $num_lines 2 } @test './Aliases/Running "nvm alias" lists implicit aliases when they do not exist' { + run nvm alias + expected_stable="$(nvm_print_implicit_alias local stable)" + stable_version="$(nvm_version "${expected_stable}")" + + assert_line 20 "stable -> ${expected_stable} (-> ${stable_version}) (default)" + assert_line 21 "stable -> ${expected_stable} (-> ${stable_version}) (default)" + ##!/bin/sh # #. ../../../nvm.sh From 98a48ef52abb7d3c371a6ce195d1949b101a8619 Mon Sep 17 00:00:00 2001 From: smikes Date: Sun, 21 Dec 2014 10:13:32 -0700 Subject: [PATCH 09/21] add test files (wip) --- test/bats/aliases.bats | 156 +--- test/bats/fast-raw.bats | 4 +- test/bats/fast2.bats | 1589 ++++++++++++++++++++++++++++++++++++ test/bats/test.bats | 21 + test/bats/test_helper.bash | 14 +- 5 files changed, 1668 insertions(+), 116 deletions(-) create mode 100644 test/bats/fast2.bats create mode 100644 test/bats/test.bats diff --git a/test/bats/aliases.bats b/test/bats/aliases.bats index bfe2bca..f5ef2f7 100644 --- a/test/bats/aliases.bats +++ b/test/bats/aliases.bats @@ -34,20 +34,20 @@ teardown() { for i in $(seq 1 10) do run nvm_resolve_alias test-stable-$i - assert_success "v0.0.$i" + assert_success "v0.0.$i" "nvm_resolve_alias test-stable-$i" run nvm_resolve_alias test-unstable-$i - assert_success "v0.1.$i" + assert_success "v0.1.$i" "nvm_resolve_alias test-unstable-$i" done run nvm_resolve_alias nonexistent assert_failure run nvm_resolve_alias stable - assert_success "v0.0.10" + assert_success "v0.0.10" "'nvm_resolve_alias stable' was not v0.0.10" run nvm_resolve_alias unstable - assert_success "v0.1.10" + assert_success "v0.1.10" "'nvm_resolve_alias unstable' was not v0.1.10" } @test './Aliases/Running "nvm alias " should list but one alias.' { @@ -60,120 +60,52 @@ teardown() { @test './Aliases/Running "nvm alias" lists implicit aliases when they do not exist' { run nvm alias - expected_stable="$(nvm_print_implicit_alias local stable)" - stable_version="$(nvm_version "${expected_stable}")" - assert_line 20 "stable -> ${expected_stable} (-> ${stable_version}) (default)" - assert_line 21 "stable -> ${expected_stable} (-> ${stable_version}) (default)" - -##!/bin/sh -# -#. ../../../nvm.sh -# -#die () { echo $@ ; exit 1; } -# -#NVM_ALIAS_OUTPUT=$(nvm alias) -# -#EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)" -#STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e "^stable -> $EXPECTED_STABLE (-> $STABLE_VERSION) (default)$" \ -# || die "nvm alias did not contain the default local stable node version" -# -#EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)" -#UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e "^unstable -> $EXPECTED_UNSTABLE (-> $UNSTABLE_VERSION) (default)$" \ -# || die "nvm alias did not contain the default local unstable node version" -# + assert_line 20 "stable -> 0.0 (-> v0.0.10) (default)" "nvm alias did not contain the default local stable node version" + assert_line 21 "unstable -> 0.1 (-> v0.1.10) (default)" "nvm alias did not contain the default local unstable node version" } @test './Aliases/Running "nvm alias" lists manual aliases instead of implicit aliases when present' { -##!/bin/sh -# -#. ../../../nvm.sh -# -#die () { echo $@ ; cleanup ; exit 1; } -#cleanup () { -# rm -rf ../../../alias/stable -# rm -rf ../../../alias/unstable -# rm -rf ../../../v0.8.1 -# rm -rf ../../../v0.9.1 -#} -# -#mkdir ../../../v0.8.1 -#mkdir ../../../v0.9.1 -# -#EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)" -#STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")" -# -#EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)" -#UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")" -# -#[ "_$STABLE_VERSION" != "_$UNSTABLE_VERSION" ] \ -# || die "stable and unstable versions are the same!" -# -#nvm alias stable "$EXPECTED_UNSTABLE" -#nvm alias unstable "$EXPECTED_STABLE" -# -#NVM_ALIAS_OUTPUT=$(nvm alias) -# -#echo "$NVM_ALIAS_OUTPUT" | \grep -e "^stable -> $EXPECTED_UNSTABLE (-> $UNSTABLE_VERSION)$" \ -# || die "nvm alias did not contain the overridden 'stable' alias" -# -#echo "$NVM_ALIAS_OUTPUT" | \grep -e "^unstable -> $EXPECTED_STABLE (-> $STABLE_VERSION)$" \ -# || die "nvm alias did not contain the overridden 'unstable' alias" -# -#cleanup -# + mkdir v0.8.1 + mkdir v0.9.1 + + stable="$(nvm_print_implicit_alias local stable)" + unstable="$(nvm_print_implicit_alias local unstable)" + + assert_unequal $stable $unstable "stable and unstable versions are the same!" + + run nvm alias stable $unstable + run nvm alias unstable $stable + + run nvm alias + + assert_line 0 "stable -> 0.9 (-> v0.9.1)" "nvm alias did not contain the overridden 'stable' alias" + assert_line 21 "unstable -> 0.8 (-> v0.8.1)" "nvm alias did not contain the overridden 'unstable' alias" } @test './Aliases/Running "nvm alias" should list all aliases.' { -##!/bin/sh -# -#. ../../../nvm.sh -# -#die () { echo $@ ; exit 1; } -# -#NVM_ALIAS_OUTPUT=$(nvm alias) -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-1 -> 0.0.1 (-> v0.0.1)$' \ -# || die "did not find test-stable-1 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-2 -> 0.0.2 (-> v0.0.2)$' \ -# || die "did not find test-stable-2 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-3 -> 0.0.3 (-> v0.0.3)$' \ -# || die "did not find test-stable-3 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-4 -> 0.0.4 (-> v0.0.4)$' \ -# || die "did not find test-stable-4 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-5 -> 0.0.5 (-> v0.0.5)$' \ -# || die "did not find test-stable-5 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-6 -> 0.0.6 (-> v0.0.6)$' \ -# || die "did not find test-stable-6 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-7 -> 0.0.7 (-> v0.0.7)$' \ -# || die "did not find test-stable-7 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-8 -> 0.0.8 (-> v0.0.8)$' \ -# || die "did not find test-stable-8 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-9 -> 0.0.9 (-> v0.0.9)$' \ -# || die "did not find test-stable-9 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-10 -> 0.0.10 (-> v0.0.10)$' \ -# || die "did not find test-stable-10 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-1 -> 0.1.1 (-> v0.1.1)$' \ -# || die "did not find test-unstable-1 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-2 -> 0.1.2 (-> v0.1.2)$' \ -# || die "did not find test-unstable-2 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-3 -> 0.1.3 (-> v0.1.3)$' \ -# || die "did not find test-unstable-3 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-4 -> 0.1.4 (-> v0.1.4)$' \ -# || die "did not find test-unstable-4 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-5 -> 0.1.5 (-> v0.1.5)$' \ -# || die "did not find test-unstable-5 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-6 -> 0.1.6 (-> v0.1.6)$' \ -# || die "did not find test-unstable-6 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-7 -> 0.1.7 (-> v0.1.7)$' \ -# || die "did not find test-unstable-7 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-8 -> 0.1.8 (-> v0.1.8)$' \ -# || die "did not find test-unstable-8 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-9 -> 0.1.9 (-> v0.1.9)$' \ -# || die "did not find test-unstable-9 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-10 -> 0.1.10 (-> v0.1.10)$' \ -# || die "did not find test-unstable-10 alias" -# + run nvm alias + + assert_line 0 'test-stable-1 -> 0.0.1 (-> v0.0.1)' "did not find test-stable-1 alias" + assert_line 1 'test-stable-10 -> 0.0.10 (-> v0.0.10)' "did not find test-stable-10 alias" + assert_line 2 'test-stable-2 -> 0.0.2 (-> v0.0.2)' "did not find test-stable-2 alias" + assert_line 3 'test-stable-3 -> 0.0.3 (-> v0.0.3)' "did not find test-stable-3 alias" + assert_line 4 'test-stable-4 -> 0.0.4 (-> v0.0.4)' "did not find test-stable-4 alias" + assert_line 5 'test-stable-5 -> 0.0.5 (-> v0.0.5)' "did not find test-stable-5 alias" + assert_line 6 'test-stable-6 -> 0.0.6 (-> v0.0.6)' "did not find test-stable-6 alias" + assert_line 7 'test-stable-7 -> 0.0.7 (-> v0.0.7)' "did not find test-stable-7 alias" + assert_line 8 'test-stable-8 -> 0.0.8 (-> v0.0.8)' "did not find test-stable-8 alias" + assert_line 9 'test-stable-9 -> 0.0.9 (-> v0.0.9)' "did not find test-stable-9 alias" + assert_line 10 'test-unstable-1 -> 0.1.1 (-> v0.1.1)' "did not find test-unstable-1 alias" + assert_line 11 'test-unstable-10 -> 0.1.10 (-> v0.1.10)' "did not find test-unstable-10 alias" + assert_line 12 'test-unstable-2 -> 0.1.2 (-> v0.1.2)' "did not find test-unstable-2 alias" + assert_line 13 'test-unstable-3 -> 0.1.3 (-> v0.1.3)' "did not find test-unstable-3 alias" + assert_line 14 'test-unstable-4 -> 0.1.4 (-> v0.1.4)' "did not find test-unstable-4 alias" + assert_line 15 'test-unstable-5 -> 0.1.5 (-> v0.1.5)' "did not find test-unstable-5 alias" + assert_line 16 'test-unstable-6 -> 0.1.6 (-> v0.1.6)' "did not find test-unstable-6 alias" + assert_line 17 'test-unstable-7 -> 0.1.7 (-> v0.1.7)' "did not find test-unstable-7 alias" + assert_line 18 'test-unstable-8 -> 0.1.8 (-> v0.1.8)' "did not find test-unstable-8 alias" + assert_line 19 'test-unstable-9 -> 0.1.9 (-> v0.1.9)' "did not find test-unstable-9 alias" + } diff --git a/test/bats/fast-raw.bats b/test/bats/fast-raw.bats index 54f7295..00a5593 100644 --- a/test/bats/fast-raw.bats +++ b/test/bats/fast-raw.bats @@ -68,12 +68,12 @@ teardown() { #EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)" #STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")" #echo "$NVM_ALIAS_OUTPUT" | \grep -e "^stable -> $EXPECTED_STABLE (-> $STABLE_VERSION) (default)$" \ -# || die "nvm alias did not contain the default local stable node version" +# || die # #EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)" #UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")" #echo "$NVM_ALIAS_OUTPUT" | \grep -e "^unstable -> $EXPECTED_UNSTABLE (-> $UNSTABLE_VERSION) (default)$" \ -# || die "nvm alias did not contain the default local unstable node version" +# || die # } diff --git a/test/bats/fast2.bats b/test/bats/fast2.bats new file mode 100644 index 0000000..c2e9757 --- /dev/null +++ b/test/bats/fast2.bats @@ -0,0 +1,1589 @@ +#!/usr/bin/env bats + +NVM_SRC_DIR="${BATS_TEST_DIRNAME}/../.." + +setup() { + echo 'setup' >&2 + NVM_DIR="${BATS_TMPDIR}" + cd "${NVM_DIR}" + rm -Rf src alias v* + mkdir src alias + load "${NVM_SRC_DIR}/nvm.sh" +} + +teardown() { + echo 'teardown' >&2 + NVM_DIR="${BATS_TMPDIR}" + cd "${NVM_DIR}" + rm -Rf src alias v* +} + +@test './Listing versions/Running "nvm ls 0.0.2" should display only version 0.0.2.' { +##!/bin/sh +# +#mkdir ../../../v0.0.2 +#mkdir ../../../v0.0.20 +# +#. ../../../nvm.sh +# +#die () { echo $@ ; exit 1; } +# +## The result should contain only the appropriate version numbers. +# +#nvm ls 0.0.2 | grep 'v0.0.2' > /dev/null +#if [ $? -eq 0 ]; then +# echo '"nvm ls 0.0.2" contained v0.0.2' +#fi +# +#nvm ls 0.0.2 | grep 'v0.0.20' > /dev/null +#if [ $? -eq 0 ]; then +# die '"nvm ls 0.0.2" contained v0.0.20' +#fi +# +} + +@test './Listing versions/Running "nvm ls 0.2" should display only 0.2.x versions.' { +##!/bin/sh +# +#mkdir ../../../v0.1.3 +#mkdir ../../../v0.2.3 +#mkdir ../../../v0.20.3 +# +#. ../../../nvm.sh +# +#die () { echo $@ ; exit 1; } +# +## The result should contain only the appropriate version numbers. +# +#nvm ls 0.1 | grep 'v0.2.3' > /dev/null +#if [ $? -eq 0 ]; then +# echo '"nvm ls 0.1" contained v0.2.3' +#fi +# +#nvm ls 0.1 | grep 'v0.20.3' > /dev/null +#if [ $? -eq 0 ]; then +# die '"nvm ls 0.1" contained v0.20.3' +#fi +# +#nvm ls 0.1 | grep 'v0.1.3' > /dev/null +#if [ $? -ne 0 ]; then +# die '"nvm ls 0.1" did not contain v0.1.3' +#fi +# +#nvm ls 0.2 | grep 'v0.2.3' > /dev/null +#if [ $? -ne 0 ]; then +# die '"nvm ls 0.2" did not contain v0.2.3' +#fi +# +#nvm ls 0.2 | grep 'v0.20.3' > /dev/null +#if [ $? -eq 0 ]; then +# die '"nvm ls 0.2" contained v0.20.3' +#fi +# +#nvm ls 0.2 | grep 'v0.2.3' > /dev/null +#if [ $? -ne 0 ]; then +# die '"nvm ls 0.2" did not contain v0.2.3' +#fi +} + +@test './Listing versions/Running "nvm ls foo" should return a nonzero exit code when not found' { +# #!/bin/sh +# +#. ../../../nvm.sh +# +#nvm ls nonexistent_version +#[ "$?" = "3" ] +# +} + +@test './Listing versions/Running "nvm ls node" should return a nonzero exit code when not found' { +# #!/bin/sh +# +#. ../../../nvm.sh +# +#nvm ls node +#[ "$?" = "3" ] +# +} + +@test './Listing versions/Running "nvm ls stable" and "nvm ls unstable" should return the appropriate implicit alias' { +# #!/bin/sh +# +#. ../../../nvm.sh +# +#die () { echo $@ ; exit 1; } +# +#mkdir ../../../v0.2.3 +#mkdir ../../../v0.3.3 +# +#EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)" +#STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")" +# +#EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)" +#UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")" +# +#nvm ls stable | \grep "$STABLE_VERSION" >/dev/null \ +# || die "expected 'nvm ls stable' to give $STABLE_VERSION, got $(nvm ls stable)" +# +#nvm ls unstable | \grep "$UNSTABLE_VERSION" >/dev/null \ +# || die "expected 'nvm ls unstable' to give $UNSTABLE_VERSION, got $(nvm ls unstable)" +# +#mkdir ../../../v0.1.2 +#nvm alias stable 0.1 +# +#nvm ls stable | \grep -v "$STABLE_VERSION" >/dev/null \ +# || die "'nvm ls stable' contained $STABLE_VERSION instead of v0.1.2" +#nvm ls stable | \grep v0.1.2 >/dev/null \ +# || die "'nvm ls stable' did not contain v0.1.2" +# +} + +@test './Listing versions/Running "nvm ls system" should include "system" when appropriate' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#mkdir -p ../../../v0.0.1 +#mkdir -p ../../../v0.0.3 +#mkdir -p ../../../v0.0.9 +#mkdir -p ../../../v0.3.1 +#mkdir -p ../../../v0.3.3 +#mkdir -p ../../../v0.3.9 +# +#nvm_has_system_node() { return 0; } +#nvm ls system | grep system 2>&1 > /dev/null +#[ $? -eq 0 ] || die '"nvm ls system" did not contain "system" when system node is present' +# +#nvm_has_system_node() { return 1; } +#nvm ls system | grep system 2>&1 > /dev/null +#[ $? -ne 0 ] || die '"nvm ls system" contained "system" when system node is not present' +# +} + +@test './Listing versions/Running "nvm ls" should display all installed versions.' { +##!/bin/sh +# +#. ../../../nvm.sh +# +#mkdir ../../../v0.0.1 +#mkdir ../../../v0.0.3 +#mkdir ../../../v0.0.9 +#mkdir ../../../v0.3.1 +#mkdir ../../../v0.3.3 +#mkdir ../../../v0.3.9 +# +## The result should contain the version numbers. +#nvm ls | grep v0.0.1 && +#nvm ls | grep v0.0.3 && +#nvm ls | grep v0.0.9 && +#nvm ls | grep v0.3.1 && +#nvm ls | grep v0.3.3 && +#nvm ls | grep v0.3.9 +} + +@test './Listing versions/Running "nvm ls" should filter out ".nvm"' { +##!/bin/sh +# +#mkdir ../../../v0.1.3 +#mkdir ../../../v0.2.3 +# +#. ../../../nvm.sh +# +#[ -z `nvm ls | grep '^ *\.'` ] +## The result should contain only the appropriate version numbers. +} + +@test './Listing versions/Running "nvm ls" should filter out "versions"' { +##!/bin/sh +# +#mkdir ../../../v0.1.3 +#mkdir ../../../v0.2.3 +#mkdir ../../../versions +# +#. ../../../nvm.sh +# +#[ -z "$(nvm ls | \grep 'versions')" ] +## The result should contain only the appropriate version numbers. +# +} + +@test './Listing versions/Running "nvm ls" should include "system" when appropriate' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#mkdir -p ../../../v0.0.1 +#mkdir -p ../../../v0.0.3 +#mkdir -p ../../../v0.0.9 +#mkdir -p ../../../v0.3.1 +#mkdir -p ../../../v0.3.3 +#mkdir -p ../../../v0.3.9 +# +#nvm_has_system_node() { return 0; } +#nvm ls | grep system 2>&1 > /dev/null +#[ $? -eq 0 ] || die '"nvm ls" did not contain "system" when system node is present' +# +#nvm_has_system_node() { return 1; } +#nvm ls | grep system 2>&1 > /dev/null +#[ $? -ne 0 ] || die '"nvm ls" contained "system" when system node is not present' +# +} + +@test './Listing versions/Running "nvm ls" should list versions in the "versions" directory' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#mkdir -p ../../../versions/v0.12.1 +#mkdir ../../../v0.1.3 +# +#. ../../../nvm.sh +# +#nvm ls 0.12 | grep v0.12.1 || die '"nvm ls" did not list a version in the versions/ directory' +#nvm ls 0.1 | grep v0.1.3 || die '"nvm ls" did not list a version not in the versions/ directory' +# +} + +@test './Listing versions/Running "nvm ls" with node-like versioning vx.x.x should only list a matched version' { +##!/bin/sh +# +#mkdir ../../../v0.1.2 +# +#. ../../../nvm.sh +# +#nvm ls v0.1 | grep v0.1.2 && +#nvm ls v0.1.2 | grep v0.1.2 && +#nvm ls v0.1. | grep v0.1.2 && +#nvm ls v0.1.1 | grep N/A +# +} + +@test './Listing versions/teardown' { +#rmdir ../../../v0.0.1 >/dev/null 2>&1 +#rmdir ../../../v0.0.2 >/dev/null 2>&1 +#rmdir ../../../v0.0.3 >/dev/null 2>&1 +#rmdir ../../../v0.0.9 >/dev/null 2>&1 +#rmdir ../../../v0.0.20 >/dev/null 2>&1 +#rmdir ../../../v0.1.2 >/dev/null 2>&1 +#rmdir ../../../v0.1.3 >/dev/null 2>&1 +#rmdir ../../../v0.2.3 >/dev/null 2>&1 +#rmdir ../../../v0.3.1 >/dev/null 2>&1 +#rmdir ../../../v0.3.3 >/dev/null 2>&1 +#rmdir ../../../v0.3.9 >/dev/null 2>&1 +#rmdir ../../../v0.20.3 >/dev/null 2>&1 +#rmdir ../../../versions >/dev/null 2>&1 +#unalias nvm_has_system_node >/dev/null 2>&1 +#rm -f ../../../alias/stable >/dev/null 2>&1 +#rm -f ../../../alias/unstable >/dev/null 2>&1 +# +} + +@test './Running "nvm alias" should create a file in the alias directory.' { +##!/bin/sh +# +#. ../../nvm.sh +#nvm alias test v0.1.2 +#[ "$(cat ../../alias/test)" = "v0.1.2" ] +} + +@test './Running "nvm current" should display current nvm environment.' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../nvm.sh +# +#nvm deactivate 2>&1 +# +#[ "$(nvm current)" = "system" ] || [ "$(nvm current)" = "none" ] || die '"nvm current" did not report "system" or "none" when deactivated' +# +} + +@test './Running "nvm deactivate" should unset the nvm environment variables.' { +##!/bin/sh +# +#mkdir -p ../../v0.2.3 +# +#die () { echo $@ ; exit 1; } +# +#[ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&2 +# +#. ../../nvm.sh +#nvm use v0.2.3 || die "Failed to activate v0.2.3" +#[ `expr "$PATH" : ".*v0.2.3/.*/bin"` != 0 ] || die "PATH not set up properly" +#[ `expr "$NODE_PATH" : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "NODE_PATH should not contain (npm root -g)" +## ^ note: NODE_PATH should not contain `npm root -g` since globals should not be requireable +# +#nvm deactivate || die "Failed to deactivate v0.2.3" +#[ `expr "$PATH" : ".*v0.2.3/.*/bin"` = 0 ] || die "PATH not cleaned properly" +#[ `expr "$NODE_PATH" : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "NODE_PATH not cleaned properly" +} + +@test './Running "nvm install" with "--reinstall-packages-from" requires a valid version' { +##!/bin/sh +# +#die () { echo $@ ; cleanup ; exit 1; } +#cleanup () { +# rm -rf ../../v0.10.4 +#} +# +#mkdir ../../v0.10.4 +# +#. ../../nvm.sh +# +#nvm deactivate >/dev/null 2>&1 +# +#INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from=0.11 2>&1)" +#EXPECTED_ERROR_MSG="If --reinstall-packages-from is provided, it must point to an installed version of node." +#[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \ +# || die ""nvm install --reinstall-packages-from" should fail when given an uninstalled version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'" +# +#INSTALL_EXIT_CODE="$(nvm install v0.10.5 --reinstall-packages-from=0.11 >/dev/null 2>&1; echo $?)" +#[ "~$INSTALL_EXIT_CODE" = "~5" ] \ +# || die ""nvm install --reinstall-packages-from" should exit with code 5 when given an uninstalled version, got $INSTALL_EXIT_CODE" +# +#INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from=0.10.5 2>&1)" +#EXPECTED_ERROR_MSG="You can't reinstall global packages from the same version of node you're installing." +#[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \ +# || die ""nvm install --reinstall-packages-from" should fail when given the same version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'" +# +#INSTALL_EXIT_CODE="$(nvm install v0.10.5 --reinstall-packages-from=0.10.5 >/dev/null 2>&1; echo $?)" +#[ "~$INSTALL_EXIT_CODE" = "~4" ] \ +# || die ""nvm install --reinstall-packages-from" should exit with code 4 when given the same version, got $INSTALL_EXIT_CODE" +# +} + +@test './Running "nvm install" with an invalid version fails nicely' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../nvm.sh +#[ "$(nvm install invalid.invalid 2>&1)" = "Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions." ] || die "nvm installing an invalid version did not print a nice error message" +# +} + +@test './Running "nvm unalias" should remove the alias file.' { +##!/bin/sh +# +#echo v0.1.2 > ../../alias/test +#. ../../nvm.sh +#nvm unalias test +#! [ -e ../../alias/test ] +} + +@test './Running "nvm uninstall" should remove the appropriate directory.' { +##!/bin/sh +# +#cd ../.. +#mkdir v0.0.1 +#mkdir src/node-v0.0.1 +# +#. ./nvm.sh +#nvm uninstall v0.0.1 +# +#[ ! -d 'v0.0.1' ] && [ ! -d 'src/node-v0.0.1' ] +} + +@test './Running "nvm unload" should unset all function and variables.' { +##!/bin/sh +# +#fail () { echo $@ ; exit 1; } +# +#. ../../nvm.sh +# +#type nvm > /dev/null 2>&1 || fail "NVM not loaded" +# +#nvm unload +# +#type nvm > /dev/null 2>&1 && fail "NVM not unloaded" || exit 0 +# +} + +@test './Running "nvm use foo" where "foo" is circular aborts' { +##!/bin/sh +# +#die () { echo $@ ; cleanup ; exit 1; } +# +#cleanup() { +# rm -rf ../../alias/foo +#} +# +#. ../../nvm.sh +# +#echo 'foo' > ../../alias/foo +# +#OUTPUT="$(nvm use foo 2>&1)" +#EXPECTED_OUTPUT='The alias "foo" leads to an infinite loop. Aborting.' +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \ +# || die "'nvm use foo' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'" +# +#EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)" +#[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got $EXIT_CODE" +# +#cleanup; +# +} + +@test './Running "nvm use system" should work as expected' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../nvm.sh +# +#nvm_has_system_node() { return 0; } +#[ "$(nvm use system 2>&1 | tail -n1)" = "Now using system version of node: $(node -v)." ] || die "Could not use system version of node" +# +#nvm_has_system_node() { return 1; } +#[ "$(nvm use system 2>&1 | tail -n1)" = "System version of node not found." ] || die "Did not report error, system node not found" +#nvm use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found" +# +} + +@test './Running "nvm use x" should create and change the "current" symlink' { +##!/bin/bash +# +#export NVM_SYMLINK_CURRENT=true +#. ../../nvm.sh +# +#rm -rf ../../v0.10.29 +#mkdir ../../v0.10.29 +#nvm use 0.10.29 +#rmdir ../../v0.10.29 +# +#if [ ! -L ../../current ];then +# echo "Expected 'current' symlink to be created!" +# exit 1 +#fi +# +#oldLink="$(readlink ../../current)" +# +#if [ "$(basename $oldLink)" != 'v0.10.29' ];then +# echo "Expected 'current' to point to v0.10.29 but was $oldLink" +# exit 1 +#fi +# +#rm -rf ../../v0.11.13 +#mkdir ../../v0.11.13 +#nvm use 0.11.13 +#rmdir ../../v0.11.13 +# +#newLink="$(readlink ../../current)" +# +#if [ "$(basename $newLink)" != 'v0.11.13' ];then +# echo "Expected 'current' to point to v0.11.13 but was $newLink" +# exit 1 +#fi +} + +@test './Running "nvm use x" should not create the "current" symlink if $NVM_SYMLINK_CURRENT is false' { +##!/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 2>&1 +# rmdir ../../${TEST_NODE_VERSION} +#} +# +#function isCurrentSymlinkPresent() { +# [ -L ../../current ] +#} +# +#NVM_SYMLINK_CURRENT=false +#cleanup +#runNvmUse +#isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=false!" +#registerExpectedNoSymlink $? +# +#NVM_SYMLINK_CURRENT=true +#cleanup +#runNvmUse +#isCurrentSymlinkPresent || echo >&2 "Expected 'current' symlink to be created when NVM_SYMLINK_CURRENT=true!" +#registerExpectedSymlink $? +# +#NVM_SYMLINK_CURRENT=garbagevalue +#cleanup +#runNvmUse +#isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT contains a string!" +#registerExpectedNoSymlink $? +# +#NVM_SYMLINK_CURRENT=0 +#cleanup +#runNvmUse +#isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=0!" +#registerExpectedNoSymlink $? +# +#NVM_SYMLINK_CURRENT=1 +#cleanup +#runNvmUse +#isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=1!" +#registerExpectedNoSymlink $? +# +#unset NVM_SYMLINK_CURRENT +#cleanup +#runNvmUse +#isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT has been unset (default behaviour)!" +#registerExpectedNoSymlink $? +# +#cleanup +# +#[ ${TEST_FAILED} -ne 0 ] && echo "${TEST_COUNT} tested, ${TEST_PASSED} passed, ${TEST_FAILED} failed" && exit 1 || true +# +} + +@test './setup' { +##!/bin/sh +# +#( +# cd ../.. +# +# # Back up +# +# type setopt >/dev/null 2>&1 && setopt NULL_GLOB +# type shopt >/dev/null 2>&1 && shopt -s nullglob +# rm -Rf v* src alias +# mkdir src alias +#) +} + +@test './setup_dir' { +##!/bin/sh +# +#( +# cd ../.. +# +# # Back up +# +# mkdir -p bak +# for SRC in v* src alias; do +# [ -e "$SRC" ] && mv "$SRC" bak +# done +# if [ -d versions ]; then +# mv versions bak +# fi +# true +#) +} + +@test './Sourcing nvm.sh should make the nvm command available.' { +##!/bin/sh +# +#. ../../nvm.sh +#nvm +} + +@test './teardown' { +##!/bin/sh +# +## Remove temporary files +#( +# cd ../.. +# +# type setopt >/dev/null 2>&1 && setopt NULL_GLOB +# type shopt >/dev/null 2>&1 && shopt -s nullglob +# rm -fR v* src alias +#) +} + +@test './teardown_dir' { +##!/bin/sh +# +#( +# cd ../.. +# +# # Restore +# if [ -d bak ] +# then +# mv bak/* . > /dev/null 2>&1 || sleep 0s +# rmdir bak +# fi +# mkdir -p src alias +#) +} + +@test './Unit tests/nvm_alias' { +##!/bin/sh +# +#die () { echo $@ ; cleanup ; exit 1; } +# +#cleanup () { +# rm -rf ../../../alias/test +#} +# +#. ../../../nvm.sh +# +#OUTPUT="$(nvm_alias 2>&1)" +#EXPECTED_OUTPUT='An alias is required.' +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_alias' produced wrong output; got $OUTPUT" +# +#EXIT_CODE="$(nvm_alias >/dev/null 2>&1 ; echo $?)" +#[ "_$EXIT_CODE" = "_1" ] || die "'nvm_alias' exited with $EXIT_CODE, expected 1" +# +#rm -rf ../../../alias/nonexistent +# +#OUTPUT="$(nvm_alias nonexistent 2>&1)" +#EXPECTED_OUTPUT='Alias does not exist.' +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_alias nonexistent' produced wrong output; got $OUTPUT" +# +#EXIT_CODE="$(nvm_alias nonexistent >/dev/null 2>&1 ; echo $?)" +#[ "_$EXIT_CODE" = "_2" ] || die "'nvm_alias nonexistent' exited with $EXIT_CODE, expected 2" +# +#EXPECTED_OUTPUT="0.10" +#nvm alias test "$EXPECTED_OUTPUT" || die "'nvm alias test $EXPECTED_OUTPUT' failed" +#OUTPUT="$(nvm_alias test)" +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_alias test' produced wrong output; got $OUTPUT" +# +#cleanup +# +} + +@test './Unit tests/nvm_checksum' { +##!/bin/sh +# +#cleanup () { +# rm tmp/emptyfile tmp/testfile +# rmdir tmp +#} +#die () { echo $@ ; cleanup; exit 1; } +# +#. ../../../nvm.sh +# +#mkdir -p tmp +#touch tmp/emptyfile +#echo -n "test" > tmp/testfile +# +#nvm_checksum tmp/emptyfile "da39a3ee5e6b4b0d3255bfef95601890afd80709" || die "nvm_checksum on an empty file did not match the SHA1 digest of the empty string" +#nvm_checksum tmp/testfile "da39a3ee5e6b4b0d3255bfef95601890afd80709" && die "nvm_checksum allowed a bad checksum" +# +#cleanup +} + +@test './Unit tests/nvm_find_up' { +##!/bin/sh +# +#die () { echo $@ ; cleanup ; exit 1; } +#setup() { +# cleanup +# mkdir -p tmp_nvm_find_up/a/b/c/d +# touch tmp_nvm_find_up/test +# touch tmp_nvm_find_up/a/b/c/test +#} +#cleanup () { +# rm -rf tmp_nvm_find_up +#} +# +#. ../../../nvm.sh +# +#setup +# +#TEST_DIR="$PWD" +# +#[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up" ] || die "failed to find 1 dir up" +#[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up" ] || die "failed to find 2 dirs up" +#[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b/c nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up/a/b/c" ] || die "failed to find in current dir" +#[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b/c/d nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up/a/b/c" ] || die "failed to find 1 level up from current dir" +# +#cleanup +# +} + +@test './Unit tests/nvm_format_version' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#OUTPUT="$(nvm_format_version 0.1.2)" +#EXPECTED_OUTPUT="v0.1.2" +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_format_version 0.1.2 did not return $EXPECTED_OUTPUT; got $OUTPUT" +# +#OUTPUT="$(nvm_format_version 0.1)" +#EXPECTED_OUTPUT="v0.1.0" +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_format_version 0.1.0 did not return $EXPECTED_OUTPUT; got $OUTPUT" +# +} + +@test './Unit tests/nvm_has' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#nvm_has cat && type cat > /dev/null || die 'nvm_has locates "cat" properly' +# +#[ "~$(nvm_has foobarbaz 2>&1)" = "~" ] || die "nvm_has does not suppress error output" +# +#! nvm_has foobarbaz && ! type foobarbaz >/dev/null 2>&1 || die "nvm_has does not return a nonzero exit code when not found" +# +} + +@test './Unit tests/nvm_has_system_node' { +##!/bin/sh +# +#cleanup () { +# rm ../../../v0.1.2/node +# rmdir ../../../v0.1.2 +#} +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#mkdir ../../../v0.1.2 +#touch ../../../v0.1.2/node +# +#nvm use 0.1.2 +# +#if command -v node; then +# nvm_has_system_node +#else +# ! nvm_has_system_node +#fi +# +#nvm deactivate /dev/null 2>&1 +# +#if command -v node; then +# nvm_has_system_node +#else +# ! nvm_has_system_node +#fi +# +} + +@test './Unit tests/nvm_ls_current' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#return_zero () { return 0; } +# +#[ "$(nvm deactivate > /dev/null 2>&1 ; nvm_ls_current)" = "system" ] || die 'when deactivated, did not return "system"' +# +#TEST_PWD=$(pwd) +#TEST_DIR="$TEST_PWD/nvm_ls_current_tmp" +#rm -rf "$TEST_DIR" +#mkdir "$TEST_DIR" +#ln -s "$(which which)" "$TEST_DIR/which" +#ln -s "$(which dirname)" "$TEST_DIR/dirname" +# +#[ "$(PATH="$TEST_DIR" nvm_ls_current)" = "none" ] || die 'when node not installed, nvm_ls_current did not return "none"' +#[ "@$(PATH="$TEST_DIR" nvm_ls_current 2> /dev/stdout 1> /dev/null)@" = "@@" ] || die 'when node not installed, nvm_ls_current returned error output' +# +#echo "#!/bin/bash" > "$TEST_DIR/node" +#echo "echo 'VERSION FOO!'" > "$TEST_DIR/node" +#chmod a+x "$TEST_DIR/node" +# +#[ "$(alias nvm_tree_contains_path='return_zero' && PATH="$TEST_DIR" nvm_ls_current)" = "VERSION FOO!" ] || die 'when activated, did not return nvm node version' +# +#rm -rf "$TEST_DIR" +# +} + +@test './Unit tests/nvm_ls_remote' { +##!/bin/sh +# +#die () { echo $@ ; cleanup ; exit 1; } +# +#cleanup() { +# unset -f nvm_download +#} +# +#. ../../../nvm.sh +# +## sample output at the time the test was written +#nvm_download() { +# echo 'foo "v0.10.0' +# echo 'foo "v0.10.0' +# echo 'foo "v0.10.1' +# echo 'foo "v0.10.1' +# echo 'foo "v0.10.10' +# echo 'foo "v0.10.10' +# echo 'foo "v0.10.11' +# echo 'foo "v0.10.11' +# echo 'foo "v0.10.12' +# echo 'foo "v0.10.12' +# echo 'foo "v0.10.13' +# echo 'foo "v0.10.13' +# echo 'foo "v0.10.14' +# echo 'foo "v0.10.14' +# echo 'foo "v0.10.15' +# echo 'foo "v0.10.15' +# echo 'foo "v0.10.16' +# echo 'foo "v0.10.16' +# echo 'foo "v0.10.16' +# echo 'foo "v0.10.16' +# echo 'foo "v0.10.17' +# echo 'foo "v0.10.17' +# echo 'foo "v0.10.18' +# echo 'foo "v0.10.18' +# echo 'foo "v0.10.19' +# echo 'foo "v0.10.19' +# echo 'foo "v0.10.2' +# echo 'foo "v0.10.2' +# echo 'foo "v0.10.20' +# echo 'foo "v0.10.20' +# echo 'foo "v0.10.21' +# echo 'foo "v0.10.21' +# echo 'foo "v0.10.22' +# echo 'foo "v0.10.22' +# echo 'foo "v0.10.23' +# echo 'foo "v0.10.23' +# echo 'foo "v0.10.24' +# echo 'foo "v0.10.24' +# echo 'foo "v0.10.25' +# echo 'foo "v0.10.25' +# echo 'foo "v0.10.26' +# echo 'foo "v0.10.26' +# echo 'foo "v0.10.27' +# echo 'foo "v0.10.27' +# echo 'foo "v0.10.28' +# echo 'foo "v0.10.28' +# echo 'foo "v0.10.29' +# echo 'foo "v0.10.29' +# echo 'foo "v0.10.3' +# echo 'foo "v0.10.3' +# echo 'foo "v0.10.30' +# echo 'foo "v0.10.30' +# echo 'foo "v0.10.31' +# echo 'foo "v0.10.31' +# echo 'foo "v0.10.32' +# echo 'foo "v0.10.32' +# echo 'foo "v0.10.4' +# echo 'foo "v0.10.4' +# echo 'foo "v0.10.5' +# echo 'foo "v0.10.5' +# echo 'foo "v0.10.6' +# echo 'foo "v0.10.6' +# echo 'foo "v0.10.7' +# echo 'foo "v0.10.7' +# echo 'foo "v0.10.8' +# echo 'foo "v0.10.8' +# echo 'foo "v0.10.9' +# echo 'foo "v0.10.9' +# echo 'foo "v0.11.0' +# echo 'foo "v0.11.0' +# echo 'foo "v0.11.1' +# echo 'foo "v0.11.1' +# echo 'foo "v0.11.10' +# echo 'foo "v0.11.10' +# echo 'foo "v0.11.11' +# echo 'foo "v0.11.11' +# echo 'foo "v0.11.12' +# echo 'foo "v0.11.12' +# echo 'foo "v0.11.13' +# echo 'foo "v0.11.13' +# echo 'foo "v0.11.14' +# echo 'foo "v0.11.14' +# echo 'foo "v0.11.2' +# echo 'foo "v0.11.2' +# echo 'foo "v0.11.3' +# echo 'foo "v0.11.3' +# echo 'foo "v0.11.4' +# echo 'foo "v0.11.4' +# echo 'foo "v0.11.5' +# echo 'foo "v0.11.5' +# echo 'foo "v0.11.6' +# echo 'foo "v0.11.6' +# echo 'foo "v0.11.7' +# echo 'foo "v0.11.7' +# echo 'foo "v0.11.8' +# echo 'foo "v0.11.8' +# echo 'foo "v0.11.9' +# echo 'foo "v0.11.9' +# echo 'foo "v0.5.1' +# echo 'foo "v0.5.1' +# echo 'foo "v0.5.10' +# echo 'foo "v0.5.10' +# echo 'foo "v0.5.2' +# echo 'foo "v0.5.2' +# echo 'foo "v0.5.3' +# echo 'foo "v0.5.3' +# echo 'foo "v0.5.4' +# echo 'foo "v0.5.4' +# echo 'foo "v0.5.5' +# echo 'foo "v0.5.5' +# echo 'foo "v0.5.6' +# echo 'foo "v0.5.6' +# echo 'foo "v0.5.7' +# echo 'foo "v0.5.7' +# echo 'foo "v0.5.8' +# echo 'foo "v0.5.8' +# echo 'foo "v0.5.9' +# echo 'foo "v0.5.9' +# echo 'foo "v0.6.0' +# echo 'foo "v0.6.0' +# echo 'foo "v0.6.1' +# echo 'foo "v0.6.1' +# echo 'foo "v0.6.10' +# echo 'foo "v0.6.10' +# echo 'foo "v0.6.11' +# echo 'foo "v0.6.11' +# echo 'foo "v0.6.12' +# echo 'foo "v0.6.12' +# echo 'foo "v0.6.13' +# echo 'foo "v0.6.13' +# echo 'foo "v0.6.14' +# echo 'foo "v0.6.14' +# echo 'foo "v0.6.15' +# echo 'foo "v0.6.15' +# echo 'foo "v0.6.16' +# echo 'foo "v0.6.16' +# echo 'foo "v0.6.17' +# echo 'foo "v0.6.17' +# echo 'foo "v0.6.18' +# echo 'foo "v0.6.18' +# echo 'foo "v0.6.19' +# echo 'foo "v0.6.19' +# echo 'foo "v0.6.2' +# echo 'foo "v0.6.2' +# echo 'foo "v0.6.20' +# echo 'foo "v0.6.20' +# echo 'foo "v0.6.21' +# echo 'foo "v0.6.21' +# echo 'foo "v0.6.3' +# echo 'foo "v0.6.3' +# echo 'foo "v0.6.4' +# echo 'foo "v0.6.4' +# echo 'foo "v0.6.5' +# echo 'foo "v0.6.5' +# echo 'foo "v0.6.6' +# echo 'foo "v0.6.6' +# echo 'foo "v0.6.7' +# echo 'foo "v0.6.7' +# echo 'foo "v0.6.8' +# echo 'foo "v0.6.8' +# echo 'foo "v0.6.9' +# echo 'foo "v0.6.9' +# echo 'foo "v0.7.0' +# echo 'foo "v0.7.0' +# echo 'foo "v0.7.1' +# echo 'foo "v0.7.1' +# echo 'foo "v0.7.10' +# echo 'foo "v0.7.10' +# echo 'foo "v0.7.11' +# echo 'foo "v0.7.11' +# echo 'foo "v0.7.12' +# echo 'foo "v0.7.12' +# echo 'foo "v0.7.2' +# echo 'foo "v0.7.2' +# echo 'foo "v0.7.3' +# echo 'foo "v0.7.3' +# echo 'foo "v0.7.4' +# echo 'foo "v0.7.4' +# echo 'foo "v0.7.5' +# echo 'foo "v0.7.5' +# echo 'foo "v0.7.6' +# echo 'foo "v0.7.6' +# echo 'foo "v0.7.7' +# echo 'foo "v0.7.7' +# echo 'foo "v0.7.8' +# echo 'foo "v0.7.8' +# echo 'foo "v0.7.9' +# echo 'foo "v0.7.9' +# echo 'foo "v0.8.0' +# echo 'foo "v0.8.0' +# echo 'foo "v0.8.1' +# echo 'foo "v0.8.1' +# echo 'foo "v0.8.10' +# echo 'foo "v0.8.10' +# echo 'foo "v0.8.11' +# echo 'foo "v0.8.11' +# echo 'foo "v0.8.12' +# echo 'foo "v0.8.12' +# echo 'foo "v0.8.13' +# echo 'foo "v0.8.13' +# echo 'foo "v0.8.14' +# echo 'foo "v0.8.14' +# echo 'foo "v0.8.15' +# echo 'foo "v0.8.15' +# echo 'foo "v0.8.16' +# echo 'foo "v0.8.16' +# echo 'foo "v0.8.17' +# echo 'foo "v0.8.17' +# echo 'foo "v0.8.18' +# echo 'foo "v0.8.18' +# echo 'foo "v0.8.19' +# echo 'foo "v0.8.19' +# echo 'foo "v0.8.2' +# echo 'foo "v0.8.2' +# echo 'foo "v0.8.20' +# echo 'foo "v0.8.20' +# echo 'foo "v0.8.21' +# echo 'foo "v0.8.21' +# echo 'foo "v0.8.22' +# echo 'foo "v0.8.22' +# echo 'foo "v0.8.23' +# echo 'foo "v0.8.23' +# echo 'foo "v0.8.24' +# echo 'foo "v0.8.24' +# echo 'foo "v0.8.25' +# echo 'foo "v0.8.25' +# echo 'foo "v0.8.26' +# echo 'foo "v0.8.26' +# echo 'foo "v0.8.27' +# echo 'foo "v0.8.27' +# echo 'foo "v0.8.28' +# echo 'foo "v0.8.28' +# echo 'foo "v0.8.3' +# echo 'foo "v0.8.3' +# echo 'foo "v0.8.4' +# echo 'foo "v0.8.4' +# echo 'foo "v0.8.5' +# echo 'foo "v0.8.5' +# echo 'foo "v0.8.6' +# echo 'foo "v0.8.6' +# echo 'foo "v0.8.7' +# echo 'foo "v0.8.7' +# echo 'foo "v0.8.8' +# echo 'foo "v0.8.8' +# echo 'foo "v0.8.9' +# echo 'foo "v0.8.9' +# echo 'foo "v0.9.0' +# echo 'foo "v0.9.0' +# echo 'foo "v0.9.1' +# echo 'foo "v0.9.1' +# echo 'foo "v0.9.10' +# echo 'foo "v0.9.10' +# echo 'foo "v0.9.11' +# echo 'foo "v0.9.11' +# echo 'foo "v0.9.12' +# echo 'foo "v0.9.12' +# echo 'foo "v0.9.2' +# echo 'foo "v0.9.2' +# echo 'foo "v0.9.3' +# echo 'foo "v0.9.3' +# echo 'foo "v0.9.4' +# echo 'foo "v0.9.4' +# echo 'foo "v0.9.5' +# echo 'foo "v0.9.5' +# echo 'foo "v0.9.6' +# echo 'foo "v0.9.6' +# echo 'foo "v0.9.7' +# echo 'foo "v0.9.7' +# echo 'foo "v0.9.8' +# echo 'foo "v0.9.8' +# echo 'foo "v0.9.9' +# echo 'foo "v0.9.9' +# echo 'foo "v0.1.100' +# echo 'foo "v0.1.100' +# echo 'foo "v0.1.101' +# echo 'foo "v0.1.101' +# echo 'foo "v0.1.102' +# echo 'foo "v0.1.102' +# echo 'foo "v0.1.103' +# echo 'foo "v0.1.103' +# echo 'foo "v0.1.104' +# echo 'foo "v0.1.104' +# echo 'foo "v0.1.14' +# echo 'foo "v0.1.14' +# echo 'foo "v0.1.15' +# echo 'foo "v0.1.15' +# echo 'foo "v0.1.16' +# echo 'foo "v0.1.16' +# echo 'foo "v0.1.17' +# echo 'foo "v0.1.17' +# echo 'foo "v0.1.18' +# echo 'foo "v0.1.18' +# echo 'foo "v0.1.19' +# echo 'foo "v0.1.19' +# echo 'foo "v0.1.20' +# echo 'foo "v0.1.20' +# echo 'foo "v0.1.21' +# echo 'foo "v0.1.21' +# echo 'foo "v0.1.22' +# echo 'foo "v0.1.22' +# echo 'foo "v0.1.23' +# echo 'foo "v0.1.23' +# echo 'foo "v0.1.24' +# echo 'foo "v0.1.24' +# echo 'foo "v0.1.25' +# echo 'foo "v0.1.25' +# echo 'foo "v0.1.26' +# echo 'foo "v0.1.26' +# echo 'foo "v0.1.27' +# echo 'foo "v0.1.27' +# echo 'foo "v0.1.28' +# echo 'foo "v0.1.28' +# echo 'foo "v0.1.29' +# echo 'foo "v0.1.29' +# echo 'foo "v0.1.30' +# echo 'foo "v0.1.30' +# echo 'foo "v0.1.31' +# echo 'foo "v0.1.31' +# echo 'foo "v0.1.32' +# echo 'foo "v0.1.32' +# echo 'foo "v0.1.33' +# echo 'foo "v0.1.33' +# echo 'foo "v0.1.90' +# echo 'foo "v0.1.90' +# echo 'foo "v0.1.91' +# echo 'foo "v0.1.91' +# echo 'foo "v0.1.92' +# echo 'foo "v0.1.92' +# echo 'foo "v0.1.93' +# echo 'foo "v0.1.93' +# echo 'foo "v0.1.94' +# echo 'foo "v0.1.94' +# echo 'foo "v0.1.95' +# echo 'foo "v0.1.95' +# echo 'foo "v0.1.96' +# echo 'foo "v0.1.96' +# echo 'foo "v0.1.97' +# echo 'foo "v0.1.97' +# echo 'foo "v0.1.98' +# echo 'foo "v0.1.98' +# echo 'foo "v0.1.99' +# echo 'foo "v0.1.99' +# echo 'foo "v0.10.14' +# echo 'foo "v0.10.14' +# echo 'foo "v0.2.0' +# echo 'foo "v0.2.0' +# echo 'foo "v0.2.1' +# echo 'foo "v0.2.1' +# echo 'foo "v0.2.2' +# echo 'foo "v0.2.2' +# echo 'foo "v0.2.3' +# echo 'foo "v0.2.3' +# echo 'foo "v0.2.4' +# echo 'foo "v0.2.4' +# echo 'foo "v0.2.5' +# echo 'foo "v0.2.5' +# echo 'foo "v0.2.6' +# echo 'foo "v0.2.6' +# echo 'foo "v0.3.0' +# echo 'foo "v0.3.0' +# echo 'foo "v0.3.1' +# echo 'foo "v0.3.1' +# echo 'foo "v0.3.2' +# echo 'foo "v0.3.2' +# echo 'foo "v0.3.3' +# echo 'foo "v0.3.3' +# echo 'foo "v0.3.4' +# echo 'foo "v0.3.4' +# echo 'foo "v0.3.5' +# echo 'foo "v0.3.5' +# echo 'foo "v0.3.6' +# echo 'foo "v0.3.6' +# echo 'foo "v0.3.7' +# echo 'foo "v0.3.7' +# echo 'foo "v0.3.8' +# echo 'foo "v0.3.8' +# echo 'foo "v0.4.0' +# echo 'foo "v0.4.0' +# echo 'foo "v0.4.1' +# echo 'foo "v0.4.1' +# echo 'foo "v0.4.10' +# echo 'foo "v0.4.10' +# echo 'foo "v0.4.11' +# echo 'foo "v0.4.11' +# echo 'foo "v0.4.12' +# echo 'foo "v0.4.12' +# echo 'foo "v0.4.2' +# echo 'foo "v0.4.2' +# echo 'foo "v0.4.3' +# echo 'foo "v0.4.3' +# echo 'foo "v0.4.4' +# echo 'foo "v0.4.4' +# echo 'foo "v0.4.5' +# echo 'foo "v0.4.5' +# echo 'foo "v0.4.6' +# echo 'foo "v0.4.6' +# echo 'foo "v0.4.7' +# echo 'foo "v0.4.7' +# echo 'foo "v0.4.8' +# echo 'foo "v0.4.8' +# echo 'foo "v0.4.9' +# echo 'foo "v0.4.9' +# echo 'foo "v0.5.0' +# echo 'foo "v0.5.0' +# echo 'foo "v0.6.1' +# echo 'foo "v0.6.1' +# echo 'foo "v0.6.10' +# echo 'foo "v0.6.10' +# echo 'foo "v0.6.11' +# echo 'foo "v0.6.11' +# echo 'foo "v0.6.12' +# echo 'foo "v0.6.12' +# echo 'foo "v0.6.13' +# echo 'foo "v0.6.13' +# echo 'foo "v0.6.2' +# echo 'foo "v0.6.2' +# echo 'foo "v0.6.3' +# echo 'foo "v0.6.3' +# echo 'foo "v0.6.4' +# echo 'foo "v0.6.4' +# echo 'foo "v0.6.5' +# echo 'foo "v0.6.5' +# echo 'foo "v0.6.6' +# echo 'foo "v0.6.6' +# echo 'foo "v0.6.7' +# echo 'foo "v0.6.7' +# echo 'foo "v0.6.8' +# echo 'foo "v0.6.8' +# echo 'foo "v0.6.9' +# echo 'foo "v0.6.9' +#} +# +#OUTPUT="$(nvm_ls_remote foo)" +#EXIT_CODE="$(nvm_ls_remote foo >/dev/null 2>&1 ; echo $?)" +#[ "_$OUTPUT" = "_N/A" ] || die "nonexistent version did not report N/A" +#[ "_$EXIT_CODE" = "_3" ] || die "nonexistent version did not exit with code 3, got $EXIT_CODE" +# +#OUTPUT="$(nvm_ls_remote)" +#EXPECTED_OUTPUT="$(nvm_download | \egrep -o 'v[0-9]+\.[0-9]+\.[0-9]+' | sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n)" +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "bare nvm_ls_remote did not output expected sorted versions; got $(echo "$OUTPUT") expected $(echo "$EXPECTED_OUTPUT")" +# +#OUTPUT="$(nvm_ls_remote 0.3)" +#EXPECTED_OUTPUT="v0.3.0 +#v0.3.1 +#v0.3.2 +#v0.3.3 +#v0.3.4 +#v0.3.5 +#v0.3.6 +#v0.3.7 +#v0.3.8" +# +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_ls_remote 0.3 did not output 0.3.x versions; got $OUTPUT" +# +## Sanity checks +#OUTPUT="$(nvm_print_implicit_alias remote stable)" +#EXPECTED_OUTPUT="0.10" +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_print_implicit_alias remote stable did not output $EXPECTED_OUTPUT; got $OUTPUT" +# +#OUTPUT="$(nvm_print_implicit_alias remote unstable)" +#EXPECTED_OUTPUT="0.11" +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_print_implicit_alias remote unstable did not output $EXPECTED_OUTPUT; got $OUTPUT" +# +#OUTPUT="$(nvm_ls_remote stable)" +#EXPECTED_OUTPUT="v0.10.32" +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_ls_remote stable did not output $EXPECTED_OUTPUT; got $OUTPUT" +# +#OUTPUT="$(nvm_ls_remote unstable)" +#EXPECTED_OUTPUT="v0.11.14" +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_ls_remote unstable did not output $EXPECTED_OUTPUT; got $OUTPUT" +# +#cleanup +# +} + +@test './Unit tests/nvm_num_version_groups' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#[ "~$(nvm_num_version_groups)" = "~0" ] || die "no args should give 0" +#[ "~$(nvm_num_version_groups a)" = "~1" ] || die "one letter should give 1" +# +#[ "~$(nvm_num_version_groups 1)" = "~1" ] || die "1 should give 1" +#[ "~$(nvm_num_version_groups v1)" = "~1" ] || die "v1 should give 1" +#[ "~$(nvm_num_version_groups v1.)" = "~1" ] || die "v1. should give 1" +# +#[ "~$(nvm_num_version_groups 1.2)" = "~2" ] || die "1.2 should give 2" +#[ "~$(nvm_num_version_groups v1.2)" = "~2" ] || die "v1.2 should give 2" +#[ "~$(nvm_num_version_groups v1.2.)" = "~2" ] || die "v1.2. should give 2" +# +#[ "~$(nvm_num_version_groups 1.2.3)" = "~3" ] || die "1.2.3 should give 3" +#[ "~$(nvm_num_version_groups v1.2.3)" = "~3" ] || die "v1.2.3 should give 3" +#[ "~$(nvm_num_version_groups v1.2.3.)" = "~3" ] || die "v1.2.3. should give 3" +# +} + +@test './Unit tests/nvm_prepend_path' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#TEST_PATH=/usr/bin:/usr/local/bin +# +#NEW_PATH=`nvm_prepend_path "$TEST_PATH" "$NVM_DIR/v0.2.5/bin"` +# +#[ "$NEW_PATH" = "$NVM_DIR/v0.2.5/bin:/usr/bin:/usr/local/bin" ] || die "Not correctly prepended: $NEW_PATH " +# +# +#EMPTY_PATH= +# +#NEW_PATH=`nvm_prepend_path "$EMPTY_PATH" "$NVM_DIR/v0.2.5/bin"` +# +#[ "$NEW_PATH" = "$NVM_DIR/v0.2.5/bin" ] || die "Not correctly prepended: $NEW_PATH " +} + +@test './Unit tests/nvm_print_implicit_alias errors' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#EXPECTED_FIRST_MSG="nvm_print_implicit_alias must be specified with local or remote as the first argument." +#[ "_$(nvm_print_implicit_alias 2>&1)" = "_$EXPECTED_FIRST_MSG" ] \ +# || die "nvm_print_implicit_alias did not require local|remote as first argument" +#[ "_$(nvm_print_implicit_alias foo 2>&1)" = "_$EXPECTED_FIRST_MSG" ] \ +# || die "nvm_print_implicit_alias did not require local|remote as first argument" +# +#FIRST_EXIT_CODE="$(nvm_print_implicit_alias > /dev/null 2>&1 ; echo $?)" +#[ "_$FIRST_EXIT_CODE" = "_1" ] \ +# || die "nvm_print_implicit_alias without local|remote had wrong exit code: expected 1, got $FIRST_EXIT_CODE" +# +#EXPECTED_SECOND_MSG="Only implicit aliases 'stable' and 'unstable' are supported." +#[ "_$(nvm_print_implicit_alias local 2>&1)" = "_$EXPECTED_SECOND_MSG" ] \ +# || die "nvm_print_implicit_alias did not require stable|unstable as second argument" +#[ "_$(nvm_print_implicit_alias local foo 2>&1)" = "_$EXPECTED_SECOND_MSG" ] \ +# || die "nvm_print_implicit_alias did not require stable|unstable as second argument" +# +#SECOND_EXIT_CODE="$(nvm_print_implicit_alias local > /dev/null 2>&1 ; echo $?)" +#[ "_$SECOND_EXIT_CODE" = "_2" ] \ +# || die "nvm_print_implicit_alias without stable|unstable had wrong exit code: expected 2, got $SECOND_EXIT_CODE" +# +} + +@test './Unit tests/nvm_print_implicit_alias success' { +##!/bin/sh +# +#die () { echo $@ ; cleanup ; exit 1; } +#cleanup() { +# rm -rf ../../../v0.2.3 +# rm -rf ../../../v0.3.4 +# rm -rf ../../../v0.4.6 +# rm -rf ../../../v0.5.7 +# rm -rf ../../../v0.7.7 +# unset -f nvm_ls_remote +#} +# +#. ../../../nvm.sh +# +#mkdir ../../../v0.2.3 +#mkdir ../../../v0.3.4 +#mkdir ../../../v0.4.6 +#mkdir ../../../v0.5.7 +#mkdir ../../../v0.7.7 +# +#LATEST_STABLE="$(nvm_print_implicit_alias local stable)" +#[ "_$LATEST_STABLE" = "_0.4" ] || die "local stable is not latest even minor: expected 0.4, got $LATEST_STABLE" +# +#LATEST_UNSTABLE="$(nvm_print_implicit_alias local unstable)" +#[ "_$LATEST_UNSTABLE" = "_0.7" ] || die "local unstable is not latest odd minor: expected 0.7, got $LATEST_UNSTABLE" +# +#nvm_ls_remote() { +# echo "v0.4.3" +# echo "v0.5.4" +# echo "v0.6.6" +# echo "v0.7.7" +# echo "v0.9.7" +# echo "v0.4.3" +# echo "v0.5.4" +# echo "v0.6.6" +# echo "v0.7.7" +# echo "v0.9.7" +#} +# +#LATEST_STABLE="$(nvm_print_implicit_alias remote stable)" +#[ "_$LATEST_STABLE" = "_0.6" ] || die "remote stable is not latest even minor: expected 0.6, got $LATEST_STABLE" +# +#LATEST_UNSTABLE="$(nvm_print_implicit_alias remote unstable)" +#[ "_$LATEST_UNSTABLE" = "_0.9" ] || die "remote unstable is not latest odd minor: expected 0.9, got $LATEST_UNSTABLE" +# +#cleanup +# +} + +@test './Unit tests/nvm_remote_version' { +##!/bin/sh +# +#die () { echo $@ ; cleanup ; exit 1; } +# +#cleanup() { +# unset -f nvm_ls_remote +#} +# +#. ../../../nvm.sh +# +#nvm_ls_remote() { +# echo "N/A" +#} +# +#OUTPUT="$(nvm_remote_version foo)" +#EXIT_CODE="$(nvm_remote_version foo >/dev/null 2>&1 ; echo $?)" +# +#[ "_$OUTPUT" = "_N/A" ] || die "nonexistent version did not report N/A" +#[ "_$EXIT_CODE" = "_3" ] || die "nonexistent version did not exit with code 3, got $EXIT_CODE" +# +#nvm_ls_remote() { +# echo "test output" +# echo "more test output" +# echo "pattern received: _$1_" +#} +# +#OUTPUT="$(nvm_remote_version foo)" +#EXIT_CODE="$(nvm_remote_version foo >/dev/null 2>&1 ; echo $?)" +# +#[ "_$OUTPUT" = "_pattern received: _foo_" ] \ +# || die "nvm_remote_version foo did not return last line only of nvm_ls_remote foo; got $OUTPUT" +#[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version foo did not exit with 0, got $EXIT_CODE" +# +#cleanup +# +} + +@test './Unit tests/nvm_strip_path' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#TEST_PATH=$NVM_DIR/v0.10.5/bin:/usr/bin:$NVM_DIR/v0.11.5/bin:$NVM_DIR/v0.9.5/bin:/usr/local/bin:$NVM_DIR/v0.2.5/bin +# +#STRIPPED_PATH=`nvm_strip_path "$TEST_PATH" "/bin"` +# +#[ "$STRIPPED_PATH" = "/usr/bin:/usr/local/bin" ] || die "Not correctly stripped: $STRIPPED_PATH " +} + +@test './Unit tests/nvm_tree_contains_path' { +##!/bin/sh +# +#cleanup () { +# rm tmp/node +# rmdir tmp +# rm tmp2/node +# rmdir tmp2 +#} +#die () { echo $@ ; cleanup; exit 1; } +# +#. ../../../nvm.sh +# +#mkdir -p tmp +#touch tmp/node +#mkdir -p tmp2 +#touch tmp2/node +# +#[ "$(nvm_tree_contains_path 2>&1)" = "both the tree and the node path are required" ] || die 'incorrect error message with no args' +#[ "$(nvm_tree_contains_path > /dev/null 2>&1 ; echo $?)" = "2" ] || die 'incorrect error code with no args' +#[ "$(nvm_tree_contains_path tmp 2>&1)" = "both the tree and the node path are required" ] || die 'incorrect error message with one arg' +#[ "$(nvm_tree_contains_path > /dev/null 2>&1 ; echo $?)" = "2" ] || die 'incorrect error code with one arg' +# +#nvm_tree_contains_path tmp tmp/node || die '"tmp" should contain "tmp/node"' +# +#nvm_tree_contains_path tmp tmp2/node && die '"tmp" should not contain "tmp2/node"' +# +#nvm_tree_contains_path tmp2 tmp2/node || die '"tmp2" should contain "tmp2/node"' +# +#nvm_tree_contains_path tmp2 tmp/node && die '"tmp2" should not contain "tmp/node"' +# +#cleanup +# +} + +@test './Unit tests/nvm_validate_implicit_alias' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#EXPECTED_MSG="Only implicit aliases 'stable' and 'unstable' are supported." +#[ "_$(nvm_validate_implicit_alias 2>&1)" = "_$EXPECTED_MSG" ] \ +# || die "nvm_validate_implicit_alias did not require stable|unstable" +#[ "_$(nvm_validate_implicit_alias foo 2>&1)" = "_$EXPECTED_MSG" ] \ +# || die "nvm_validate_implicit_alias did not require stable|unstable" +# +#EXIT_CODE="$(nvm_validate_implicit_alias >/dev/null 2>&1 ; echo $?)" +#[ "_$EXIT_CODE" = "_1" ] \ +# || die "nvm_validate_implicit_alias without stable|unstable had wrong exit code: expected 1, got $EXIT_CODE" +# +#nvm_validate_implicit_alias stable || die "nvm_validate_implicit_alias stable did not exit 0" +#nvm_validate_implicit_alias unstable || die "nvm_validate_implicit_alias unstable did not exit 0" +# +} + +@test './Unit tests/nvm_version_dir' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#[ "$(nvm_version_dir)" = "$NVM_DIR/versions" ] || die '"nvm_version_dir" did not return new dir path' +#[ "$(nvm_version_dir new)" = "$(nvm_version_dir)" ] || die '"nvm_version_dir new" did not return new dir path' +#[ "$(nvm_version_dir old)" = "$NVM_DIR" ] || die '"nvm_version_dir old" did not return old dir path' +#[ "$(nvm_version_dir foo 2>&1)" = "unknown version dir" ] || die '"nvm_version_dir foo" did not error out' +# +} + +@test './Unit tests/nvm_version_greater' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#nvm_version_greater 0.10.0 0.2.12 || die '"nvm_version_greater 0.10.0 0.2.12" did not return true' +# +#if nvm_version_greater 0.10.0 0.20.12; then +# die '"nvm_version_greater 0.10.0 0.20.12" returned true' +#fi +# +#if nvm_version_greater 0.10.0 0.10.0; then +# die '"nvm_version_greater" returned false for the same two versions' +#fi +# +} + +@test './Unit tests/nvm_version_path' { +##!/bin/sh +# +#die () { echo $@ ; exit 1; } +# +#. ../../../nvm.sh +# +#[ "$(nvm_version_path foo)" = "$NVM_DIR/foo" ] || die '"nvm_version_path foo" did not return correct location' +#[ "$(nvm_version_path 2>&1)" = "version is required" ] || die '"nvm_version_path" did not error out' +#[ "$(nvm_version_path v0.11.0)" = "$NVM_DIR/v0.11.0" ] || die 'old version has the wrong path' +#[ "$(nvm_version_path v0.12.0)" = "$NVM_DIR/versions/v0.12.0" ] || die 'new version has the wrong path' +# +} + diff --git a/test/bats/test.bats b/test/bats/test.bats new file mode 100644 index 0000000..44e1abc --- /dev/null +++ b/test/bats/test.bats @@ -0,0 +1,21 @@ +#!/usr/bin/env bats + +load test_helper + +@test 'foo' { + assert_unequal "1" "1" "should be unequal" +} + +@test 'bar' { + assert_unequal "1" "1" +} + +@test 'baz' { + assert_unequal "1" "1" "" +} + +@test 'bletch' { + output="1\2" + IFS=$'\n' lines=($output) + assert_line 1 "3" "mismatch" +} \ No newline at end of file diff --git a/test/bats/test_helper.bash b/test/bats/test_helper.bash index be36d22..cb217c2 100644 --- a/test/bats/test_helper.bash +++ b/test/bats/test_helper.bash @@ -56,12 +56,22 @@ assert_failure() { assert_equal() { if [ "$1" != "$2" ]; then - { echo "expected: $1" + { [ -z "$3" ] || echo "$3" + echo "expected: $1" echo "actual: $2" } | flunk fi } +assert_unequal() { + if [ "$1" = "$2" ]; then + { [ -z "$3" ] || echo "$3" + echo "expected: $1" + echo "unequal to: $2" + } | flunk + fi +} + assert_output() { local expected if [ $# -eq 0 ]; then expected="$(cat -)" @@ -72,7 +82,7 @@ assert_output() { assert_line() { if [ "$1" -ge 0 ] 2>/dev/null; then - assert_equal "$2" "${lines[$1]}" + assert_equal "$2" "${lines[$1]}" "$3" else local line for line in "${lines[@]}"; do From 42befdc2c83b86b8e7a7c2a24f808695b027d606 Mon Sep 17 00:00:00 2001 From: smikes Date: Sun, 21 Dec 2014 12:05:37 -0700 Subject: [PATCH 10/21] remove test of test helpers --- test/bats/test.bats | 21 --------------------- 1 file changed, 21 deletions(-) delete mode 100644 test/bats/test.bats diff --git a/test/bats/test.bats b/test/bats/test.bats deleted file mode 100644 index 44e1abc..0000000 --- a/test/bats/test.bats +++ /dev/null @@ -1,21 +0,0 @@ -#!/usr/bin/env bats - -load test_helper - -@test 'foo' { - assert_unequal "1" "1" "should be unequal" -} - -@test 'bar' { - assert_unequal "1" "1" -} - -@test 'baz' { - assert_unequal "1" "1" "" -} - -@test 'bletch' { - output="1\2" - IFS=$'\n' lines=($output) - assert_line 1 "3" "mismatch" -} \ No newline at end of file From fef117efcb221a358c4ace5c164648607963f3f0 Mon Sep 17 00:00:00 2001 From: smikes Date: Sun, 21 Dec 2014 13:09:09 -0700 Subject: [PATCH 11/21] move long test into separate file --- test/bats/aliases-listall.bats | 54 ++++++++++++++++++++++++++++++++++ test/bats/aliases.bats | 28 +----------------- 2 files changed, 55 insertions(+), 27 deletions(-) create mode 100644 test/bats/aliases-listall.bats diff --git a/test/bats/aliases-listall.bats b/test/bats/aliases-listall.bats new file mode 100644 index 0000000..1104d72 --- /dev/null +++ b/test/bats/aliases-listall.bats @@ -0,0 +1,54 @@ +#!/usr/bin/env bats + +load test_helper + +NVM_SRC_DIR="${BATS_TEST_DIRNAME}/../.." +NVM_DIR="${BATS_TMPDIR}" +load "${NVM_SRC_DIR}/nvm.sh" + +setup() { + echo 'setup' >&2 + cd "${NVM_DIR}" + rm -Rf src alias v* + mkdir src alias + for i in 1 2 3 4 5 6 7 8 9 10 + do + echo 0.0.$i > alias/test-stable-$i + mkdir -p v0.0.$i + echo 0.1.$i > alias/test-unstable-$i + mkdir -p v0.1.$i + done +} + +teardown() { + echo 'teardown' >&2 + cd "${NVM_DIR}" + rm -Rf src alias v* +} + +@test './Aliases/Running "nvm alias" should list all aliases.' { + run nvm alias + + assert_line 0 'test-stable-1 -> 0.0.1 (-> v0.0.1)' "did not find test-stable-1 alias" + assert_line 1 'test-stable-10 -> 0.0.10 (-> v0.0.10)' "did not find test-stable-10 alias" + assert_line 2 'test-stable-2 -> 0.0.2 (-> v0.0.2)' "did not find test-stable-2 alias" + assert_line 3 'test-stable-3 -> 0.0.3 (-> v0.0.3)' "did not find test-stable-3 alias" + assert_line 4 'test-stable-4 -> 0.0.4 (-> v0.0.4)' "did not find test-stable-4 alias" + assert_line 5 'test-stable-5 -> 0.0.5 (-> v0.0.5)' "did not find test-stable-5 alias" + assert_line 6 'test-stable-6 -> 0.0.6 (-> v0.0.6)' "did not find test-stable-6 alias" + assert_line 7 'test-stable-7 -> 0.0.7 (-> v0.0.7)' "did not find test-stable-7 alias" + assert_line 8 'test-stable-8 -> 0.0.8 (-> v0.0.8)' "did not find test-stable-8 alias" + assert_line 9 'test-stable-9 -> 0.0.9 (-> v0.0.9)' "did not find test-stable-9 alias" + assert_line 10 'test-unstable-1 -> 0.1.1 (-> v0.1.1)' "did not find test-unstable-1 alias" + assert_line 11 'test-unstable-10 -> 0.1.10 (-> v0.1.10)' "did not find test-unstable-10 alias" + assert_line 12 'test-unstable-2 -> 0.1.2 (-> v0.1.2)' "did not find test-unstable-2 alias" + assert_line 13 'test-unstable-3 -> 0.1.3 (-> v0.1.3)' "did not find test-unstable-3 alias" + assert_line 14 'test-unstable-4 -> 0.1.4 (-> v0.1.4)' "did not find test-unstable-4 alias" + assert_line 15 'test-unstable-5 -> 0.1.5 (-> v0.1.5)' "did not find test-unstable-5 alias" + assert_line 16 'test-unstable-6 -> 0.1.6 (-> v0.1.6)' "did not find test-unstable-6 alias" + assert_line 17 'test-unstable-7 -> 0.1.7 (-> v0.1.7)' "did not find test-unstable-7 alias" + assert_line 18 'test-unstable-8 -> 0.1.8 (-> v0.1.8)' "did not find test-unstable-8 alias" + assert_line 19 'test-unstable-9 -> 0.1.9 (-> v0.1.9)' "did not find test-unstable-9 alias" + +} + diff --git a/test/bats/aliases.bats b/test/bats/aliases.bats index f5ef2f7..ca6c98a 100644 --- a/test/bats/aliases.bats +++ b/test/bats/aliases.bats @@ -11,7 +11,7 @@ setup() { cd "${NVM_DIR}" rm -Rf src alias v* mkdir src alias - for i in $(seq 1 10) + for i in 1 2 3 4 5 6 7 8 9 10 do echo 0.0.$i > alias/test-stable-$i mkdir -p v0.0.$i @@ -83,29 +83,3 @@ teardown() { assert_line 21 "unstable -> 0.8 (-> v0.8.1)" "nvm alias did not contain the overridden 'unstable' alias" } -@test './Aliases/Running "nvm alias" should list all aliases.' { - run nvm alias - - assert_line 0 'test-stable-1 -> 0.0.1 (-> v0.0.1)' "did not find test-stable-1 alias" - assert_line 1 'test-stable-10 -> 0.0.10 (-> v0.0.10)' "did not find test-stable-10 alias" - assert_line 2 'test-stable-2 -> 0.0.2 (-> v0.0.2)' "did not find test-stable-2 alias" - assert_line 3 'test-stable-3 -> 0.0.3 (-> v0.0.3)' "did not find test-stable-3 alias" - assert_line 4 'test-stable-4 -> 0.0.4 (-> v0.0.4)' "did not find test-stable-4 alias" - assert_line 5 'test-stable-5 -> 0.0.5 (-> v0.0.5)' "did not find test-stable-5 alias" - assert_line 6 'test-stable-6 -> 0.0.6 (-> v0.0.6)' "did not find test-stable-6 alias" - assert_line 7 'test-stable-7 -> 0.0.7 (-> v0.0.7)' "did not find test-stable-7 alias" - assert_line 8 'test-stable-8 -> 0.0.8 (-> v0.0.8)' "did not find test-stable-8 alias" - assert_line 9 'test-stable-9 -> 0.0.9 (-> v0.0.9)' "did not find test-stable-9 alias" - assert_line 10 'test-unstable-1 -> 0.1.1 (-> v0.1.1)' "did not find test-unstable-1 alias" - assert_line 11 'test-unstable-10 -> 0.1.10 (-> v0.1.10)' "did not find test-unstable-10 alias" - assert_line 12 'test-unstable-2 -> 0.1.2 (-> v0.1.2)' "did not find test-unstable-2 alias" - assert_line 13 'test-unstable-3 -> 0.1.3 (-> v0.1.3)' "did not find test-unstable-3 alias" - assert_line 14 'test-unstable-4 -> 0.1.4 (-> v0.1.4)' "did not find test-unstable-4 alias" - assert_line 15 'test-unstable-5 -> 0.1.5 (-> v0.1.5)' "did not find test-unstable-5 alias" - assert_line 16 'test-unstable-6 -> 0.1.6 (-> v0.1.6)' "did not find test-unstable-6 alias" - assert_line 17 'test-unstable-7 -> 0.1.7 (-> v0.1.7)' "did not find test-unstable-7 alias" - assert_line 18 'test-unstable-8 -> 0.1.8 (-> v0.1.8)' "did not find test-unstable-8 alias" - assert_line 19 'test-unstable-9 -> 0.1.9 (-> v0.1.9)' "did not find test-unstable-9 alias" - -} - From 58813cc86c4909205d2b846f5632a0394fc4d8ae Mon Sep 17 00:00:00 2001 From: smikes Date: Sun, 21 Dec 2014 13:10:35 -0700 Subject: [PATCH 12/21] remove rbenv specific envs --- test/bats/test_helper.bash | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/bats/test_helper.bash b/test/bats/test_helper.bash index cb217c2..9a79195 100644 --- a/test/bats/test_helper.bash +++ b/test/bats/test_helper.bash @@ -16,13 +16,10 @@ fi # guard against executing this block twice due to bats internals if [ "$RBENV_ROOT" != "${RBENV_TEST_DIR}/root" ]; then export RBENV_ROOT="${RBENV_TEST_DIR}/root" - export HOME="${RBENV_TEST_DIR}/home" PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin - PATH="${RBENV_TEST_DIR}/bin:$PATH" PATH="${BATS_TEST_DIRNAME}/../libexec:$PATH" PATH="${BATS_TEST_DIRNAME}/libexec:$PATH" - PATH="${RBENV_ROOT}/shims:$PATH" export PATH fi From 36b0251e5b6f324d3d339eda7c1d479152c8d1d3 Mon Sep 17 00:00:00 2001 From: smikes Date: Sun, 21 Dec 2014 13:10:45 -0700 Subject: [PATCH 13/21] port another test --- test/bats/fast.bats | 18 ++++++++++++++++-- test/bats/test_helper.bash | 18 ++++++++++++++++++ 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/test/bats/fast.bats b/test/bats/fast.bats index cd7d559..a2cd6f3 100644 --- a/test/bats/fast.bats +++ b/test/bats/fast.bats @@ -1,5 +1,7 @@ #!/usr/bin/env bats +load test_helper + NVM_SRC_DIR="${BATS_TEST_DIRNAME}/../.." load "${NVM_SRC_DIR}/nvm.sh" @@ -20,13 +22,25 @@ teardown() { @test "'nvm' command defined in environment" { run nvm - [ "$status" -eq 0 ] + assert_equal "$status" "0" "nvm command defined" } @test "Running 'nvm alias' should create a file in the alias directory." { run nvm alias test v0.1.2 [ "$status" -eq 0 ] result=$(cat "alias/test") - [ "$result" = "v0.1.2" ] + assert_equal "$result" "v0.1.2" "expected new alias" +} + +@test './Listing versions/Running "nvm ls 0.0.2" should display only version 0.0.2.' { + + mkdir -p v0.0.2 + mkdir -p v0.0.20 + + run nvm ls 0.0.2 + assert_match ${lines[0]} "v0.0.2" "nvm ls 0.0.2 must contain v0.0.2" + + run nvm ls 0.0.2 + assert_nomatch "$output" "v0.0.20" "nvm ls 0.0.2 must NOT contain v0.0.20" } diff --git a/test/bats/test_helper.bash b/test/bats/test_helper.bash index 9a79195..9a2f2aa 100644 --- a/test/bats/test_helper.bash +++ b/test/bats/test_helper.bash @@ -60,6 +60,24 @@ assert_equal() { fi } +assert_match() { + if [[ ! "$1" =~ $2 ]]; then + { [ -z "$3" ] || echo "$3" + echo "expected: $1" + echo "to match: $2" + } | flunk + fi +} + +assert_nomatch() { + if [[ "$1" =~ $2 ]]; then + { [ -z "$3" ] || echo "$3" + echo "expected : $1" + echo "to not match: $2" + } | flunk + fi +} + assert_unequal() { if [ "$1" = "$2" ]; then { [ -z "$3" ] || echo "$3" From 01d2a3faf897b1bda1473e9c8d233260a60af1ad Mon Sep 17 00:00:00 2001 From: smikes Date: Sun, 21 Dec 2014 13:25:47 -0700 Subject: [PATCH 14/21] port 4 more list tests --- test/bats/fast.bats | 49 +++++++++++++++++- test/bats/fast2.bats | 120 ------------------------------------------- 2 files changed, 48 insertions(+), 121 deletions(-) diff --git a/test/bats/fast.bats b/test/bats/fast.bats index a2cd6f3..520b432 100644 --- a/test/bats/fast.bats +++ b/test/bats/fast.bats @@ -3,7 +3,7 @@ load test_helper NVM_SRC_DIR="${BATS_TEST_DIRNAME}/../.." -load "${NVM_SRC_DIR}/nvm.sh" +source "${NVM_SRC_DIR}/nvm.sh" setup() { echo 'setup' >&2 @@ -44,3 +44,50 @@ teardown() { assert_nomatch "$output" "v0.0.20" "nvm ls 0.0.2 must NOT contain v0.0.20" } +@test './Listing versions/Running "nvm ls 0.2" should display only 0.2.x versions.' { + + mkdir -p v0.1.3 + mkdir -p v0.2.3 + mkdir -p v0.20.3 + + run nvm ls 0.1 + assert_nomatch "$output" "v0.2.3" "nvm ls 0.1 should not contain v0.2.3" + assert_nomatch "$output" "v0.20.3" "nvm ls 0.1 should not contain v0.20.3" + assert_match "$output" "v0.1.3" "nvm ls 0.1 should contain v0.1.3" + + run nvm ls 0.2 + assert_match "$output" "v0.2.3" "nvm ls 0.2 should contain v0.2.3" + assert_nomatch "$output" "v0.20.3" "nvm ls 0.2 should not contain v0.20.3" + assert_nomatch "$output" "v0.1.3" "nvm ls 0.2 should not contain v0.1.3" +} + +@test './Listing versions/Running "nvm ls foo" should return a nonzero exit code when not found' { + + run nvm ls nonexistent_version + assert_equal 3 "$status" +} + +@test './Listing versions/Running "nvm ls node" should return a nonzero exit code when not found' { + + run nvm ls node + assert_equal 3 "$status" +} + +@test './Listing versions/Running "nvm ls stable" and "nvm ls unstable" should return the appropriate implicit alias' { + + mkdir -p v0.2.3 + mkdir -p v0.3.3 + + run nvm ls stable + assert_match "$output" "0.2.3" "expected 'nvm ls stable' to give STABLE_VERSION" + + run nvm ls unstable + assert_match "$output" "0.3.3" "expected 'nvm ls unstable' to give UNSTABLE_VERSION" + mkdir -p v0.1.2 + nvm alias stable 0.1 + + run nvm ls stable + assert_nomatch "$output" "0.2.3" "expected 'nvm ls stable' to not give old STABLE_VERSION" + assert_match "$output" "v0.1.2" "expected 'nvm ls stable' to give new STABLE_VERSION" +} + diff --git a/test/bats/fast2.bats b/test/bats/fast2.bats index c2e9757..17d45c5 100644 --- a/test/bats/fast2.bats +++ b/test/bats/fast2.bats @@ -18,126 +18,6 @@ teardown() { rm -Rf src alias v* } -@test './Listing versions/Running "nvm ls 0.0.2" should display only version 0.0.2.' { -##!/bin/sh -# -#mkdir ../../../v0.0.2 -#mkdir ../../../v0.0.20 -# -#. ../../../nvm.sh -# -#die () { echo $@ ; exit 1; } -# -## The result should contain only the appropriate version numbers. -# -#nvm ls 0.0.2 | grep 'v0.0.2' > /dev/null -#if [ $? -eq 0 ]; then -# echo '"nvm ls 0.0.2" contained v0.0.2' -#fi -# -#nvm ls 0.0.2 | grep 'v0.0.20' > /dev/null -#if [ $? -eq 0 ]; then -# die '"nvm ls 0.0.2" contained v0.0.20' -#fi -# -} - -@test './Listing versions/Running "nvm ls 0.2" should display only 0.2.x versions.' { -##!/bin/sh -# -#mkdir ../../../v0.1.3 -#mkdir ../../../v0.2.3 -#mkdir ../../../v0.20.3 -# -#. ../../../nvm.sh -# -#die () { echo $@ ; exit 1; } -# -## The result should contain only the appropriate version numbers. -# -#nvm ls 0.1 | grep 'v0.2.3' > /dev/null -#if [ $? -eq 0 ]; then -# echo '"nvm ls 0.1" contained v0.2.3' -#fi -# -#nvm ls 0.1 | grep 'v0.20.3' > /dev/null -#if [ $? -eq 0 ]; then -# die '"nvm ls 0.1" contained v0.20.3' -#fi -# -#nvm ls 0.1 | grep 'v0.1.3' > /dev/null -#if [ $? -ne 0 ]; then -# die '"nvm ls 0.1" did not contain v0.1.3' -#fi -# -#nvm ls 0.2 | grep 'v0.2.3' > /dev/null -#if [ $? -ne 0 ]; then -# die '"nvm ls 0.2" did not contain v0.2.3' -#fi -# -#nvm ls 0.2 | grep 'v0.20.3' > /dev/null -#if [ $? -eq 0 ]; then -# die '"nvm ls 0.2" contained v0.20.3' -#fi -# -#nvm ls 0.2 | grep 'v0.2.3' > /dev/null -#if [ $? -ne 0 ]; then -# die '"nvm ls 0.2" did not contain v0.2.3' -#fi -} - -@test './Listing versions/Running "nvm ls foo" should return a nonzero exit code when not found' { -# #!/bin/sh -# -#. ../../../nvm.sh -# -#nvm ls nonexistent_version -#[ "$?" = "3" ] -# -} - -@test './Listing versions/Running "nvm ls node" should return a nonzero exit code when not found' { -# #!/bin/sh -# -#. ../../../nvm.sh -# -#nvm ls node -#[ "$?" = "3" ] -# -} - -@test './Listing versions/Running "nvm ls stable" and "nvm ls unstable" should return the appropriate implicit alias' { -# #!/bin/sh -# -#. ../../../nvm.sh -# -#die () { echo $@ ; exit 1; } -# -#mkdir ../../../v0.2.3 -#mkdir ../../../v0.3.3 -# -#EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)" -#STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")" -# -#EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)" -#UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")" -# -#nvm ls stable | \grep "$STABLE_VERSION" >/dev/null \ -# || die "expected 'nvm ls stable' to give $STABLE_VERSION, got $(nvm ls stable)" -# -#nvm ls unstable | \grep "$UNSTABLE_VERSION" >/dev/null \ -# || die "expected 'nvm ls unstable' to give $UNSTABLE_VERSION, got $(nvm ls unstable)" -# -#mkdir ../../../v0.1.2 -#nvm alias stable 0.1 -# -#nvm ls stable | \grep -v "$STABLE_VERSION" >/dev/null \ -# || die "'nvm ls stable' contained $STABLE_VERSION instead of v0.1.2" -#nvm ls stable | \grep v0.1.2 >/dev/null \ -# || die "'nvm ls stable' did not contain v0.1.2" -# -} - @test './Listing versions/Running "nvm ls system" should include "system" when appropriate' { ##!/bin/sh # From e2a2926d06467e53d20816176d4136c6da3d19e6 Mon Sep 17 00:00:00 2001 From: smikes Date: Sun, 21 Dec 2014 14:07:06 -0700 Subject: [PATCH 15/21] move listing tests into own file --- test/bats/fast.bats | 59 -- test/bats/fast2.bats | 1469 ------------------------------- test/bats/listing-versions.bats | 158 ++++ 3 files changed, 158 insertions(+), 1528 deletions(-) delete mode 100644 test/bats/fast2.bats create mode 100644 test/bats/listing-versions.bats diff --git a/test/bats/fast.bats b/test/bats/fast.bats index 520b432..b0b5b74 100644 --- a/test/bats/fast.bats +++ b/test/bats/fast.bats @@ -32,62 +32,3 @@ teardown() { assert_equal "$result" "v0.1.2" "expected new alias" } -@test './Listing versions/Running "nvm ls 0.0.2" should display only version 0.0.2.' { - - mkdir -p v0.0.2 - mkdir -p v0.0.20 - - run nvm ls 0.0.2 - assert_match ${lines[0]} "v0.0.2" "nvm ls 0.0.2 must contain v0.0.2" - - run nvm ls 0.0.2 - assert_nomatch "$output" "v0.0.20" "nvm ls 0.0.2 must NOT contain v0.0.20" -} - -@test './Listing versions/Running "nvm ls 0.2" should display only 0.2.x versions.' { - - mkdir -p v0.1.3 - mkdir -p v0.2.3 - mkdir -p v0.20.3 - - run nvm ls 0.1 - assert_nomatch "$output" "v0.2.3" "nvm ls 0.1 should not contain v0.2.3" - assert_nomatch "$output" "v0.20.3" "nvm ls 0.1 should not contain v0.20.3" - assert_match "$output" "v0.1.3" "nvm ls 0.1 should contain v0.1.3" - - run nvm ls 0.2 - assert_match "$output" "v0.2.3" "nvm ls 0.2 should contain v0.2.3" - assert_nomatch "$output" "v0.20.3" "nvm ls 0.2 should not contain v0.20.3" - assert_nomatch "$output" "v0.1.3" "nvm ls 0.2 should not contain v0.1.3" -} - -@test './Listing versions/Running "nvm ls foo" should return a nonzero exit code when not found' { - - run nvm ls nonexistent_version - assert_equal 3 "$status" -} - -@test './Listing versions/Running "nvm ls node" should return a nonzero exit code when not found' { - - run nvm ls node - assert_equal 3 "$status" -} - -@test './Listing versions/Running "nvm ls stable" and "nvm ls unstable" should return the appropriate implicit alias' { - - mkdir -p v0.2.3 - mkdir -p v0.3.3 - - run nvm ls stable - assert_match "$output" "0.2.3" "expected 'nvm ls stable' to give STABLE_VERSION" - - run nvm ls unstable - assert_match "$output" "0.3.3" "expected 'nvm ls unstable' to give UNSTABLE_VERSION" - mkdir -p v0.1.2 - nvm alias stable 0.1 - - run nvm ls stable - assert_nomatch "$output" "0.2.3" "expected 'nvm ls stable' to not give old STABLE_VERSION" - assert_match "$output" "v0.1.2" "expected 'nvm ls stable' to give new STABLE_VERSION" -} - diff --git a/test/bats/fast2.bats b/test/bats/fast2.bats deleted file mode 100644 index 17d45c5..0000000 --- a/test/bats/fast2.bats +++ /dev/null @@ -1,1469 +0,0 @@ -#!/usr/bin/env bats - -NVM_SRC_DIR="${BATS_TEST_DIRNAME}/../.." - -setup() { - echo 'setup' >&2 - NVM_DIR="${BATS_TMPDIR}" - cd "${NVM_DIR}" - rm -Rf src alias v* - mkdir src alias - load "${NVM_SRC_DIR}/nvm.sh" -} - -teardown() { - echo 'teardown' >&2 - NVM_DIR="${BATS_TMPDIR}" - cd "${NVM_DIR}" - rm -Rf src alias v* -} - -@test './Listing versions/Running "nvm ls system" should include "system" when appropriate' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#mkdir -p ../../../v0.0.1 -#mkdir -p ../../../v0.0.3 -#mkdir -p ../../../v0.0.9 -#mkdir -p ../../../v0.3.1 -#mkdir -p ../../../v0.3.3 -#mkdir -p ../../../v0.3.9 -# -#nvm_has_system_node() { return 0; } -#nvm ls system | grep system 2>&1 > /dev/null -#[ $? -eq 0 ] || die '"nvm ls system" did not contain "system" when system node is present' -# -#nvm_has_system_node() { return 1; } -#nvm ls system | grep system 2>&1 > /dev/null -#[ $? -ne 0 ] || die '"nvm ls system" contained "system" when system node is not present' -# -} - -@test './Listing versions/Running "nvm ls" should display all installed versions.' { -##!/bin/sh -# -#. ../../../nvm.sh -# -#mkdir ../../../v0.0.1 -#mkdir ../../../v0.0.3 -#mkdir ../../../v0.0.9 -#mkdir ../../../v0.3.1 -#mkdir ../../../v0.3.3 -#mkdir ../../../v0.3.9 -# -## The result should contain the version numbers. -#nvm ls | grep v0.0.1 && -#nvm ls | grep v0.0.3 && -#nvm ls | grep v0.0.9 && -#nvm ls | grep v0.3.1 && -#nvm ls | grep v0.3.3 && -#nvm ls | grep v0.3.9 -} - -@test './Listing versions/Running "nvm ls" should filter out ".nvm"' { -##!/bin/sh -# -#mkdir ../../../v0.1.3 -#mkdir ../../../v0.2.3 -# -#. ../../../nvm.sh -# -#[ -z `nvm ls | grep '^ *\.'` ] -## The result should contain only the appropriate version numbers. -} - -@test './Listing versions/Running "nvm ls" should filter out "versions"' { -##!/bin/sh -# -#mkdir ../../../v0.1.3 -#mkdir ../../../v0.2.3 -#mkdir ../../../versions -# -#. ../../../nvm.sh -# -#[ -z "$(nvm ls | \grep 'versions')" ] -## The result should contain only the appropriate version numbers. -# -} - -@test './Listing versions/Running "nvm ls" should include "system" when appropriate' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#mkdir -p ../../../v0.0.1 -#mkdir -p ../../../v0.0.3 -#mkdir -p ../../../v0.0.9 -#mkdir -p ../../../v0.3.1 -#mkdir -p ../../../v0.3.3 -#mkdir -p ../../../v0.3.9 -# -#nvm_has_system_node() { return 0; } -#nvm ls | grep system 2>&1 > /dev/null -#[ $? -eq 0 ] || die '"nvm ls" did not contain "system" when system node is present' -# -#nvm_has_system_node() { return 1; } -#nvm ls | grep system 2>&1 > /dev/null -#[ $? -ne 0 ] || die '"nvm ls" contained "system" when system node is not present' -# -} - -@test './Listing versions/Running "nvm ls" should list versions in the "versions" directory' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#mkdir -p ../../../versions/v0.12.1 -#mkdir ../../../v0.1.3 -# -#. ../../../nvm.sh -# -#nvm ls 0.12 | grep v0.12.1 || die '"nvm ls" did not list a version in the versions/ directory' -#nvm ls 0.1 | grep v0.1.3 || die '"nvm ls" did not list a version not in the versions/ directory' -# -} - -@test './Listing versions/Running "nvm ls" with node-like versioning vx.x.x should only list a matched version' { -##!/bin/sh -# -#mkdir ../../../v0.1.2 -# -#. ../../../nvm.sh -# -#nvm ls v0.1 | grep v0.1.2 && -#nvm ls v0.1.2 | grep v0.1.2 && -#nvm ls v0.1. | grep v0.1.2 && -#nvm ls v0.1.1 | grep N/A -# -} - -@test './Listing versions/teardown' { -#rmdir ../../../v0.0.1 >/dev/null 2>&1 -#rmdir ../../../v0.0.2 >/dev/null 2>&1 -#rmdir ../../../v0.0.3 >/dev/null 2>&1 -#rmdir ../../../v0.0.9 >/dev/null 2>&1 -#rmdir ../../../v0.0.20 >/dev/null 2>&1 -#rmdir ../../../v0.1.2 >/dev/null 2>&1 -#rmdir ../../../v0.1.3 >/dev/null 2>&1 -#rmdir ../../../v0.2.3 >/dev/null 2>&1 -#rmdir ../../../v0.3.1 >/dev/null 2>&1 -#rmdir ../../../v0.3.3 >/dev/null 2>&1 -#rmdir ../../../v0.3.9 >/dev/null 2>&1 -#rmdir ../../../v0.20.3 >/dev/null 2>&1 -#rmdir ../../../versions >/dev/null 2>&1 -#unalias nvm_has_system_node >/dev/null 2>&1 -#rm -f ../../../alias/stable >/dev/null 2>&1 -#rm -f ../../../alias/unstable >/dev/null 2>&1 -# -} - -@test './Running "nvm alias" should create a file in the alias directory.' { -##!/bin/sh -# -#. ../../nvm.sh -#nvm alias test v0.1.2 -#[ "$(cat ../../alias/test)" = "v0.1.2" ] -} - -@test './Running "nvm current" should display current nvm environment.' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../nvm.sh -# -#nvm deactivate 2>&1 -# -#[ "$(nvm current)" = "system" ] || [ "$(nvm current)" = "none" ] || die '"nvm current" did not report "system" or "none" when deactivated' -# -} - -@test './Running "nvm deactivate" should unset the nvm environment variables.' { -##!/bin/sh -# -#mkdir -p ../../v0.2.3 -# -#die () { echo $@ ; exit 1; } -# -#[ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&2 -# -#. ../../nvm.sh -#nvm use v0.2.3 || die "Failed to activate v0.2.3" -#[ `expr "$PATH" : ".*v0.2.3/.*/bin"` != 0 ] || die "PATH not set up properly" -#[ `expr "$NODE_PATH" : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "NODE_PATH should not contain (npm root -g)" -## ^ note: NODE_PATH should not contain `npm root -g` since globals should not be requireable -# -#nvm deactivate || die "Failed to deactivate v0.2.3" -#[ `expr "$PATH" : ".*v0.2.3/.*/bin"` = 0 ] || die "PATH not cleaned properly" -#[ `expr "$NODE_PATH" : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "NODE_PATH not cleaned properly" -} - -@test './Running "nvm install" with "--reinstall-packages-from" requires a valid version' { -##!/bin/sh -# -#die () { echo $@ ; cleanup ; exit 1; } -#cleanup () { -# rm -rf ../../v0.10.4 -#} -# -#mkdir ../../v0.10.4 -# -#. ../../nvm.sh -# -#nvm deactivate >/dev/null 2>&1 -# -#INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from=0.11 2>&1)" -#EXPECTED_ERROR_MSG="If --reinstall-packages-from is provided, it must point to an installed version of node." -#[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \ -# || die ""nvm install --reinstall-packages-from" should fail when given an uninstalled version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'" -# -#INSTALL_EXIT_CODE="$(nvm install v0.10.5 --reinstall-packages-from=0.11 >/dev/null 2>&1; echo $?)" -#[ "~$INSTALL_EXIT_CODE" = "~5" ] \ -# || die ""nvm install --reinstall-packages-from" should exit with code 5 when given an uninstalled version, got $INSTALL_EXIT_CODE" -# -#INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from=0.10.5 2>&1)" -#EXPECTED_ERROR_MSG="You can't reinstall global packages from the same version of node you're installing." -#[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \ -# || die ""nvm install --reinstall-packages-from" should fail when given the same version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'" -# -#INSTALL_EXIT_CODE="$(nvm install v0.10.5 --reinstall-packages-from=0.10.5 >/dev/null 2>&1; echo $?)" -#[ "~$INSTALL_EXIT_CODE" = "~4" ] \ -# || die ""nvm install --reinstall-packages-from" should exit with code 4 when given the same version, got $INSTALL_EXIT_CODE" -# -} - -@test './Running "nvm install" with an invalid version fails nicely' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../nvm.sh -#[ "$(nvm install invalid.invalid 2>&1)" = "Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions." ] || die "nvm installing an invalid version did not print a nice error message" -# -} - -@test './Running "nvm unalias" should remove the alias file.' { -##!/bin/sh -# -#echo v0.1.2 > ../../alias/test -#. ../../nvm.sh -#nvm unalias test -#! [ -e ../../alias/test ] -} - -@test './Running "nvm uninstall" should remove the appropriate directory.' { -##!/bin/sh -# -#cd ../.. -#mkdir v0.0.1 -#mkdir src/node-v0.0.1 -# -#. ./nvm.sh -#nvm uninstall v0.0.1 -# -#[ ! -d 'v0.0.1' ] && [ ! -d 'src/node-v0.0.1' ] -} - -@test './Running "nvm unload" should unset all function and variables.' { -##!/bin/sh -# -#fail () { echo $@ ; exit 1; } -# -#. ../../nvm.sh -# -#type nvm > /dev/null 2>&1 || fail "NVM not loaded" -# -#nvm unload -# -#type nvm > /dev/null 2>&1 && fail "NVM not unloaded" || exit 0 -# -} - -@test './Running "nvm use foo" where "foo" is circular aborts' { -##!/bin/sh -# -#die () { echo $@ ; cleanup ; exit 1; } -# -#cleanup() { -# rm -rf ../../alias/foo -#} -# -#. ../../nvm.sh -# -#echo 'foo' > ../../alias/foo -# -#OUTPUT="$(nvm use foo 2>&1)" -#EXPECTED_OUTPUT='The alias "foo" leads to an infinite loop. Aborting.' -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \ -# || die "'nvm use foo' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'" -# -#EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)" -#[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got $EXIT_CODE" -# -#cleanup; -# -} - -@test './Running "nvm use system" should work as expected' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../nvm.sh -# -#nvm_has_system_node() { return 0; } -#[ "$(nvm use system 2>&1 | tail -n1)" = "Now using system version of node: $(node -v)." ] || die "Could not use system version of node" -# -#nvm_has_system_node() { return 1; } -#[ "$(nvm use system 2>&1 | tail -n1)" = "System version of node not found." ] || die "Did not report error, system node not found" -#nvm use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found" -# -} - -@test './Running "nvm use x" should create and change the "current" symlink' { -##!/bin/bash -# -#export NVM_SYMLINK_CURRENT=true -#. ../../nvm.sh -# -#rm -rf ../../v0.10.29 -#mkdir ../../v0.10.29 -#nvm use 0.10.29 -#rmdir ../../v0.10.29 -# -#if [ ! -L ../../current ];then -# echo "Expected 'current' symlink to be created!" -# exit 1 -#fi -# -#oldLink="$(readlink ../../current)" -# -#if [ "$(basename $oldLink)" != 'v0.10.29' ];then -# echo "Expected 'current' to point to v0.10.29 but was $oldLink" -# exit 1 -#fi -# -#rm -rf ../../v0.11.13 -#mkdir ../../v0.11.13 -#nvm use 0.11.13 -#rmdir ../../v0.11.13 -# -#newLink="$(readlink ../../current)" -# -#if [ "$(basename $newLink)" != 'v0.11.13' ];then -# echo "Expected 'current' to point to v0.11.13 but was $newLink" -# exit 1 -#fi -} - -@test './Running "nvm use x" should not create the "current" symlink if $NVM_SYMLINK_CURRENT is false' { -##!/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 2>&1 -# rmdir ../../${TEST_NODE_VERSION} -#} -# -#function isCurrentSymlinkPresent() { -# [ -L ../../current ] -#} -# -#NVM_SYMLINK_CURRENT=false -#cleanup -#runNvmUse -#isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=false!" -#registerExpectedNoSymlink $? -# -#NVM_SYMLINK_CURRENT=true -#cleanup -#runNvmUse -#isCurrentSymlinkPresent || echo >&2 "Expected 'current' symlink to be created when NVM_SYMLINK_CURRENT=true!" -#registerExpectedSymlink $? -# -#NVM_SYMLINK_CURRENT=garbagevalue -#cleanup -#runNvmUse -#isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT contains a string!" -#registerExpectedNoSymlink $? -# -#NVM_SYMLINK_CURRENT=0 -#cleanup -#runNvmUse -#isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=0!" -#registerExpectedNoSymlink $? -# -#NVM_SYMLINK_CURRENT=1 -#cleanup -#runNvmUse -#isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=1!" -#registerExpectedNoSymlink $? -# -#unset NVM_SYMLINK_CURRENT -#cleanup -#runNvmUse -#isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT has been unset (default behaviour)!" -#registerExpectedNoSymlink $? -# -#cleanup -# -#[ ${TEST_FAILED} -ne 0 ] && echo "${TEST_COUNT} tested, ${TEST_PASSED} passed, ${TEST_FAILED} failed" && exit 1 || true -# -} - -@test './setup' { -##!/bin/sh -# -#( -# cd ../.. -# -# # Back up -# -# type setopt >/dev/null 2>&1 && setopt NULL_GLOB -# type shopt >/dev/null 2>&1 && shopt -s nullglob -# rm -Rf v* src alias -# mkdir src alias -#) -} - -@test './setup_dir' { -##!/bin/sh -# -#( -# cd ../.. -# -# # Back up -# -# mkdir -p bak -# for SRC in v* src alias; do -# [ -e "$SRC" ] && mv "$SRC" bak -# done -# if [ -d versions ]; then -# mv versions bak -# fi -# true -#) -} - -@test './Sourcing nvm.sh should make the nvm command available.' { -##!/bin/sh -# -#. ../../nvm.sh -#nvm -} - -@test './teardown' { -##!/bin/sh -# -## Remove temporary files -#( -# cd ../.. -# -# type setopt >/dev/null 2>&1 && setopt NULL_GLOB -# type shopt >/dev/null 2>&1 && shopt -s nullglob -# rm -fR v* src alias -#) -} - -@test './teardown_dir' { -##!/bin/sh -# -#( -# cd ../.. -# -# # Restore -# if [ -d bak ] -# then -# mv bak/* . > /dev/null 2>&1 || sleep 0s -# rmdir bak -# fi -# mkdir -p src alias -#) -} - -@test './Unit tests/nvm_alias' { -##!/bin/sh -# -#die () { echo $@ ; cleanup ; exit 1; } -# -#cleanup () { -# rm -rf ../../../alias/test -#} -# -#. ../../../nvm.sh -# -#OUTPUT="$(nvm_alias 2>&1)" -#EXPECTED_OUTPUT='An alias is required.' -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_alias' produced wrong output; got $OUTPUT" -# -#EXIT_CODE="$(nvm_alias >/dev/null 2>&1 ; echo $?)" -#[ "_$EXIT_CODE" = "_1" ] || die "'nvm_alias' exited with $EXIT_CODE, expected 1" -# -#rm -rf ../../../alias/nonexistent -# -#OUTPUT="$(nvm_alias nonexistent 2>&1)" -#EXPECTED_OUTPUT='Alias does not exist.' -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_alias nonexistent' produced wrong output; got $OUTPUT" -# -#EXIT_CODE="$(nvm_alias nonexistent >/dev/null 2>&1 ; echo $?)" -#[ "_$EXIT_CODE" = "_2" ] || die "'nvm_alias nonexistent' exited with $EXIT_CODE, expected 2" -# -#EXPECTED_OUTPUT="0.10" -#nvm alias test "$EXPECTED_OUTPUT" || die "'nvm alias test $EXPECTED_OUTPUT' failed" -#OUTPUT="$(nvm_alias test)" -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_alias test' produced wrong output; got $OUTPUT" -# -#cleanup -# -} - -@test './Unit tests/nvm_checksum' { -##!/bin/sh -# -#cleanup () { -# rm tmp/emptyfile tmp/testfile -# rmdir tmp -#} -#die () { echo $@ ; cleanup; exit 1; } -# -#. ../../../nvm.sh -# -#mkdir -p tmp -#touch tmp/emptyfile -#echo -n "test" > tmp/testfile -# -#nvm_checksum tmp/emptyfile "da39a3ee5e6b4b0d3255bfef95601890afd80709" || die "nvm_checksum on an empty file did not match the SHA1 digest of the empty string" -#nvm_checksum tmp/testfile "da39a3ee5e6b4b0d3255bfef95601890afd80709" && die "nvm_checksum allowed a bad checksum" -# -#cleanup -} - -@test './Unit tests/nvm_find_up' { -##!/bin/sh -# -#die () { echo $@ ; cleanup ; exit 1; } -#setup() { -# cleanup -# mkdir -p tmp_nvm_find_up/a/b/c/d -# touch tmp_nvm_find_up/test -# touch tmp_nvm_find_up/a/b/c/test -#} -#cleanup () { -# rm -rf tmp_nvm_find_up -#} -# -#. ../../../nvm.sh -# -#setup -# -#TEST_DIR="$PWD" -# -#[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up" ] || die "failed to find 1 dir up" -#[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up" ] || die "failed to find 2 dirs up" -#[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b/c nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up/a/b/c" ] || die "failed to find in current dir" -#[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b/c/d nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up/a/b/c" ] || die "failed to find 1 level up from current dir" -# -#cleanup -# -} - -@test './Unit tests/nvm_format_version' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#OUTPUT="$(nvm_format_version 0.1.2)" -#EXPECTED_OUTPUT="v0.1.2" -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_format_version 0.1.2 did not return $EXPECTED_OUTPUT; got $OUTPUT" -# -#OUTPUT="$(nvm_format_version 0.1)" -#EXPECTED_OUTPUT="v0.1.0" -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_format_version 0.1.0 did not return $EXPECTED_OUTPUT; got $OUTPUT" -# -} - -@test './Unit tests/nvm_has' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#nvm_has cat && type cat > /dev/null || die 'nvm_has locates "cat" properly' -# -#[ "~$(nvm_has foobarbaz 2>&1)" = "~" ] || die "nvm_has does not suppress error output" -# -#! nvm_has foobarbaz && ! type foobarbaz >/dev/null 2>&1 || die "nvm_has does not return a nonzero exit code when not found" -# -} - -@test './Unit tests/nvm_has_system_node' { -##!/bin/sh -# -#cleanup () { -# rm ../../../v0.1.2/node -# rmdir ../../../v0.1.2 -#} -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#mkdir ../../../v0.1.2 -#touch ../../../v0.1.2/node -# -#nvm use 0.1.2 -# -#if command -v node; then -# nvm_has_system_node -#else -# ! nvm_has_system_node -#fi -# -#nvm deactivate /dev/null 2>&1 -# -#if command -v node; then -# nvm_has_system_node -#else -# ! nvm_has_system_node -#fi -# -} - -@test './Unit tests/nvm_ls_current' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#return_zero () { return 0; } -# -#[ "$(nvm deactivate > /dev/null 2>&1 ; nvm_ls_current)" = "system" ] || die 'when deactivated, did not return "system"' -# -#TEST_PWD=$(pwd) -#TEST_DIR="$TEST_PWD/nvm_ls_current_tmp" -#rm -rf "$TEST_DIR" -#mkdir "$TEST_DIR" -#ln -s "$(which which)" "$TEST_DIR/which" -#ln -s "$(which dirname)" "$TEST_DIR/dirname" -# -#[ "$(PATH="$TEST_DIR" nvm_ls_current)" = "none" ] || die 'when node not installed, nvm_ls_current did not return "none"' -#[ "@$(PATH="$TEST_DIR" nvm_ls_current 2> /dev/stdout 1> /dev/null)@" = "@@" ] || die 'when node not installed, nvm_ls_current returned error output' -# -#echo "#!/bin/bash" > "$TEST_DIR/node" -#echo "echo 'VERSION FOO!'" > "$TEST_DIR/node" -#chmod a+x "$TEST_DIR/node" -# -#[ "$(alias nvm_tree_contains_path='return_zero' && PATH="$TEST_DIR" nvm_ls_current)" = "VERSION FOO!" ] || die 'when activated, did not return nvm node version' -# -#rm -rf "$TEST_DIR" -# -} - -@test './Unit tests/nvm_ls_remote' { -##!/bin/sh -# -#die () { echo $@ ; cleanup ; exit 1; } -# -#cleanup() { -# unset -f nvm_download -#} -# -#. ../../../nvm.sh -# -## sample output at the time the test was written -#nvm_download() { -# echo 'foo "v0.10.0' -# echo 'foo "v0.10.0' -# echo 'foo "v0.10.1' -# echo 'foo "v0.10.1' -# echo 'foo "v0.10.10' -# echo 'foo "v0.10.10' -# echo 'foo "v0.10.11' -# echo 'foo "v0.10.11' -# echo 'foo "v0.10.12' -# echo 'foo "v0.10.12' -# echo 'foo "v0.10.13' -# echo 'foo "v0.10.13' -# echo 'foo "v0.10.14' -# echo 'foo "v0.10.14' -# echo 'foo "v0.10.15' -# echo 'foo "v0.10.15' -# echo 'foo "v0.10.16' -# echo 'foo "v0.10.16' -# echo 'foo "v0.10.16' -# echo 'foo "v0.10.16' -# echo 'foo "v0.10.17' -# echo 'foo "v0.10.17' -# echo 'foo "v0.10.18' -# echo 'foo "v0.10.18' -# echo 'foo "v0.10.19' -# echo 'foo "v0.10.19' -# echo 'foo "v0.10.2' -# echo 'foo "v0.10.2' -# echo 'foo "v0.10.20' -# echo 'foo "v0.10.20' -# echo 'foo "v0.10.21' -# echo 'foo "v0.10.21' -# echo 'foo "v0.10.22' -# echo 'foo "v0.10.22' -# echo 'foo "v0.10.23' -# echo 'foo "v0.10.23' -# echo 'foo "v0.10.24' -# echo 'foo "v0.10.24' -# echo 'foo "v0.10.25' -# echo 'foo "v0.10.25' -# echo 'foo "v0.10.26' -# echo 'foo "v0.10.26' -# echo 'foo "v0.10.27' -# echo 'foo "v0.10.27' -# echo 'foo "v0.10.28' -# echo 'foo "v0.10.28' -# echo 'foo "v0.10.29' -# echo 'foo "v0.10.29' -# echo 'foo "v0.10.3' -# echo 'foo "v0.10.3' -# echo 'foo "v0.10.30' -# echo 'foo "v0.10.30' -# echo 'foo "v0.10.31' -# echo 'foo "v0.10.31' -# echo 'foo "v0.10.32' -# echo 'foo "v0.10.32' -# echo 'foo "v0.10.4' -# echo 'foo "v0.10.4' -# echo 'foo "v0.10.5' -# echo 'foo "v0.10.5' -# echo 'foo "v0.10.6' -# echo 'foo "v0.10.6' -# echo 'foo "v0.10.7' -# echo 'foo "v0.10.7' -# echo 'foo "v0.10.8' -# echo 'foo "v0.10.8' -# echo 'foo "v0.10.9' -# echo 'foo "v0.10.9' -# echo 'foo "v0.11.0' -# echo 'foo "v0.11.0' -# echo 'foo "v0.11.1' -# echo 'foo "v0.11.1' -# echo 'foo "v0.11.10' -# echo 'foo "v0.11.10' -# echo 'foo "v0.11.11' -# echo 'foo "v0.11.11' -# echo 'foo "v0.11.12' -# echo 'foo "v0.11.12' -# echo 'foo "v0.11.13' -# echo 'foo "v0.11.13' -# echo 'foo "v0.11.14' -# echo 'foo "v0.11.14' -# echo 'foo "v0.11.2' -# echo 'foo "v0.11.2' -# echo 'foo "v0.11.3' -# echo 'foo "v0.11.3' -# echo 'foo "v0.11.4' -# echo 'foo "v0.11.4' -# echo 'foo "v0.11.5' -# echo 'foo "v0.11.5' -# echo 'foo "v0.11.6' -# echo 'foo "v0.11.6' -# echo 'foo "v0.11.7' -# echo 'foo "v0.11.7' -# echo 'foo "v0.11.8' -# echo 'foo "v0.11.8' -# echo 'foo "v0.11.9' -# echo 'foo "v0.11.9' -# echo 'foo "v0.5.1' -# echo 'foo "v0.5.1' -# echo 'foo "v0.5.10' -# echo 'foo "v0.5.10' -# echo 'foo "v0.5.2' -# echo 'foo "v0.5.2' -# echo 'foo "v0.5.3' -# echo 'foo "v0.5.3' -# echo 'foo "v0.5.4' -# echo 'foo "v0.5.4' -# echo 'foo "v0.5.5' -# echo 'foo "v0.5.5' -# echo 'foo "v0.5.6' -# echo 'foo "v0.5.6' -# echo 'foo "v0.5.7' -# echo 'foo "v0.5.7' -# echo 'foo "v0.5.8' -# echo 'foo "v0.5.8' -# echo 'foo "v0.5.9' -# echo 'foo "v0.5.9' -# echo 'foo "v0.6.0' -# echo 'foo "v0.6.0' -# echo 'foo "v0.6.1' -# echo 'foo "v0.6.1' -# echo 'foo "v0.6.10' -# echo 'foo "v0.6.10' -# echo 'foo "v0.6.11' -# echo 'foo "v0.6.11' -# echo 'foo "v0.6.12' -# echo 'foo "v0.6.12' -# echo 'foo "v0.6.13' -# echo 'foo "v0.6.13' -# echo 'foo "v0.6.14' -# echo 'foo "v0.6.14' -# echo 'foo "v0.6.15' -# echo 'foo "v0.6.15' -# echo 'foo "v0.6.16' -# echo 'foo "v0.6.16' -# echo 'foo "v0.6.17' -# echo 'foo "v0.6.17' -# echo 'foo "v0.6.18' -# echo 'foo "v0.6.18' -# echo 'foo "v0.6.19' -# echo 'foo "v0.6.19' -# echo 'foo "v0.6.2' -# echo 'foo "v0.6.2' -# echo 'foo "v0.6.20' -# echo 'foo "v0.6.20' -# echo 'foo "v0.6.21' -# echo 'foo "v0.6.21' -# echo 'foo "v0.6.3' -# echo 'foo "v0.6.3' -# echo 'foo "v0.6.4' -# echo 'foo "v0.6.4' -# echo 'foo "v0.6.5' -# echo 'foo "v0.6.5' -# echo 'foo "v0.6.6' -# echo 'foo "v0.6.6' -# echo 'foo "v0.6.7' -# echo 'foo "v0.6.7' -# echo 'foo "v0.6.8' -# echo 'foo "v0.6.8' -# echo 'foo "v0.6.9' -# echo 'foo "v0.6.9' -# echo 'foo "v0.7.0' -# echo 'foo "v0.7.0' -# echo 'foo "v0.7.1' -# echo 'foo "v0.7.1' -# echo 'foo "v0.7.10' -# echo 'foo "v0.7.10' -# echo 'foo "v0.7.11' -# echo 'foo "v0.7.11' -# echo 'foo "v0.7.12' -# echo 'foo "v0.7.12' -# echo 'foo "v0.7.2' -# echo 'foo "v0.7.2' -# echo 'foo "v0.7.3' -# echo 'foo "v0.7.3' -# echo 'foo "v0.7.4' -# echo 'foo "v0.7.4' -# echo 'foo "v0.7.5' -# echo 'foo "v0.7.5' -# echo 'foo "v0.7.6' -# echo 'foo "v0.7.6' -# echo 'foo "v0.7.7' -# echo 'foo "v0.7.7' -# echo 'foo "v0.7.8' -# echo 'foo "v0.7.8' -# echo 'foo "v0.7.9' -# echo 'foo "v0.7.9' -# echo 'foo "v0.8.0' -# echo 'foo "v0.8.0' -# echo 'foo "v0.8.1' -# echo 'foo "v0.8.1' -# echo 'foo "v0.8.10' -# echo 'foo "v0.8.10' -# echo 'foo "v0.8.11' -# echo 'foo "v0.8.11' -# echo 'foo "v0.8.12' -# echo 'foo "v0.8.12' -# echo 'foo "v0.8.13' -# echo 'foo "v0.8.13' -# echo 'foo "v0.8.14' -# echo 'foo "v0.8.14' -# echo 'foo "v0.8.15' -# echo 'foo "v0.8.15' -# echo 'foo "v0.8.16' -# echo 'foo "v0.8.16' -# echo 'foo "v0.8.17' -# echo 'foo "v0.8.17' -# echo 'foo "v0.8.18' -# echo 'foo "v0.8.18' -# echo 'foo "v0.8.19' -# echo 'foo "v0.8.19' -# echo 'foo "v0.8.2' -# echo 'foo "v0.8.2' -# echo 'foo "v0.8.20' -# echo 'foo "v0.8.20' -# echo 'foo "v0.8.21' -# echo 'foo "v0.8.21' -# echo 'foo "v0.8.22' -# echo 'foo "v0.8.22' -# echo 'foo "v0.8.23' -# echo 'foo "v0.8.23' -# echo 'foo "v0.8.24' -# echo 'foo "v0.8.24' -# echo 'foo "v0.8.25' -# echo 'foo "v0.8.25' -# echo 'foo "v0.8.26' -# echo 'foo "v0.8.26' -# echo 'foo "v0.8.27' -# echo 'foo "v0.8.27' -# echo 'foo "v0.8.28' -# echo 'foo "v0.8.28' -# echo 'foo "v0.8.3' -# echo 'foo "v0.8.3' -# echo 'foo "v0.8.4' -# echo 'foo "v0.8.4' -# echo 'foo "v0.8.5' -# echo 'foo "v0.8.5' -# echo 'foo "v0.8.6' -# echo 'foo "v0.8.6' -# echo 'foo "v0.8.7' -# echo 'foo "v0.8.7' -# echo 'foo "v0.8.8' -# echo 'foo "v0.8.8' -# echo 'foo "v0.8.9' -# echo 'foo "v0.8.9' -# echo 'foo "v0.9.0' -# echo 'foo "v0.9.0' -# echo 'foo "v0.9.1' -# echo 'foo "v0.9.1' -# echo 'foo "v0.9.10' -# echo 'foo "v0.9.10' -# echo 'foo "v0.9.11' -# echo 'foo "v0.9.11' -# echo 'foo "v0.9.12' -# echo 'foo "v0.9.12' -# echo 'foo "v0.9.2' -# echo 'foo "v0.9.2' -# echo 'foo "v0.9.3' -# echo 'foo "v0.9.3' -# echo 'foo "v0.9.4' -# echo 'foo "v0.9.4' -# echo 'foo "v0.9.5' -# echo 'foo "v0.9.5' -# echo 'foo "v0.9.6' -# echo 'foo "v0.9.6' -# echo 'foo "v0.9.7' -# echo 'foo "v0.9.7' -# echo 'foo "v0.9.8' -# echo 'foo "v0.9.8' -# echo 'foo "v0.9.9' -# echo 'foo "v0.9.9' -# echo 'foo "v0.1.100' -# echo 'foo "v0.1.100' -# echo 'foo "v0.1.101' -# echo 'foo "v0.1.101' -# echo 'foo "v0.1.102' -# echo 'foo "v0.1.102' -# echo 'foo "v0.1.103' -# echo 'foo "v0.1.103' -# echo 'foo "v0.1.104' -# echo 'foo "v0.1.104' -# echo 'foo "v0.1.14' -# echo 'foo "v0.1.14' -# echo 'foo "v0.1.15' -# echo 'foo "v0.1.15' -# echo 'foo "v0.1.16' -# echo 'foo "v0.1.16' -# echo 'foo "v0.1.17' -# echo 'foo "v0.1.17' -# echo 'foo "v0.1.18' -# echo 'foo "v0.1.18' -# echo 'foo "v0.1.19' -# echo 'foo "v0.1.19' -# echo 'foo "v0.1.20' -# echo 'foo "v0.1.20' -# echo 'foo "v0.1.21' -# echo 'foo "v0.1.21' -# echo 'foo "v0.1.22' -# echo 'foo "v0.1.22' -# echo 'foo "v0.1.23' -# echo 'foo "v0.1.23' -# echo 'foo "v0.1.24' -# echo 'foo "v0.1.24' -# echo 'foo "v0.1.25' -# echo 'foo "v0.1.25' -# echo 'foo "v0.1.26' -# echo 'foo "v0.1.26' -# echo 'foo "v0.1.27' -# echo 'foo "v0.1.27' -# echo 'foo "v0.1.28' -# echo 'foo "v0.1.28' -# echo 'foo "v0.1.29' -# echo 'foo "v0.1.29' -# echo 'foo "v0.1.30' -# echo 'foo "v0.1.30' -# echo 'foo "v0.1.31' -# echo 'foo "v0.1.31' -# echo 'foo "v0.1.32' -# echo 'foo "v0.1.32' -# echo 'foo "v0.1.33' -# echo 'foo "v0.1.33' -# echo 'foo "v0.1.90' -# echo 'foo "v0.1.90' -# echo 'foo "v0.1.91' -# echo 'foo "v0.1.91' -# echo 'foo "v0.1.92' -# echo 'foo "v0.1.92' -# echo 'foo "v0.1.93' -# echo 'foo "v0.1.93' -# echo 'foo "v0.1.94' -# echo 'foo "v0.1.94' -# echo 'foo "v0.1.95' -# echo 'foo "v0.1.95' -# echo 'foo "v0.1.96' -# echo 'foo "v0.1.96' -# echo 'foo "v0.1.97' -# echo 'foo "v0.1.97' -# echo 'foo "v0.1.98' -# echo 'foo "v0.1.98' -# echo 'foo "v0.1.99' -# echo 'foo "v0.1.99' -# echo 'foo "v0.10.14' -# echo 'foo "v0.10.14' -# echo 'foo "v0.2.0' -# echo 'foo "v0.2.0' -# echo 'foo "v0.2.1' -# echo 'foo "v0.2.1' -# echo 'foo "v0.2.2' -# echo 'foo "v0.2.2' -# echo 'foo "v0.2.3' -# echo 'foo "v0.2.3' -# echo 'foo "v0.2.4' -# echo 'foo "v0.2.4' -# echo 'foo "v0.2.5' -# echo 'foo "v0.2.5' -# echo 'foo "v0.2.6' -# echo 'foo "v0.2.6' -# echo 'foo "v0.3.0' -# echo 'foo "v0.3.0' -# echo 'foo "v0.3.1' -# echo 'foo "v0.3.1' -# echo 'foo "v0.3.2' -# echo 'foo "v0.3.2' -# echo 'foo "v0.3.3' -# echo 'foo "v0.3.3' -# echo 'foo "v0.3.4' -# echo 'foo "v0.3.4' -# echo 'foo "v0.3.5' -# echo 'foo "v0.3.5' -# echo 'foo "v0.3.6' -# echo 'foo "v0.3.6' -# echo 'foo "v0.3.7' -# echo 'foo "v0.3.7' -# echo 'foo "v0.3.8' -# echo 'foo "v0.3.8' -# echo 'foo "v0.4.0' -# echo 'foo "v0.4.0' -# echo 'foo "v0.4.1' -# echo 'foo "v0.4.1' -# echo 'foo "v0.4.10' -# echo 'foo "v0.4.10' -# echo 'foo "v0.4.11' -# echo 'foo "v0.4.11' -# echo 'foo "v0.4.12' -# echo 'foo "v0.4.12' -# echo 'foo "v0.4.2' -# echo 'foo "v0.4.2' -# echo 'foo "v0.4.3' -# echo 'foo "v0.4.3' -# echo 'foo "v0.4.4' -# echo 'foo "v0.4.4' -# echo 'foo "v0.4.5' -# echo 'foo "v0.4.5' -# echo 'foo "v0.4.6' -# echo 'foo "v0.4.6' -# echo 'foo "v0.4.7' -# echo 'foo "v0.4.7' -# echo 'foo "v0.4.8' -# echo 'foo "v0.4.8' -# echo 'foo "v0.4.9' -# echo 'foo "v0.4.9' -# echo 'foo "v0.5.0' -# echo 'foo "v0.5.0' -# echo 'foo "v0.6.1' -# echo 'foo "v0.6.1' -# echo 'foo "v0.6.10' -# echo 'foo "v0.6.10' -# echo 'foo "v0.6.11' -# echo 'foo "v0.6.11' -# echo 'foo "v0.6.12' -# echo 'foo "v0.6.12' -# echo 'foo "v0.6.13' -# echo 'foo "v0.6.13' -# echo 'foo "v0.6.2' -# echo 'foo "v0.6.2' -# echo 'foo "v0.6.3' -# echo 'foo "v0.6.3' -# echo 'foo "v0.6.4' -# echo 'foo "v0.6.4' -# echo 'foo "v0.6.5' -# echo 'foo "v0.6.5' -# echo 'foo "v0.6.6' -# echo 'foo "v0.6.6' -# echo 'foo "v0.6.7' -# echo 'foo "v0.6.7' -# echo 'foo "v0.6.8' -# echo 'foo "v0.6.8' -# echo 'foo "v0.6.9' -# echo 'foo "v0.6.9' -#} -# -#OUTPUT="$(nvm_ls_remote foo)" -#EXIT_CODE="$(nvm_ls_remote foo >/dev/null 2>&1 ; echo $?)" -#[ "_$OUTPUT" = "_N/A" ] || die "nonexistent version did not report N/A" -#[ "_$EXIT_CODE" = "_3" ] || die "nonexistent version did not exit with code 3, got $EXIT_CODE" -# -#OUTPUT="$(nvm_ls_remote)" -#EXPECTED_OUTPUT="$(nvm_download | \egrep -o 'v[0-9]+\.[0-9]+\.[0-9]+' | sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n)" -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "bare nvm_ls_remote did not output expected sorted versions; got $(echo "$OUTPUT") expected $(echo "$EXPECTED_OUTPUT")" -# -#OUTPUT="$(nvm_ls_remote 0.3)" -#EXPECTED_OUTPUT="v0.3.0 -#v0.3.1 -#v0.3.2 -#v0.3.3 -#v0.3.4 -#v0.3.5 -#v0.3.6 -#v0.3.7 -#v0.3.8" -# -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_ls_remote 0.3 did not output 0.3.x versions; got $OUTPUT" -# -## Sanity checks -#OUTPUT="$(nvm_print_implicit_alias remote stable)" -#EXPECTED_OUTPUT="0.10" -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_print_implicit_alias remote stable did not output $EXPECTED_OUTPUT; got $OUTPUT" -# -#OUTPUT="$(nvm_print_implicit_alias remote unstable)" -#EXPECTED_OUTPUT="0.11" -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_print_implicit_alias remote unstable did not output $EXPECTED_OUTPUT; got $OUTPUT" -# -#OUTPUT="$(nvm_ls_remote stable)" -#EXPECTED_OUTPUT="v0.10.32" -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_ls_remote stable did not output $EXPECTED_OUTPUT; got $OUTPUT" -# -#OUTPUT="$(nvm_ls_remote unstable)" -#EXPECTED_OUTPUT="v0.11.14" -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_ls_remote unstable did not output $EXPECTED_OUTPUT; got $OUTPUT" -# -#cleanup -# -} - -@test './Unit tests/nvm_num_version_groups' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#[ "~$(nvm_num_version_groups)" = "~0" ] || die "no args should give 0" -#[ "~$(nvm_num_version_groups a)" = "~1" ] || die "one letter should give 1" -# -#[ "~$(nvm_num_version_groups 1)" = "~1" ] || die "1 should give 1" -#[ "~$(nvm_num_version_groups v1)" = "~1" ] || die "v1 should give 1" -#[ "~$(nvm_num_version_groups v1.)" = "~1" ] || die "v1. should give 1" -# -#[ "~$(nvm_num_version_groups 1.2)" = "~2" ] || die "1.2 should give 2" -#[ "~$(nvm_num_version_groups v1.2)" = "~2" ] || die "v1.2 should give 2" -#[ "~$(nvm_num_version_groups v1.2.)" = "~2" ] || die "v1.2. should give 2" -# -#[ "~$(nvm_num_version_groups 1.2.3)" = "~3" ] || die "1.2.3 should give 3" -#[ "~$(nvm_num_version_groups v1.2.3)" = "~3" ] || die "v1.2.3 should give 3" -#[ "~$(nvm_num_version_groups v1.2.3.)" = "~3" ] || die "v1.2.3. should give 3" -# -} - -@test './Unit tests/nvm_prepend_path' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#TEST_PATH=/usr/bin:/usr/local/bin -# -#NEW_PATH=`nvm_prepend_path "$TEST_PATH" "$NVM_DIR/v0.2.5/bin"` -# -#[ "$NEW_PATH" = "$NVM_DIR/v0.2.5/bin:/usr/bin:/usr/local/bin" ] || die "Not correctly prepended: $NEW_PATH " -# -# -#EMPTY_PATH= -# -#NEW_PATH=`nvm_prepend_path "$EMPTY_PATH" "$NVM_DIR/v0.2.5/bin"` -# -#[ "$NEW_PATH" = "$NVM_DIR/v0.2.5/bin" ] || die "Not correctly prepended: $NEW_PATH " -} - -@test './Unit tests/nvm_print_implicit_alias errors' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#EXPECTED_FIRST_MSG="nvm_print_implicit_alias must be specified with local or remote as the first argument." -#[ "_$(nvm_print_implicit_alias 2>&1)" = "_$EXPECTED_FIRST_MSG" ] \ -# || die "nvm_print_implicit_alias did not require local|remote as first argument" -#[ "_$(nvm_print_implicit_alias foo 2>&1)" = "_$EXPECTED_FIRST_MSG" ] \ -# || die "nvm_print_implicit_alias did not require local|remote as first argument" -# -#FIRST_EXIT_CODE="$(nvm_print_implicit_alias > /dev/null 2>&1 ; echo $?)" -#[ "_$FIRST_EXIT_CODE" = "_1" ] \ -# || die "nvm_print_implicit_alias without local|remote had wrong exit code: expected 1, got $FIRST_EXIT_CODE" -# -#EXPECTED_SECOND_MSG="Only implicit aliases 'stable' and 'unstable' are supported." -#[ "_$(nvm_print_implicit_alias local 2>&1)" = "_$EXPECTED_SECOND_MSG" ] \ -# || die "nvm_print_implicit_alias did not require stable|unstable as second argument" -#[ "_$(nvm_print_implicit_alias local foo 2>&1)" = "_$EXPECTED_SECOND_MSG" ] \ -# || die "nvm_print_implicit_alias did not require stable|unstable as second argument" -# -#SECOND_EXIT_CODE="$(nvm_print_implicit_alias local > /dev/null 2>&1 ; echo $?)" -#[ "_$SECOND_EXIT_CODE" = "_2" ] \ -# || die "nvm_print_implicit_alias without stable|unstable had wrong exit code: expected 2, got $SECOND_EXIT_CODE" -# -} - -@test './Unit tests/nvm_print_implicit_alias success' { -##!/bin/sh -# -#die () { echo $@ ; cleanup ; exit 1; } -#cleanup() { -# rm -rf ../../../v0.2.3 -# rm -rf ../../../v0.3.4 -# rm -rf ../../../v0.4.6 -# rm -rf ../../../v0.5.7 -# rm -rf ../../../v0.7.7 -# unset -f nvm_ls_remote -#} -# -#. ../../../nvm.sh -# -#mkdir ../../../v0.2.3 -#mkdir ../../../v0.3.4 -#mkdir ../../../v0.4.6 -#mkdir ../../../v0.5.7 -#mkdir ../../../v0.7.7 -# -#LATEST_STABLE="$(nvm_print_implicit_alias local stable)" -#[ "_$LATEST_STABLE" = "_0.4" ] || die "local stable is not latest even minor: expected 0.4, got $LATEST_STABLE" -# -#LATEST_UNSTABLE="$(nvm_print_implicit_alias local unstable)" -#[ "_$LATEST_UNSTABLE" = "_0.7" ] || die "local unstable is not latest odd minor: expected 0.7, got $LATEST_UNSTABLE" -# -#nvm_ls_remote() { -# echo "v0.4.3" -# echo "v0.5.4" -# echo "v0.6.6" -# echo "v0.7.7" -# echo "v0.9.7" -# echo "v0.4.3" -# echo "v0.5.4" -# echo "v0.6.6" -# echo "v0.7.7" -# echo "v0.9.7" -#} -# -#LATEST_STABLE="$(nvm_print_implicit_alias remote stable)" -#[ "_$LATEST_STABLE" = "_0.6" ] || die "remote stable is not latest even minor: expected 0.6, got $LATEST_STABLE" -# -#LATEST_UNSTABLE="$(nvm_print_implicit_alias remote unstable)" -#[ "_$LATEST_UNSTABLE" = "_0.9" ] || die "remote unstable is not latest odd minor: expected 0.9, got $LATEST_UNSTABLE" -# -#cleanup -# -} - -@test './Unit tests/nvm_remote_version' { -##!/bin/sh -# -#die () { echo $@ ; cleanup ; exit 1; } -# -#cleanup() { -# unset -f nvm_ls_remote -#} -# -#. ../../../nvm.sh -# -#nvm_ls_remote() { -# echo "N/A" -#} -# -#OUTPUT="$(nvm_remote_version foo)" -#EXIT_CODE="$(nvm_remote_version foo >/dev/null 2>&1 ; echo $?)" -# -#[ "_$OUTPUT" = "_N/A" ] || die "nonexistent version did not report N/A" -#[ "_$EXIT_CODE" = "_3" ] || die "nonexistent version did not exit with code 3, got $EXIT_CODE" -# -#nvm_ls_remote() { -# echo "test output" -# echo "more test output" -# echo "pattern received: _$1_" -#} -# -#OUTPUT="$(nvm_remote_version foo)" -#EXIT_CODE="$(nvm_remote_version foo >/dev/null 2>&1 ; echo $?)" -# -#[ "_$OUTPUT" = "_pattern received: _foo_" ] \ -# || die "nvm_remote_version foo did not return last line only of nvm_ls_remote foo; got $OUTPUT" -#[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version foo did not exit with 0, got $EXIT_CODE" -# -#cleanup -# -} - -@test './Unit tests/nvm_strip_path' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#TEST_PATH=$NVM_DIR/v0.10.5/bin:/usr/bin:$NVM_DIR/v0.11.5/bin:$NVM_DIR/v0.9.5/bin:/usr/local/bin:$NVM_DIR/v0.2.5/bin -# -#STRIPPED_PATH=`nvm_strip_path "$TEST_PATH" "/bin"` -# -#[ "$STRIPPED_PATH" = "/usr/bin:/usr/local/bin" ] || die "Not correctly stripped: $STRIPPED_PATH " -} - -@test './Unit tests/nvm_tree_contains_path' { -##!/bin/sh -# -#cleanup () { -# rm tmp/node -# rmdir tmp -# rm tmp2/node -# rmdir tmp2 -#} -#die () { echo $@ ; cleanup; exit 1; } -# -#. ../../../nvm.sh -# -#mkdir -p tmp -#touch tmp/node -#mkdir -p tmp2 -#touch tmp2/node -# -#[ "$(nvm_tree_contains_path 2>&1)" = "both the tree and the node path are required" ] || die 'incorrect error message with no args' -#[ "$(nvm_tree_contains_path > /dev/null 2>&1 ; echo $?)" = "2" ] || die 'incorrect error code with no args' -#[ "$(nvm_tree_contains_path tmp 2>&1)" = "both the tree and the node path are required" ] || die 'incorrect error message with one arg' -#[ "$(nvm_tree_contains_path > /dev/null 2>&1 ; echo $?)" = "2" ] || die 'incorrect error code with one arg' -# -#nvm_tree_contains_path tmp tmp/node || die '"tmp" should contain "tmp/node"' -# -#nvm_tree_contains_path tmp tmp2/node && die '"tmp" should not contain "tmp2/node"' -# -#nvm_tree_contains_path tmp2 tmp2/node || die '"tmp2" should contain "tmp2/node"' -# -#nvm_tree_contains_path tmp2 tmp/node && die '"tmp2" should not contain "tmp/node"' -# -#cleanup -# -} - -@test './Unit tests/nvm_validate_implicit_alias' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#EXPECTED_MSG="Only implicit aliases 'stable' and 'unstable' are supported." -#[ "_$(nvm_validate_implicit_alias 2>&1)" = "_$EXPECTED_MSG" ] \ -# || die "nvm_validate_implicit_alias did not require stable|unstable" -#[ "_$(nvm_validate_implicit_alias foo 2>&1)" = "_$EXPECTED_MSG" ] \ -# || die "nvm_validate_implicit_alias did not require stable|unstable" -# -#EXIT_CODE="$(nvm_validate_implicit_alias >/dev/null 2>&1 ; echo $?)" -#[ "_$EXIT_CODE" = "_1" ] \ -# || die "nvm_validate_implicit_alias without stable|unstable had wrong exit code: expected 1, got $EXIT_CODE" -# -#nvm_validate_implicit_alias stable || die "nvm_validate_implicit_alias stable did not exit 0" -#nvm_validate_implicit_alias unstable || die "nvm_validate_implicit_alias unstable did not exit 0" -# -} - -@test './Unit tests/nvm_version_dir' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#[ "$(nvm_version_dir)" = "$NVM_DIR/versions" ] || die '"nvm_version_dir" did not return new dir path' -#[ "$(nvm_version_dir new)" = "$(nvm_version_dir)" ] || die '"nvm_version_dir new" did not return new dir path' -#[ "$(nvm_version_dir old)" = "$NVM_DIR" ] || die '"nvm_version_dir old" did not return old dir path' -#[ "$(nvm_version_dir foo 2>&1)" = "unknown version dir" ] || die '"nvm_version_dir foo" did not error out' -# -} - -@test './Unit tests/nvm_version_greater' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#nvm_version_greater 0.10.0 0.2.12 || die '"nvm_version_greater 0.10.0 0.2.12" did not return true' -# -#if nvm_version_greater 0.10.0 0.20.12; then -# die '"nvm_version_greater 0.10.0 0.20.12" returned true' -#fi -# -#if nvm_version_greater 0.10.0 0.10.0; then -# die '"nvm_version_greater" returned false for the same two versions' -#fi -# -} - -@test './Unit tests/nvm_version_path' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#[ "$(nvm_version_path foo)" = "$NVM_DIR/foo" ] || die '"nvm_version_path foo" did not return correct location' -#[ "$(nvm_version_path 2>&1)" = "version is required" ] || die '"nvm_version_path" did not error out' -#[ "$(nvm_version_path v0.11.0)" = "$NVM_DIR/v0.11.0" ] || die 'old version has the wrong path' -#[ "$(nvm_version_path v0.12.0)" = "$NVM_DIR/versions/v0.12.0" ] || die 'new version has the wrong path' -# -} - diff --git a/test/bats/listing-versions.bats b/test/bats/listing-versions.bats new file mode 100644 index 0000000..54e1d79 --- /dev/null +++ b/test/bats/listing-versions.bats @@ -0,0 +1,158 @@ +#!/usr/bin/env bats + +load test_helper + +NVM_SRC_DIR="${BATS_TEST_DIRNAME}/../.." + +setup() { + NVM_DIR="${BATS_TMPDIR}" + cd "${NVM_DIR}" + rm -Rf src alias v* + mkdir src alias + load "${NVM_SRC_DIR}/nvm.sh" +} + +teardown() { + NVM_DIR="${BATS_TMPDIR}" + cd "${NVM_DIR}" + rm -Rf src alias v* +} + +@test './Listing versions/Running "nvm ls 0.0.2" should display only version 0.0.2.' { + + mkdir -p v0.0.2 + mkdir -p v0.0.20 + + run nvm ls 0.0.2 + assert_match ${lines[0]} "v0.0.2" "nvm ls 0.0.2 must contain v0.0.2" + + run nvm ls 0.0.2 + assert_nomatch "$output" "v0.0.20" "nvm ls 0.0.2 must NOT contain v0.0.20" +} + +@test './Listing versions/Running "nvm ls 0.2" should display only 0.2.x versions.' { + + mkdir -p v0.1.3 + mkdir -p v0.2.3 + mkdir -p v0.20.3 + + run nvm ls 0.1 + assert_nomatch "$output" "v0.2.3" "nvm ls 0.1 should not contain v0.2.3" + assert_nomatch "$output" "v0.20.3" "nvm ls 0.1 should not contain v0.20.3" + assert_match "$output" "v0.1.3" "nvm ls 0.1 should contain v0.1.3" + + run nvm ls 0.2 + assert_match "$output" "v0.2.3" "nvm ls 0.2 should contain v0.2.3" + assert_nomatch "$output" "v0.20.3" "nvm ls 0.2 should not contain v0.20.3" + assert_nomatch "$output" "v0.1.3" "nvm ls 0.2 should not contain v0.1.3" +} + +@test './Listing versions/Running "nvm ls foo" should return a nonzero exit code when not found' { + + run nvm ls nonexistent_version + assert_equal 3 "$status" +} + +@test './Listing versions/Running "nvm ls node" should return a nonzero exit code when not found' { + + run nvm ls node + assert_equal 3 "$status" +} + +@test './Listing versions/Running "nvm ls stable" and "nvm ls unstable" should return the appropriate implicit alias' { + + mkdir -p v0.2.3 + mkdir -p v0.3.3 + + run nvm ls stable + assert_match "$output" "0.2.3" "expected 'nvm ls stable' to give STABLE_VERSION" + + run nvm ls unstable + assert_match "$output" "0.3.3" "expected 'nvm ls unstable' to give UNSTABLE_VERSION" + mkdir -p v0.1.2 + nvm alias stable 0.1 + + run nvm ls stable + assert_nomatch "$output" "0.2.3" "expected 'nvm ls stable' to not give old STABLE_VERSION" + assert_match "$output" "v0.1.2" "expected 'nvm ls stable' to give new STABLE_VERSION" +} + +## merged two tests here +# `nvm ls` and `nvm ls system` +@test './Listing versions/Running "nvm ls [system]" should include "system" when appropriate' { + + mkdir -p v0.{0,3}.{1,3,9} + + nvm_has_system_node() { return 0; } + run nvm ls system + assert_match "$output" system '"nvm ls system" did not contain "system" when system node is present' + + run nvm ls + assert_match "$output" system '"nvm ls" did not contain "system" when system node is present' + + nvm_has_system_node() { return 1; } + run nvm ls system + assert_nomatch "$output" system '"nvm ls system" contained "system" when system node is NOT present' + + run nvm ls + assert_nomatch "$output" system '"nvm ls" contained "system" when system node is NOT present' +} + +@test './Listing versions/Running "nvm ls" should display all installed versions.' { + + mkdir -p v0.{0,3}.{1,3,9} + + run nvm ls + assert_match "$output" v0.0.1 + assert_match "$output" v0.0.3 + assert_match "$output" v0.0.9 + assert_match "$output" v0.3.1 + assert_match "$output" v0.3.3 + assert_match "$output" v0.3.9 +} + +@test './Listing versions/Running "nvm ls" should filter out ".nvm"' { + + mkdir -p v0.{1,2}.3 + + run nvm ls + assert_nomatch "$output" "^ *\." "running 'nvm ls' should filter out dotfiles" +} + +@test './Listing versions/Running "nvm ls" should filter out "versions"' { + + mkdir -p v0.{1,2}.3 versions + run nvm ls + assert_nomatch "$output" versions "running 'nvm ls' should filter out 'versions'" +} + +@test './Listing versions/Running "nvm ls" should list versions both in and out of the "versions" directory' { + + mkdir -p versions/v0.12.1 + mkdir -p v0.1.3 + + run nvm ls 0.12 + assert_match "$output" "v0.12.1" "'nvm ls' did not list a version in versions/" + + run nvm ls 0.1 + assert_match "$output" "v0.1.3" "'nvm ls' did not list a version NOT in versions/" + +} + +@test './Listing versions/Running "nvm ls" with node-like versioning vx.x.x should only list a matched version' { + + mkdir -p v0.1.2 + + run nvm ls v0.1 + assert_match "$output" "v0.1.2" + + run nvm ls v0.1.2 + assert_match "$output" "v0.1.2" + + run nvm ls v0.1. + assert_match "$output" "v0.1.2" + + run nvm ls v0.1.1 + assert_nomatch "$output" "v0.1.2" + assert_match "$output" "N/A" +} From 324210598c73b70034724898551544a70b6b412b Mon Sep 17 00:00:00 2001 From: smikes Date: Sun, 21 Dec 2014 14:43:05 -0700 Subject: [PATCH 16/21] add a few more fast tests --- test/bats/fast.bats | 112 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 2 deletions(-) diff --git a/test/bats/fast.bats b/test/bats/fast.bats index b0b5b74..fff641c 100644 --- a/test/bats/fast.bats +++ b/test/bats/fast.bats @@ -5,8 +5,17 @@ load test_helper NVM_SRC_DIR="${BATS_TEST_DIRNAME}/../.." source "${NVM_SRC_DIR}/nvm.sh" +test_debug() { + false # set to 'true' to get setup/teardown in test stderr +} + +test_implementing() { + true # set to 'false' to run all tests; set to 'true' to skip implemented tests + # only used while porting to bats: remove afterward +} + setup() { - echo 'setup' >&2 + test_debug && echo 'setup' >&2 NVM_DIR="${BATS_TMPDIR}" cd "${NVM_DIR}" rm -Rf src alias v* @@ -14,21 +23,120 @@ setup() { } teardown() { - echo 'teardown' >&2 + test_debug && echo 'teardown' >&2 NVM_DIR="${BATS_TMPDIR}" cd "${NVM_DIR}" rm -Rf src alias v* } @test "'nvm' command defined in environment" { + test_implementing && skip run nvm assert_equal "$status" "0" "nvm command defined" } @test "Running 'nvm alias' should create a file in the alias directory." { + test_implementing && skip run nvm alias test v0.1.2 [ "$status" -eq 0 ] result=$(cat "alias/test") assert_equal "$result" "v0.1.2" "expected new alias" } +@test 'Running "nvm current" should display current nvm environment.' { + test_implementing && skip + + run nvm deactivate + + run nvm current + assert_match "$output" 'system|none' "expected 'none' or 'system' when deactivated" +} + +@test 'Running "nvm deactivate" should unset the nvm environment variables.' { + test_implementing && skip + + mkdir -p v0.2.3 + + # v0.2.3 should not be active + assert_nomatch "$PATH" ".*v0.2.3/.*/bin" "v0.2.3 should not be active yet" + [ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] + + x=$(nvm_version_path v0.2.3) + + # can't use 'run' -- sets up new env, PATH is lost + nvm use 0.2.3 + + assert_match $PATH "v0.2.3/.*/bin" "PATH should contain v0.2.3" + assert_nomatch $NODE_PATH "v0.2.3/lib/node_modules" "NODE_PATH should not contain v0.2.3" + + nvm deactivate + + assert_nomatch $PATH "v0.2.3/.*/bin" "PATH should be cleaned of v0.2.3" + assert_nomatch $NODE_PATH "v0.2.3/lib/node_modules" "NODE_PATH should not contain v0.2.3" +} + +@test 'Running "nvm install" with "--reinstall-packages-from" requires a valid version' { + test_implementing && skip + + mkdir -p v0.10.4 + + nvm deactivate + + run nvm install v0.10.5 --reinstall-packages-from=0.11 + assert_equal 5 "$status" "should exit with code 5, invalid version" + assert_match "$output" "If --reinstall-packages-from is provided, it must point to an installed version of node." + + run nvm install v0.10.5 --reinstall-packages-from=0.10.5 + assert_equal 4 "$status" "should exit with code 4, same version" + assert_match "$output" "You can't reinstall global packages from the same version of node you're installing." + +} + +@test 'Running "nvm install" with an invalid version fails nicely' { + test_implementing && skip + + run nvm install invalid.invalid + assert_equal "3" "$status" "Invalid version, exit with status 3" + assert_match "$output" "Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions." "nvm installing an invalid version did not print a nice error message" +} + +@test 'Running "nvm unalias" should remove the alias file.' { + test_implementing && skip + + echo v0.1.2 > alias/test + + run nvm unalias test + ! [ -e alias/test ] +} + +@test 'Running "nvm uninstall" should remove the appropriate directory.' { + test_implementing && skip + + mkdir -p v0.0.1 src/node-v0.0.1 + + nvm uninstall v0.0.1 + ! [ -d 'v0.0.1' ] + ! [ -d 'src/node-v0.0.1' ] +} + +@test 'Running "nvm unload" should unset all function and variables.' { + test_implementing && skip + + run type nvm + assert_equal 0 "$status" "nvm not loaded" + + nvm unload + + run type nvm + assert_equal 1 "$status" "nvm should have unloaded" +} + +@test 'Running "nvm use foo" where "foo" is circular aborts' { + test_implementing && skip + + echo 'foo' > alias/foo + + run nvm use foo + assert_equal 8 "$status" "Expected exit code 8 (infinite alias loop)" + assert_match "$output" 'The alias "foo" leads to an infinite loop. Aborting.' +} From 0796a2932c93c2af0e97f9cdfd7cd5fc623db9bc Mon Sep 17 00:00:00 2001 From: smikes Date: Sun, 21 Dec 2014 16:03:35 -0700 Subject: [PATCH 17/21] fix test tiles --- test/bats/listing-versions.bats | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/test/bats/listing-versions.bats b/test/bats/listing-versions.bats index 54e1d79..f209df8 100644 --- a/test/bats/listing-versions.bats +++ b/test/bats/listing-versions.bats @@ -18,7 +18,7 @@ teardown() { rm -Rf src alias v* } -@test './Listing versions/Running "nvm ls 0.0.2" should display only version 0.0.2.' { +@test 'Listing versions/Running "nvm ls 0.0.2" should display only version 0.0.2.' { mkdir -p v0.0.2 mkdir -p v0.0.20 @@ -30,7 +30,7 @@ teardown() { assert_nomatch "$output" "v0.0.20" "nvm ls 0.0.2 must NOT contain v0.0.20" } -@test './Listing versions/Running "nvm ls 0.2" should display only 0.2.x versions.' { +@test 'Listing versions/Running "nvm ls 0.2" should display only 0.2.x versions.' { mkdir -p v0.1.3 mkdir -p v0.2.3 @@ -47,19 +47,19 @@ teardown() { assert_nomatch "$output" "v0.1.3" "nvm ls 0.2 should not contain v0.1.3" } -@test './Listing versions/Running "nvm ls foo" should return a nonzero exit code when not found' { +@test 'Listing versions/Running "nvm ls foo" should return a nonzero exit code when not found' { run nvm ls nonexistent_version assert_equal 3 "$status" } -@test './Listing versions/Running "nvm ls node" should return a nonzero exit code when not found' { +@test 'Listing versions/Running "nvm ls node" should return a nonzero exit code when not found' { run nvm ls node assert_equal 3 "$status" } -@test './Listing versions/Running "nvm ls stable" and "nvm ls unstable" should return the appropriate implicit alias' { +@test 'Listing versions/Running "nvm ls stable" and "nvm ls unstable" should return the appropriate implicit alias' { mkdir -p v0.2.3 mkdir -p v0.3.3 @@ -79,7 +79,7 @@ teardown() { ## merged two tests here # `nvm ls` and `nvm ls system` -@test './Listing versions/Running "nvm ls [system]" should include "system" when appropriate' { +@test 'Listing versions/Running "nvm ls [system]" should include "system" when appropriate' { mkdir -p v0.{0,3}.{1,3,9} @@ -98,7 +98,7 @@ teardown() { assert_nomatch "$output" system '"nvm ls" contained "system" when system node is NOT present' } -@test './Listing versions/Running "nvm ls" should display all installed versions.' { +@test 'Listing versions/Running "nvm ls" should display all installed versions.' { mkdir -p v0.{0,3}.{1,3,9} @@ -111,7 +111,7 @@ teardown() { assert_match "$output" v0.3.9 } -@test './Listing versions/Running "nvm ls" should filter out ".nvm"' { +@test 'Listing versions/Running "nvm ls" should filter out ".nvm"' { mkdir -p v0.{1,2}.3 @@ -119,14 +119,14 @@ teardown() { assert_nomatch "$output" "^ *\." "running 'nvm ls' should filter out dotfiles" } -@test './Listing versions/Running "nvm ls" should filter out "versions"' { +@test 'Listing versions/Running "nvm ls" should filter out "versions"' { mkdir -p v0.{1,2}.3 versions run nvm ls assert_nomatch "$output" versions "running 'nvm ls' should filter out 'versions'" } -@test './Listing versions/Running "nvm ls" should list versions both in and out of the "versions" directory' { +@test 'Listing versions/Running "nvm ls" should list versions both in and out of the "versions" directory' { mkdir -p versions/v0.12.1 mkdir -p v0.1.3 @@ -139,7 +139,7 @@ teardown() { } -@test './Listing versions/Running "nvm ls" with node-like versioning vx.x.x should only list a matched version' { +@test 'Listing versions/Running "nvm ls" with node-like versioning vx.x.x should only list a matched version' { mkdir -p v0.1.2 From 757075dc7d70379cef66bb4dcbb99bd3e4180261 Mon Sep 17 00:00:00 2001 From: smikes Date: Sun, 21 Dec 2014 16:03:52 -0700 Subject: [PATCH 18/21] only unit tests remain --- test/bats/fast.bats | 84 +- test/bats/{fast-raw.bats => unit-tests.bats} | 816 +------------------ 2 files changed, 98 insertions(+), 802 deletions(-) rename test/bats/{fast-raw.bats => unit-tests.bats} (54%) diff --git a/test/bats/fast.bats b/test/bats/fast.bats index fff641c..7092f6a 100644 --- a/test/bats/fast.bats +++ b/test/bats/fast.bats @@ -10,7 +10,7 @@ test_debug() { } test_implementing() { - true # set to 'false' to run all tests; set to 'true' to skip implemented tests + false # set to 'false' to run all tests; set to 'true' to skip implemented tests # only used while porting to bats: remove afterward } @@ -140,3 +140,85 @@ teardown() { assert_equal 8 "$status" "Expected exit code 8 (infinite alias loop)" assert_match "$output" 'The alias "foo" leads to an infinite loop. Aborting.' } + +@test 'Running "nvm use system" should work as expected' { + test_implementing && skip + + # NOTE: undocumented assumption of this test is + # that node is installed on the test machine! + # TODO: fix that, by using a mock + + nvm_has_system_node() { return 0; } + run nvm use system + assert_equal 0 "$status" "Expect success in using system node" + assert_match "$output" 'Now using system version of node:' + + nvm_has_system_node() { return 1; } + run nvm use system + assert_equal 127 "$status" "Expect failure when no system node" + assert_match "$output" 'System version of node not found.' +} + +@test 'Running "nvm use x" should create and change the "current" symlink' { + test_implementing && skip + + export NVM_SYMLINK_CURRENT=true + + mkdir -p v0.10.29 + nvm use 0.10.29 + rmdir v0.10.29 + + # TODO make this a proper assert + [ -L current ] # "expected 'current' symlink to be created" + + oldLink="$(readlink current)" + + assert_equal "$(basename $oldLink)" "v0.10.29" "Expected 'current' to point to v0.10.29 but was $oldLink" + + mkdir v0.11.13 + nvm use 0.11.13 + rmdir v0.11.13 + + newlink="$(readlink current)" + + assert_equal "$(basename $newlink)" "v0.11.13" "Expected 'current' to point to v0.11.13 but was $newLink" +} + +@test 'Running "nvm use x" should not create the "current" symlink if $NVM_SYMLINK_CURRENT is false' { + test_implementing && skip + + test_symlink_made() { + local arg="$1" + + mkdir v0.10.29 + + if [ "$arg" = "undef" ] + then + unset NVM_SYMLINK_CURRENT + else + NVM_SYMLINK_CURRENT="$arg" + fi + + run nvm use 0.10.29 + run [ -L current ] + result="$status" + + rm -f current + rmdir v0.10.29 + + return $result + } + + test_symlink_made 'true' + + ! test_symlink_made 'false' + ! test_symlink_made 'garbagevalue' + ! test_symlink_made 0 + ! test_symlink_made 1 + ! test_symlink_made 'undef' +} + +@test 'Sourcing nvm.sh should make the nvm command available.' { + + nvm +} diff --git a/test/bats/fast-raw.bats b/test/bats/unit-tests.bats similarity index 54% rename from test/bats/fast-raw.bats rename to test/bats/unit-tests.bats index 00a5593..8a751de 100644 --- a/test/bats/fast-raw.bats +++ b/test/bats/unit-tests.bats @@ -1,821 +1,35 @@ #!/usr/bin/env bats +load test_helper + NVM_SRC_DIR="${BATS_TEST_DIRNAME}/../.." -load "${NVM_SRC_DIR}/nvm.sh" +source "${NVM_SRC_DIR}/nvm.sh" + +test_debug() { + false # set to 'true' to get setup/teardown in test stderr +} + +test_implementing() { + true # set to 'false' to run all tests; set to 'true' to skip implemented tests + # only used while porting to bats: remove afterward +} setup() { - echo 'setup' >&2 + test_debug && echo 'setup' >&2 NVM_DIR="${BATS_TMPDIR}" cd "${NVM_DIR}" rm -Rf src alias v* mkdir src alias + load "${NVM_SRC_DIR}/nvm.sh" } teardown() { - echo 'teardown' >&2 + test_debug && echo 'teardown' >&2 NVM_DIR="${BATS_TMPDIR}" cd "${NVM_DIR}" rm -Rf src alias v* } -@test './Aliases/nvm_resolve_alias' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#EXIT_CODE=$(nvm_resolve_alias ; echo $?) -#[ $EXIT_CODE = "1" ] || die "nvm_resolve_alias without an argument did not return 1; got $EXIT_CODE" -# -#for i in $(seq 1 10) -# do -# STABLE_ALIAS="$(nvm_resolve_alias test-stable-$i)" -# [ "_$STABLE_ALIAS" = "_v0.0.$i" ] \ -# || die "'nvm_resolve_alias test-stable-$i' was not v0.0.$i; got $STABLE_ALIAS" -# UNSTABLE_ALIAS="$(nvm_resolve_alias test-unstable-$i)" -# [ "_$UNSTABLE_ALIAS" = "_v0.1.$i" ] \ -# || die "'nvm_resolve_alias test-unstable-$i' was not v0.1.$i; got $UNSTABLE_ALIAS" -#done -# -#EXIT_CODE=$(nvm_resolve_alias nonexistent ; echo $?) -#[ $EXIT_CODE = "2" ] || die "'nvm_resolve_alias nonexistent' did not return 2; got $EXIT_CODE" -# -#STABLE="$(nvm_resolve_alias stable)" -#[ "_$STABLE" = "_v0.0.10" ] || die "'nvm_resolve_alias stable' was not v0.0.10; got $STABLE" -# -#UNSTABLE="$(nvm_resolve_alias unstable)" -#[ "_$UNSTABLE" = "_v0.1.10" ] || die "'nvm_resolve_alias unstable' was not v0.1.10; got $UNSTABLE" -# -} - -@test './Aliases/Running "nvm alias " should list but one alias.' { -##!/bin/sh -# -#. ../../../nvm.sh -#[ $(nvm alias test-stable-1 | wc -l) = '2' ] -} - -@test './Aliases/Running "nvm alias" lists implicit aliases when they do not exist' { -##!/bin/sh -# -#. ../../../nvm.sh -# -#die () { echo $@ ; exit 1; } -# -#NVM_ALIAS_OUTPUT=$(nvm alias) -# -#EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)" -#STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e "^stable -> $EXPECTED_STABLE (-> $STABLE_VERSION) (default)$" \ -# || die -# -#EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)" -#UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e "^unstable -> $EXPECTED_UNSTABLE (-> $UNSTABLE_VERSION) (default)$" \ -# || die -# -} - -@test './Aliases/Running "nvm alias" lists manual aliases instead of implicit aliases when present' { -##!/bin/sh -# -#. ../../../nvm.sh -# -#die () { echo $@ ; cleanup ; exit 1; } -#cleanup () { -# rm -rf ../../../alias/stable -# rm -rf ../../../alias/unstable -# rm -rf ../../../v0.8.1 -# rm -rf ../../../v0.9.1 -#} -# -#mkdir ../../../v0.8.1 -#mkdir ../../../v0.9.1 -# -#EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)" -#STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")" -# -#EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)" -#UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")" -# -#[ "_$STABLE_VERSION" != "_$UNSTABLE_VERSION" ] \ -# || die "stable and unstable versions are the same!" -# -#nvm alias stable "$EXPECTED_UNSTABLE" -#nvm alias unstable "$EXPECTED_STABLE" -# -#NVM_ALIAS_OUTPUT=$(nvm alias) -# -#echo "$NVM_ALIAS_OUTPUT" | \grep -e "^stable -> $EXPECTED_UNSTABLE (-> $UNSTABLE_VERSION)$" \ -# || die "nvm alias did not contain the overridden 'stable' alias" -# -#echo "$NVM_ALIAS_OUTPUT" | \grep -e "^unstable -> $EXPECTED_STABLE (-> $STABLE_VERSION)$" \ -# || die "nvm alias did not contain the overridden 'unstable' alias" -# -#cleanup -# -} - -@test './Aliases/Running "nvm alias" should list all aliases.' { -##!/bin/sh -# -#. ../../../nvm.sh -# -#die () { echo $@ ; exit 1; } -# -#NVM_ALIAS_OUTPUT=$(nvm alias) -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-1 -> 0.0.1 (-> v0.0.1)$' \ -# || die "did not find test-stable-1 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-2 -> 0.0.2 (-> v0.0.2)$' \ -# || die "did not find test-stable-2 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-3 -> 0.0.3 (-> v0.0.3)$' \ -# || die "did not find test-stable-3 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-4 -> 0.0.4 (-> v0.0.4)$' \ -# || die "did not find test-stable-4 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-5 -> 0.0.5 (-> v0.0.5)$' \ -# || die "did not find test-stable-5 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-6 -> 0.0.6 (-> v0.0.6)$' \ -# || die "did not find test-stable-6 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-7 -> 0.0.7 (-> v0.0.7)$' \ -# || die "did not find test-stable-7 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-8 -> 0.0.8 (-> v0.0.8)$' \ -# || die "did not find test-stable-8 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-9 -> 0.0.9 (-> v0.0.9)$' \ -# || die "did not find test-stable-9 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-stable-10 -> 0.0.10 (-> v0.0.10)$' \ -# || die "did not find test-stable-10 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-1 -> 0.1.1 (-> v0.1.1)$' \ -# || die "did not find test-unstable-1 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-2 -> 0.1.2 (-> v0.1.2)$' \ -# || die "did not find test-unstable-2 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-3 -> 0.1.3 (-> v0.1.3)$' \ -# || die "did not find test-unstable-3 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-4 -> 0.1.4 (-> v0.1.4)$' \ -# || die "did not find test-unstable-4 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-5 -> 0.1.5 (-> v0.1.5)$' \ -# || die "did not find test-unstable-5 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-6 -> 0.1.6 (-> v0.1.6)$' \ -# || die "did not find test-unstable-6 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-7 -> 0.1.7 (-> v0.1.7)$' \ -# || die "did not find test-unstable-7 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-8 -> 0.1.8 (-> v0.1.8)$' \ -# || die "did not find test-unstable-8 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-9 -> 0.1.9 (-> v0.1.9)$' \ -# || die "did not find test-unstable-9 alias" -#echo "$NVM_ALIAS_OUTPUT" | \grep -e '^test-unstable-10 -> 0.1.10 (-> v0.1.10)$' \ -# || die "did not find test-unstable-10 alias" -# -} - -@test './Aliases/setup' { -##!/bin/sh -# -#for i in $(seq 1 10) -# do -# echo 0.0.$i > ../../../alias/test-stable-$i -# mkdir -p ../../../v0.0.$i -# echo 0.1.$i > ../../../alias/test-unstable-$i -# mkdir -p ../../../v0.1.$i -#done -} - -@test './Aliases/teardown' { -##!/bin/sh -# -#for i in $(seq 1 10) -# do -# rm -f "../../../alias/test-stable-$i" -# rm -rf "../../../v0.0.$i" -# rm -f "../../../alias/test-unstable-$i" -# rm -rf "../../../v0.1.$i" -#done -# -#rm -f "../../../alias/stable" -#rm -f "../../../alias/unstable" -# -} - -@test './Listing versions/Running "nvm ls 0.0.2" should display only version 0.0.2.' { -##!/bin/sh -# -#mkdir ../../../v0.0.2 -#mkdir ../../../v0.0.20 -# -#. ../../../nvm.sh -# -#die () { echo $@ ; exit 1; } -# -## The result should contain only the appropriate version numbers. -# -#nvm ls 0.0.2 | grep 'v0.0.2' > /dev/null -#if [ $? -eq 0 ]; then -# echo '"nvm ls 0.0.2" contained v0.0.2' -#fi -# -#nvm ls 0.0.2 | grep 'v0.0.20' > /dev/null -#if [ $? -eq 0 ]; then -# die '"nvm ls 0.0.2" contained v0.0.20' -#fi -# -} - -@test './Listing versions/Running "nvm ls 0.2" should display only 0.2.x versions.' { -##!/bin/sh -# -#mkdir ../../../v0.1.3 -#mkdir ../../../v0.2.3 -#mkdir ../../../v0.20.3 -# -#. ../../../nvm.sh -# -#die () { echo $@ ; exit 1; } -# -## The result should contain only the appropriate version numbers. -# -#nvm ls 0.1 | grep 'v0.2.3' > /dev/null -#if [ $? -eq 0 ]; then -# echo '"nvm ls 0.1" contained v0.2.3' -#fi -# -#nvm ls 0.1 | grep 'v0.20.3' > /dev/null -#if [ $? -eq 0 ]; then -# die '"nvm ls 0.1" contained v0.20.3' -#fi -# -#nvm ls 0.1 | grep 'v0.1.3' > /dev/null -#if [ $? -ne 0 ]; then -# die '"nvm ls 0.1" did not contain v0.1.3' -#fi -# -#nvm ls 0.2 | grep 'v0.2.3' > /dev/null -#if [ $? -ne 0 ]; then -# die '"nvm ls 0.2" did not contain v0.2.3' -#fi -# -#nvm ls 0.2 | grep 'v0.20.3' > /dev/null -#if [ $? -eq 0 ]; then -# die '"nvm ls 0.2" contained v0.20.3' -#fi -# -#nvm ls 0.2 | grep 'v0.2.3' > /dev/null -#if [ $? -ne 0 ]; then -# die '"nvm ls 0.2" did not contain v0.2.3' -#fi -} - -@test './Listing versions/Running "nvm ls foo" should return a nonzero exit code when not found' { -# #!/bin/sh -# -#. ../../../nvm.sh -# -#nvm ls nonexistent_version -#[ "$?" = "3" ] -# -} - -@test './Listing versions/Running "nvm ls node" should return a nonzero exit code when not found' { -# #!/bin/sh -# -#. ../../../nvm.sh -# -#nvm ls node -#[ "$?" = "3" ] -# -} - -@test './Listing versions/Running "nvm ls stable" and "nvm ls unstable" should return the appropriate implicit alias' { -# #!/bin/sh -# -#. ../../../nvm.sh -# -#die () { echo $@ ; exit 1; } -# -#mkdir ../../../v0.2.3 -#mkdir ../../../v0.3.3 -# -#EXPECTED_STABLE="$(nvm_print_implicit_alias local stable)" -#STABLE_VERSION="$(nvm_version "$EXPECTED_STABLE")" -# -#EXPECTED_UNSTABLE="$(nvm_print_implicit_alias local unstable)" -#UNSTABLE_VERSION="$(nvm_version "$EXPECTED_UNSTABLE")" -# -#nvm ls stable | \grep "$STABLE_VERSION" >/dev/null \ -# || die "expected 'nvm ls stable' to give $STABLE_VERSION, got $(nvm ls stable)" -# -#nvm ls unstable | \grep "$UNSTABLE_VERSION" >/dev/null \ -# || die "expected 'nvm ls unstable' to give $UNSTABLE_VERSION, got $(nvm ls unstable)" -# -#mkdir ../../../v0.1.2 -#nvm alias stable 0.1 -# -#nvm ls stable | \grep -v "$STABLE_VERSION" >/dev/null \ -# || die "'nvm ls stable' contained $STABLE_VERSION instead of v0.1.2" -#nvm ls stable | \grep v0.1.2 >/dev/null \ -# || die "'nvm ls stable' did not contain v0.1.2" -# -} - -@test './Listing versions/Running "nvm ls system" should include "system" when appropriate' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#mkdir -p ../../../v0.0.1 -#mkdir -p ../../../v0.0.3 -#mkdir -p ../../../v0.0.9 -#mkdir -p ../../../v0.3.1 -#mkdir -p ../../../v0.3.3 -#mkdir -p ../../../v0.3.9 -# -#nvm_has_system_node() { return 0; } -#nvm ls system | grep system 2>&1 > /dev/null -#[ $? -eq 0 ] || die '"nvm ls system" did not contain "system" when system node is present' -# -#nvm_has_system_node() { return 1; } -#nvm ls system | grep system 2>&1 > /dev/null -#[ $? -ne 0 ] || die '"nvm ls system" contained "system" when system node is not present' -# -} - -@test './Listing versions/Running "nvm ls" should display all installed versions.' { -##!/bin/sh -# -#. ../../../nvm.sh -# -#mkdir ../../../v0.0.1 -#mkdir ../../../v0.0.3 -#mkdir ../../../v0.0.9 -#mkdir ../../../v0.3.1 -#mkdir ../../../v0.3.3 -#mkdir ../../../v0.3.9 -# -## The result should contain the version numbers. -#nvm ls | grep v0.0.1 && -#nvm ls | grep v0.0.3 && -#nvm ls | grep v0.0.9 && -#nvm ls | grep v0.3.1 && -#nvm ls | grep v0.3.3 && -#nvm ls | grep v0.3.9 -} - -@test './Listing versions/Running "nvm ls" should filter out ".nvm"' { -##!/bin/sh -# -#mkdir ../../../v0.1.3 -#mkdir ../../../v0.2.3 -# -#. ../../../nvm.sh -# -#[ -z `nvm ls | grep '^ *\.'` ] -## The result should contain only the appropriate version numbers. -} - -@test './Listing versions/Running "nvm ls" should filter out "versions"' { -##!/bin/sh -# -#mkdir ../../../v0.1.3 -#mkdir ../../../v0.2.3 -#mkdir ../../../versions -# -#. ../../../nvm.sh -# -#[ -z "$(nvm ls | \grep 'versions')" ] -## The result should contain only the appropriate version numbers. -# -} - -@test './Listing versions/Running "nvm ls" should include "system" when appropriate' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#mkdir -p ../../../v0.0.1 -#mkdir -p ../../../v0.0.3 -#mkdir -p ../../../v0.0.9 -#mkdir -p ../../../v0.3.1 -#mkdir -p ../../../v0.3.3 -#mkdir -p ../../../v0.3.9 -# -#nvm_has_system_node() { return 0; } -#nvm ls | grep system 2>&1 > /dev/null -#[ $? -eq 0 ] || die '"nvm ls" did not contain "system" when system node is present' -# -#nvm_has_system_node() { return 1; } -#nvm ls | grep system 2>&1 > /dev/null -#[ $? -ne 0 ] || die '"nvm ls" contained "system" when system node is not present' -# -} - -@test './Listing versions/Running "nvm ls" should list versions in the "versions" directory' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#mkdir -p ../../../versions/v0.12.1 -#mkdir ../../../v0.1.3 -# -#. ../../../nvm.sh -# -#nvm ls 0.12 | grep v0.12.1 || die '"nvm ls" did not list a version in the versions/ directory' -#nvm ls 0.1 | grep v0.1.3 || die '"nvm ls" did not list a version not in the versions/ directory' -# -} - -@test './Listing versions/Running "nvm ls" with node-like versioning vx.x.x should only list a matched version' { -##!/bin/sh -# -#mkdir ../../../v0.1.2 -# -#. ../../../nvm.sh -# -#nvm ls v0.1 | grep v0.1.2 && -#nvm ls v0.1.2 | grep v0.1.2 && -#nvm ls v0.1. | grep v0.1.2 && -#nvm ls v0.1.1 | grep N/A -# -} - -@test './Listing versions/teardown' { -#rmdir ../../../v0.0.1 >/dev/null 2>&1 -#rmdir ../../../v0.0.2 >/dev/null 2>&1 -#rmdir ../../../v0.0.3 >/dev/null 2>&1 -#rmdir ../../../v0.0.9 >/dev/null 2>&1 -#rmdir ../../../v0.0.20 >/dev/null 2>&1 -#rmdir ../../../v0.1.2 >/dev/null 2>&1 -#rmdir ../../../v0.1.3 >/dev/null 2>&1 -#rmdir ../../../v0.2.3 >/dev/null 2>&1 -#rmdir ../../../v0.3.1 >/dev/null 2>&1 -#rmdir ../../../v0.3.3 >/dev/null 2>&1 -#rmdir ../../../v0.3.9 >/dev/null 2>&1 -#rmdir ../../../v0.20.3 >/dev/null 2>&1 -#rmdir ../../../versions >/dev/null 2>&1 -#unalias nvm_has_system_node >/dev/null 2>&1 -#rm -f ../../../alias/stable >/dev/null 2>&1 -#rm -f ../../../alias/unstable >/dev/null 2>&1 -# -} - -@test './Running "nvm alias" should create a file in the alias directory.' { -##!/bin/sh -# -#. ../../nvm.sh -#nvm alias test v0.1.2 -#[ "$(cat ../../alias/test)" = "v0.1.2" ] -} - -@test './Running "nvm current" should display current nvm environment.' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../nvm.sh -# -#nvm deactivate 2>&1 -# -#[ "$(nvm current)" = "system" ] || [ "$(nvm current)" = "none" ] || die '"nvm current" did not report "system" or "none" when deactivated' -# -} - -@test './Running "nvm deactivate" should unset the nvm environment variables.' { -##!/bin/sh -# -#mkdir -p ../../v0.2.3 -# -#die () { echo $@ ; exit 1; } -# -#[ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] || echo "WARNING: Unexpectedly found v0.2.3 already active" >&2 -# -#. ../../nvm.sh -#nvm use v0.2.3 || die "Failed to activate v0.2.3" -#[ `expr "$PATH" : ".*v0.2.3/.*/bin"` != 0 ] || die "PATH not set up properly" -#[ `expr "$NODE_PATH" : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "NODE_PATH should not contain (npm root -g)" -## ^ note: NODE_PATH should not contain `npm root -g` since globals should not be requireable -# -#nvm deactivate || die "Failed to deactivate v0.2.3" -#[ `expr "$PATH" : ".*v0.2.3/.*/bin"` = 0 ] || die "PATH not cleaned properly" -#[ `expr "$NODE_PATH" : ".*v0.2.3/.*/lib/node_modules"` = 0 ] || die "NODE_PATH not cleaned properly" -} - -@test './Running "nvm install" with "--reinstall-packages-from" requires a valid version' { -##!/bin/sh -# -#die () { echo $@ ; cleanup ; exit 1; } -#cleanup () { -# rm -rf ../../v0.10.4 -#} -# -#mkdir ../../v0.10.4 -# -#. ../../nvm.sh -# -#nvm deactivate >/dev/null 2>&1 -# -#INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from=0.11 2>&1)" -#EXPECTED_ERROR_MSG="If --reinstall-packages-from is provided, it must point to an installed version of node." -#[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \ -# || die ""nvm install --reinstall-packages-from" should fail when given an uninstalled version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'" -# -#INSTALL_EXIT_CODE="$(nvm install v0.10.5 --reinstall-packages-from=0.11 >/dev/null 2>&1; echo $?)" -#[ "~$INSTALL_EXIT_CODE" = "~5" ] \ -# || die ""nvm install --reinstall-packages-from" should exit with code 5 when given an uninstalled version, got $INSTALL_EXIT_CODE" -# -#INSTALL_ERROR_MSG="$(nvm install v0.10.5 --reinstall-packages-from=0.10.5 2>&1)" -#EXPECTED_ERROR_MSG="You can't reinstall global packages from the same version of node you're installing." -#[ "~$INSTALL_ERROR_MSG" = "~$EXPECTED_ERROR_MSG" ] \ -# || die ""nvm install --reinstall-packages-from" should fail when given the same version: expected '$EXPECTED_ERROR_MSG', got '$INSTALL_ERROR_MSG'" -# -#INSTALL_EXIT_CODE="$(nvm install v0.10.5 --reinstall-packages-from=0.10.5 >/dev/null 2>&1; echo $?)" -#[ "~$INSTALL_EXIT_CODE" = "~4" ] \ -# || die ""nvm install --reinstall-packages-from" should exit with code 4 when given the same version, got $INSTALL_EXIT_CODE" -# -} - -@test './Running "nvm install" with an invalid version fails nicely' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../nvm.sh -#[ "$(nvm install invalid.invalid 2>&1)" = "Version 'invalid.invalid' not found - try \`nvm ls-remote\` to browse available versions." ] || die "nvm installing an invalid version did not print a nice error message" -# -} - -@test './Running "nvm unalias" should remove the alias file.' { -##!/bin/sh -# -#echo v0.1.2 > ../../alias/test -#. ../../nvm.sh -#nvm unalias test -#! [ -e ../../alias/test ] -} - -@test './Running "nvm uninstall" should remove the appropriate directory.' { -##!/bin/sh -# -#cd ../.. -#mkdir v0.0.1 -#mkdir src/node-v0.0.1 -# -#. ./nvm.sh -#nvm uninstall v0.0.1 -# -#[ ! -d 'v0.0.1' ] && [ ! -d 'src/node-v0.0.1' ] -} - -@test './Running "nvm unload" should unset all function and variables.' { -##!/bin/sh -# -#fail () { echo $@ ; exit 1; } -# -#. ../../nvm.sh -# -#type nvm > /dev/null 2>&1 || fail "NVM not loaded" -# -#nvm unload -# -#type nvm > /dev/null 2>&1 && fail "NVM not unloaded" || exit 0 -# -} - -@test './Running "nvm use foo" where "foo" is circular aborts' { -##!/bin/sh -# -#die () { echo $@ ; cleanup ; exit 1; } -# -#cleanup() { -# rm -rf ../../alias/foo -#} -# -#. ../../nvm.sh -# -#echo 'foo' > ../../alias/foo -# -#OUTPUT="$(nvm use foo 2>&1)" -#EXPECTED_OUTPUT='The alias "foo" leads to an infinite loop. Aborting.' -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] \ -# || die "'nvm use foo' did not output '$EXPECTED_OUTPUT'; got '$OUTPUT'" -# -#EXIT_CODE="$(nvm use foo 2>/dev/null ; echo $?)" -#[ "_$EXIT_CODE" = "_8" ] || die "Expected exit code 8; got $EXIT_CODE" -# -#cleanup; -# -} - -@test './Running "nvm use system" should work as expected' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../nvm.sh -# -#nvm_has_system_node() { return 0; } -#[ "$(nvm use system 2>&1 | tail -n1)" = "Now using system version of node: $(node -v)." ] || die "Could not use system version of node" -# -#nvm_has_system_node() { return 1; } -#[ "$(nvm use system 2>&1 | tail -n1)" = "System version of node not found." ] || die "Did not report error, system node not found" -#nvm use system 2>&1 > /dev/null || [ $? -eq 127 ] || die "Did not return error code, system node not found" -# -} - -@test './Running "nvm use x" should create and change the "current" symlink' { -##!/bin/bash -# -#export NVM_SYMLINK_CURRENT=true -#. ../../nvm.sh -# -#rm -rf ../../v0.10.29 -#mkdir ../../v0.10.29 -#nvm use 0.10.29 -#rmdir ../../v0.10.29 -# -#if [ ! -L ../../current ];then -# echo "Expected 'current' symlink to be created!" -# exit 1 -#fi -# -#oldLink="$(readlink ../../current)" -# -#if [ "$(basename $oldLink)" != 'v0.10.29' ];then -# echo "Expected 'current' to point to v0.10.29 but was $oldLink" -# exit 1 -#fi -# -#rm -rf ../../v0.11.13 -#mkdir ../../v0.11.13 -#nvm use 0.11.13 -#rmdir ../../v0.11.13 -# -#newLink="$(readlink ../../current)" -# -#if [ "$(basename $newLink)" != 'v0.11.13' ];then -# echo "Expected 'current' to point to v0.11.13 but was $newLink" -# exit 1 -#fi -} - -@test './Running "nvm use x" should not create the "current" symlink if $NVM_SYMLINK_CURRENT is false' { -##!/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 2>&1 -# rmdir ../../${TEST_NODE_VERSION} -#} -# -#function isCurrentSymlinkPresent() { -# [ -L ../../current ] -#} -# -#NVM_SYMLINK_CURRENT=false -#cleanup -#runNvmUse -#isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=false!" -#registerExpectedNoSymlink $? -# -#NVM_SYMLINK_CURRENT=true -#cleanup -#runNvmUse -#isCurrentSymlinkPresent || echo >&2 "Expected 'current' symlink to be created when NVM_SYMLINK_CURRENT=true!" -#registerExpectedSymlink $? -# -#NVM_SYMLINK_CURRENT=garbagevalue -#cleanup -#runNvmUse -#isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT contains a string!" -#registerExpectedNoSymlink $? -# -#NVM_SYMLINK_CURRENT=0 -#cleanup -#runNvmUse -#isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=0!" -#registerExpectedNoSymlink $? -# -#NVM_SYMLINK_CURRENT=1 -#cleanup -#runNvmUse -#isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT=1!" -#registerExpectedNoSymlink $? -# -#unset NVM_SYMLINK_CURRENT -#cleanup -#runNvmUse -#isCurrentSymlinkPresent && echo >&2 "Expected 'current' symlink not to be created when NVM_SYMLINK_CURRENT has been unset (default behaviour)!" -#registerExpectedNoSymlink $? -# -#cleanup -# -#[ ${TEST_FAILED} -ne 0 ] && echo "${TEST_COUNT} tested, ${TEST_PASSED} passed, ${TEST_FAILED} failed" && exit 1 || true -# -} - -@test './setup' { -##!/bin/sh -# -#( -# cd ../.. -# -# # Back up -# -# type setopt >/dev/null 2>&1 && setopt NULL_GLOB -# type shopt >/dev/null 2>&1 && shopt -s nullglob -# rm -Rf v* src alias -# mkdir src alias -#) -} - -@test './setup_dir' { -##!/bin/sh -# -#( -# cd ../.. -# -# # Back up -# -# mkdir -p bak -# for SRC in v* src alias; do -# [ -e "$SRC" ] && mv "$SRC" bak -# done -# if [ -d versions ]; then -# mv versions bak -# fi -# true -#) -} - -@test './Sourcing nvm.sh should make the nvm command available.' { -##!/bin/sh -# -#. ../../nvm.sh -#nvm -} - -@test './teardown' { -##!/bin/sh -# -## Remove temporary files -#( -# cd ../.. -# -# type setopt >/dev/null 2>&1 && setopt NULL_GLOB -# type shopt >/dev/null 2>&1 && shopt -s nullglob -# rm -fR v* src alias -#) -} - -@test './teardown_dir' { -##!/bin/sh -# -#( -# cd ../.. -# -# # Restore -# if [ -d bak ] -# then -# mv bak/* . > /dev/null 2>&1 || sleep 0s -# rmdir bak -# fi -# mkdir -p src alias -#) -} - @test './Unit tests/nvm_alias' { ##!/bin/sh # From ea6a87939b9bda6af09cc4a0c4ad6ef600dc70f3 Mon Sep 17 00:00:00 2001 From: smikes Date: Sun, 21 Dec 2014 16:07:08 -0700 Subject: [PATCH 19/21] partial port first unit test --- test/bats/unit-tests.bats | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/bats/unit-tests.bats b/test/bats/unit-tests.bats index 8a751de..daa202c 100644 --- a/test/bats/unit-tests.bats +++ b/test/bats/unit-tests.bats @@ -31,6 +31,10 @@ teardown() { } @test './Unit tests/nvm_alias' { + + run nvm_alias + assert_equal 1 "$status" "nvm_alias should exit with code 1" + assert_match "$output" "An alias is required." ##!/bin/sh # #die () { echo $@ ; cleanup ; exit 1; } @@ -43,7 +47,7 @@ teardown() { # #OUTPUT="$(nvm_alias 2>&1)" #EXPECTED_OUTPUT='An alias is required.' -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_alias' produced wrong output; got $OUTPUT" +#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die " # #EXIT_CODE="$(nvm_alias >/dev/null 2>&1 ; echo $?)" #[ "_$EXIT_CODE" = "_1" ] || die "'nvm_alias' exited with $EXIT_CODE, expected 1" From edebb311194eef8e762da1c6f21d66bc6f65fabe Mon Sep 17 00:00:00 2001 From: smikes Date: Tue, 23 Dec 2014 14:41:55 -0700 Subject: [PATCH 20/21] finished unit tests --- test/bats/unit-tests.bats | 1190 +++++++++--------------------------- test/fixtures/download.txt | 430 +++++++++++++ 2 files changed, 726 insertions(+), 894 deletions(-) create mode 100644 test/fixtures/download.txt diff --git a/test/bats/unit-tests.bats b/test/bats/unit-tests.bats index daa202c..1a070d1 100644 --- a/test/bats/unit-tests.bats +++ b/test/bats/unit-tests.bats @@ -5,12 +5,14 @@ load test_helper NVM_SRC_DIR="${BATS_TEST_DIRNAME}/../.." source "${NVM_SRC_DIR}/nvm.sh" +FIXTURES_DIR="${NVM_SRC_DIR}/test/fixtures" + test_debug() { false # set to 'true' to get setup/teardown in test stderr } test_implementing() { - true # set to 'false' to run all tests; set to 'true' to skip implemented tests + false # set to 'false' to run all tests; set to 'true' to skip implemented tests # only used while porting to bats: remove afterward } @@ -31,955 +33,355 @@ teardown() { } @test './Unit tests/nvm_alias' { + test_implementing && skip run nvm_alias - assert_equal 1 "$status" "nvm_alias should exit with code 1" + assert_equal 1 "$status" "nvm_alias should exit with code 1 for missing" assert_match "$output" "An alias is required." -##!/bin/sh -# -#die () { echo $@ ; cleanup ; exit 1; } -# -#cleanup () { -# rm -rf ../../../alias/test -#} -# -#. ../../../nvm.sh -# -#OUTPUT="$(nvm_alias 2>&1)" -#EXPECTED_OUTPUT='An alias is required.' -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die " -# -#EXIT_CODE="$(nvm_alias >/dev/null 2>&1 ; echo $?)" -#[ "_$EXIT_CODE" = "_1" ] || die "'nvm_alias' exited with $EXIT_CODE, expected 1" -# -#rm -rf ../../../alias/nonexistent -# -#OUTPUT="$(nvm_alias nonexistent 2>&1)" -#EXPECTED_OUTPUT='Alias does not exist.' -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_alias nonexistent' produced wrong output; got $OUTPUT" -# -#EXIT_CODE="$(nvm_alias nonexistent >/dev/null 2>&1 ; echo $?)" -#[ "_$EXIT_CODE" = "_2" ] || die "'nvm_alias nonexistent' exited with $EXIT_CODE, expected 2" -# -#EXPECTED_OUTPUT="0.10" -#nvm alias test "$EXPECTED_OUTPUT" || die "'nvm alias test $EXPECTED_OUTPUT' failed" -#OUTPUT="$(nvm_alias test)" -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "'nvm_alias test' produced wrong output; got $OUTPUT" -# -#cleanup -# + + run nvm_alias nonexistent + assert_equal 2 "$status" "nvm_alias should exit with code 2 for nonexistent" + assert_match "$output" "Alias does not exist." + + run nvm alias test "0.10" + run nvm_alias test + assert_match "$output" "0.10" "nvm_alias test produced wrong output" } @test './Unit tests/nvm_checksum' { -##!/bin/sh -# -#cleanup () { -# rm tmp/emptyfile tmp/testfile -# rmdir tmp -#} -#die () { echo $@ ; cleanup; exit 1; } -# -#. ../../../nvm.sh -# -#mkdir -p tmp -#touch tmp/emptyfile -#echo -n "test" > tmp/testfile -# -#nvm_checksum tmp/emptyfile "da39a3ee5e6b4b0d3255bfef95601890afd80709" || die "nvm_checksum on an empty file did not match the SHA1 digest of the empty string" -#nvm_checksum tmp/testfile "da39a3ee5e6b4b0d3255bfef95601890afd80709" && die "nvm_checksum allowed a bad checksum" -# -#cleanup + test_implementing && skip + + mkdir -p tmp + touch tmp/emptyfile + echo -n "test" > tmp/testfile + + run nvm_checksum tmp/emptyfile "da39a3ee5e6b4b0d3255bfef95601890afd80709" + assert_equal 0 "$status" "nvm_checksum on empty file did not match SHA1 of empty string" + + run nvm_checksum tmp/testfile "da39a3ee5e6b4b0d3255bfef95601890afd80709" + assert_equal 1 "$status" "nvm_checksum allowed a bad checksum" } @test './Unit tests/nvm_find_up' { -##!/bin/sh -# -#die () { echo $@ ; cleanup ; exit 1; } -#setup() { -# cleanup -# mkdir -p tmp_nvm_find_up/a/b/c/d -# touch tmp_nvm_find_up/test -# touch tmp_nvm_find_up/a/b/c/test -#} -#cleanup () { -# rm -rf tmp_nvm_find_up -#} -# -#. ../../../nvm.sh -# -#setup -# -#TEST_DIR="$PWD" -# -#[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up" ] || die "failed to find 1 dir up" -#[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up" ] || die "failed to find 2 dirs up" -#[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b/c nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up/a/b/c" ] || die "failed to find in current dir" -#[ "~$(PWD=$TEST_DIR/tmp_nvm_find_up/a/b/c/d nvm_find_up 'test')" = "~$TEST_DIR/tmp_nvm_find_up/a/b/c" ] || die "failed to find 1 level up from current dir" -# -#cleanup -# + test_implementing && skip + + mkdir -p tmp_nvm_find_up/a/b/c/d + touch tmp_nvm_find_up/test + touch tmp_nvm_find_up/a/b/c/test + + output="$(PWD=${PWD}/tmp_nvm_find_up/a nvm_find_up 'test')" + assert_equal "${PWD}/tmp_nvm_find_up" "$output" "failed to find 1 dir up" + + output="$(PWD=${PWD}/tmp_nvm_find_up/a/b nvm_find_up 'test')" + assert_equal "${PWD}/tmp_nvm_find_up" "$output" "failed to find 2 dirs up" + + output="$(PWD=${PWD}/tmp_nvm_find_up/a/b/c nvm_find_up 'test')" + assert_equal "${PWD}/tmp_nvm_find_up/a/b/c" "$output" "failed to find in current dir" + + output="$(PWD=${PWD}/tmp_nvm_find_up/a/b/c/d nvm_find_up 'test')" + assert_equal "${PWD}/tmp_nvm_find_up/a/b/c" "$output" "failed to find 1 up from current dir" + } @test './Unit tests/nvm_format_version' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#OUTPUT="$(nvm_format_version 0.1.2)" -#EXPECTED_OUTPUT="v0.1.2" -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_format_version 0.1.2 did not return $EXPECTED_OUTPUT; got $OUTPUT" -# -#OUTPUT="$(nvm_format_version 0.1)" -#EXPECTED_OUTPUT="v0.1.0" -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_format_version 0.1.0 did not return $EXPECTED_OUTPUT; got $OUTPUT" -# + test_implementing && skip + + run nvm_format_version 0.1.2 + assert_equal "v0.1.2" "$output" + + run nvm_format_version 0.1 + assert_equal "v0.1.0" "$output" } @test './Unit tests/nvm_has' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#nvm_has cat && type cat > /dev/null || die 'nvm_has locates "cat" properly' -# -#[ "~$(nvm_has foobarbaz 2>&1)" = "~" ] || die "nvm_has does not suppress error output" -# -#! nvm_has foobarbaz && ! type foobarbaz >/dev/null 2>&1 || die "nvm_has does not return a nonzero exit code when not found" -# + test_implementing && skip + + nvm_has cat + type cat + + ! nvm_has foobarbaz + ! type foobarbaz } @test './Unit tests/nvm_has_system_node' { -##!/bin/sh -# -#cleanup () { -# rm ../../../v0.1.2/node -# rmdir ../../../v0.1.2 -#} -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#mkdir ../../../v0.1.2 -#touch ../../../v0.1.2/node -# -#nvm use 0.1.2 -# -#if command -v node; then -# nvm_has_system_node -#else -# ! nvm_has_system_node -#fi -# -#nvm deactivate /dev/null 2>&1 -# -#if command -v node; then -# nvm_has_system_node -#else -# ! nvm_has_system_node -#fi -# + test_implementing && skip + + mkdir v0.1.2 + touch v0.1.2/node + + nvm use 0.1.2 + + if command -v node; then + nvm_has_system_node + else + ! nvm_has_system_node + fi + + nvm deactivate + + if command -v node; then + nvm_has_system_node + else + ! nvm_has_system_node + fi } @test './Unit tests/nvm_ls_current' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#return_zero () { return 0; } -# -#[ "$(nvm deactivate > /dev/null 2>&1 ; nvm_ls_current)" = "system" ] || die 'when deactivated, did not return "system"' -# -#TEST_PWD=$(pwd) -#TEST_DIR="$TEST_PWD/nvm_ls_current_tmp" -#rm -rf "$TEST_DIR" -#mkdir "$TEST_DIR" -#ln -s "$(which which)" "$TEST_DIR/which" -#ln -s "$(which dirname)" "$TEST_DIR/dirname" -# -#[ "$(PATH="$TEST_DIR" nvm_ls_current)" = "none" ] || die 'when node not installed, nvm_ls_current did not return "none"' -#[ "@$(PATH="$TEST_DIR" nvm_ls_current 2> /dev/stdout 1> /dev/null)@" = "@@" ] || die 'when node not installed, nvm_ls_current returned error output' -# -#echo "#!/bin/bash" > "$TEST_DIR/node" -#echo "echo 'VERSION FOO!'" > "$TEST_DIR/node" -#chmod a+x "$TEST_DIR/node" -# -#[ "$(alias nvm_tree_contains_path='return_zero' && PATH="$TEST_DIR" nvm_ls_current)" = "VERSION FOO!" ] || die 'when activated, did not return nvm node version' -# -#rm -rf "$TEST_DIR" -# + test_implementing && skip + + nvm deactivate + run nvm_ls_current + assert_match "$output" "system" "when deactivated did not return 'system'" + + rm -fr nvm_ls_current_tmp + mkdir -p nvm_ls_current_tmp + TDIR="${PWD}/nvm_ls_current_tmp" + + ln -s "$(which which)" "$TDIR/which" + ln -s "$(which dirname)" "$TDIR/dirname" + + output="$(PATH=${TDIR} nvm_ls_current || true)" + assert_match "$output" "none" "when node not installed, nvm_ls_current should return 'none'" + + echo "#!/bin/bash" > node + echo "echo 'VERSION FOO!'" >> node + chmod a+x node + + nvm_tree_contains_path() { + return 0 + } + output="$(PATH=${TDIR} nvm_ls_current || true)" + assert_match "$output" "none" "when activated 'nvm_ls_current' should return 'noe'" } @test './Unit tests/nvm_ls_remote' { -##!/bin/sh -# -#die () { echo $@ ; cleanup ; exit 1; } -# -#cleanup() { -# unset -f nvm_download -#} -# -#. ../../../nvm.sh -# -## sample output at the time the test was written -#nvm_download() { -# echo 'foo "v0.10.0' -# echo 'foo "v0.10.0' -# echo 'foo "v0.10.1' -# echo 'foo "v0.10.1' -# echo 'foo "v0.10.10' -# echo 'foo "v0.10.10' -# echo 'foo "v0.10.11' -# echo 'foo "v0.10.11' -# echo 'foo "v0.10.12' -# echo 'foo "v0.10.12' -# echo 'foo "v0.10.13' -# echo 'foo "v0.10.13' -# echo 'foo "v0.10.14' -# echo 'foo "v0.10.14' -# echo 'foo "v0.10.15' -# echo 'foo "v0.10.15' -# echo 'foo "v0.10.16' -# echo 'foo "v0.10.16' -# echo 'foo "v0.10.16' -# echo 'foo "v0.10.16' -# echo 'foo "v0.10.17' -# echo 'foo "v0.10.17' -# echo 'foo "v0.10.18' -# echo 'foo "v0.10.18' -# echo 'foo "v0.10.19' -# echo 'foo "v0.10.19' -# echo 'foo "v0.10.2' -# echo 'foo "v0.10.2' -# echo 'foo "v0.10.20' -# echo 'foo "v0.10.20' -# echo 'foo "v0.10.21' -# echo 'foo "v0.10.21' -# echo 'foo "v0.10.22' -# echo 'foo "v0.10.22' -# echo 'foo "v0.10.23' -# echo 'foo "v0.10.23' -# echo 'foo "v0.10.24' -# echo 'foo "v0.10.24' -# echo 'foo "v0.10.25' -# echo 'foo "v0.10.25' -# echo 'foo "v0.10.26' -# echo 'foo "v0.10.26' -# echo 'foo "v0.10.27' -# echo 'foo "v0.10.27' -# echo 'foo "v0.10.28' -# echo 'foo "v0.10.28' -# echo 'foo "v0.10.29' -# echo 'foo "v0.10.29' -# echo 'foo "v0.10.3' -# echo 'foo "v0.10.3' -# echo 'foo "v0.10.30' -# echo 'foo "v0.10.30' -# echo 'foo "v0.10.31' -# echo 'foo "v0.10.31' -# echo 'foo "v0.10.32' -# echo 'foo "v0.10.32' -# echo 'foo "v0.10.4' -# echo 'foo "v0.10.4' -# echo 'foo "v0.10.5' -# echo 'foo "v0.10.5' -# echo 'foo "v0.10.6' -# echo 'foo "v0.10.6' -# echo 'foo "v0.10.7' -# echo 'foo "v0.10.7' -# echo 'foo "v0.10.8' -# echo 'foo "v0.10.8' -# echo 'foo "v0.10.9' -# echo 'foo "v0.10.9' -# echo 'foo "v0.11.0' -# echo 'foo "v0.11.0' -# echo 'foo "v0.11.1' -# echo 'foo "v0.11.1' -# echo 'foo "v0.11.10' -# echo 'foo "v0.11.10' -# echo 'foo "v0.11.11' -# echo 'foo "v0.11.11' -# echo 'foo "v0.11.12' -# echo 'foo "v0.11.12' -# echo 'foo "v0.11.13' -# echo 'foo "v0.11.13' -# echo 'foo "v0.11.14' -# echo 'foo "v0.11.14' -# echo 'foo "v0.11.2' -# echo 'foo "v0.11.2' -# echo 'foo "v0.11.3' -# echo 'foo "v0.11.3' -# echo 'foo "v0.11.4' -# echo 'foo "v0.11.4' -# echo 'foo "v0.11.5' -# echo 'foo "v0.11.5' -# echo 'foo "v0.11.6' -# echo 'foo "v0.11.6' -# echo 'foo "v0.11.7' -# echo 'foo "v0.11.7' -# echo 'foo "v0.11.8' -# echo 'foo "v0.11.8' -# echo 'foo "v0.11.9' -# echo 'foo "v0.11.9' -# echo 'foo "v0.5.1' -# echo 'foo "v0.5.1' -# echo 'foo "v0.5.10' -# echo 'foo "v0.5.10' -# echo 'foo "v0.5.2' -# echo 'foo "v0.5.2' -# echo 'foo "v0.5.3' -# echo 'foo "v0.5.3' -# echo 'foo "v0.5.4' -# echo 'foo "v0.5.4' -# echo 'foo "v0.5.5' -# echo 'foo "v0.5.5' -# echo 'foo "v0.5.6' -# echo 'foo "v0.5.6' -# echo 'foo "v0.5.7' -# echo 'foo "v0.5.7' -# echo 'foo "v0.5.8' -# echo 'foo "v0.5.8' -# echo 'foo "v0.5.9' -# echo 'foo "v0.5.9' -# echo 'foo "v0.6.0' -# echo 'foo "v0.6.0' -# echo 'foo "v0.6.1' -# echo 'foo "v0.6.1' -# echo 'foo "v0.6.10' -# echo 'foo "v0.6.10' -# echo 'foo "v0.6.11' -# echo 'foo "v0.6.11' -# echo 'foo "v0.6.12' -# echo 'foo "v0.6.12' -# echo 'foo "v0.6.13' -# echo 'foo "v0.6.13' -# echo 'foo "v0.6.14' -# echo 'foo "v0.6.14' -# echo 'foo "v0.6.15' -# echo 'foo "v0.6.15' -# echo 'foo "v0.6.16' -# echo 'foo "v0.6.16' -# echo 'foo "v0.6.17' -# echo 'foo "v0.6.17' -# echo 'foo "v0.6.18' -# echo 'foo "v0.6.18' -# echo 'foo "v0.6.19' -# echo 'foo "v0.6.19' -# echo 'foo "v0.6.2' -# echo 'foo "v0.6.2' -# echo 'foo "v0.6.20' -# echo 'foo "v0.6.20' -# echo 'foo "v0.6.21' -# echo 'foo "v0.6.21' -# echo 'foo "v0.6.3' -# echo 'foo "v0.6.3' -# echo 'foo "v0.6.4' -# echo 'foo "v0.6.4' -# echo 'foo "v0.6.5' -# echo 'foo "v0.6.5' -# echo 'foo "v0.6.6' -# echo 'foo "v0.6.6' -# echo 'foo "v0.6.7' -# echo 'foo "v0.6.7' -# echo 'foo "v0.6.8' -# echo 'foo "v0.6.8' -# echo 'foo "v0.6.9' -# echo 'foo "v0.6.9' -# echo 'foo "v0.7.0' -# echo 'foo "v0.7.0' -# echo 'foo "v0.7.1' -# echo 'foo "v0.7.1' -# echo 'foo "v0.7.10' -# echo 'foo "v0.7.10' -# echo 'foo "v0.7.11' -# echo 'foo "v0.7.11' -# echo 'foo "v0.7.12' -# echo 'foo "v0.7.12' -# echo 'foo "v0.7.2' -# echo 'foo "v0.7.2' -# echo 'foo "v0.7.3' -# echo 'foo "v0.7.3' -# echo 'foo "v0.7.4' -# echo 'foo "v0.7.4' -# echo 'foo "v0.7.5' -# echo 'foo "v0.7.5' -# echo 'foo "v0.7.6' -# echo 'foo "v0.7.6' -# echo 'foo "v0.7.7' -# echo 'foo "v0.7.7' -# echo 'foo "v0.7.8' -# echo 'foo "v0.7.8' -# echo 'foo "v0.7.9' -# echo 'foo "v0.7.9' -# echo 'foo "v0.8.0' -# echo 'foo "v0.8.0' -# echo 'foo "v0.8.1' -# echo 'foo "v0.8.1' -# echo 'foo "v0.8.10' -# echo 'foo "v0.8.10' -# echo 'foo "v0.8.11' -# echo 'foo "v0.8.11' -# echo 'foo "v0.8.12' -# echo 'foo "v0.8.12' -# echo 'foo "v0.8.13' -# echo 'foo "v0.8.13' -# echo 'foo "v0.8.14' -# echo 'foo "v0.8.14' -# echo 'foo "v0.8.15' -# echo 'foo "v0.8.15' -# echo 'foo "v0.8.16' -# echo 'foo "v0.8.16' -# echo 'foo "v0.8.17' -# echo 'foo "v0.8.17' -# echo 'foo "v0.8.18' -# echo 'foo "v0.8.18' -# echo 'foo "v0.8.19' -# echo 'foo "v0.8.19' -# echo 'foo "v0.8.2' -# echo 'foo "v0.8.2' -# echo 'foo "v0.8.20' -# echo 'foo "v0.8.20' -# echo 'foo "v0.8.21' -# echo 'foo "v0.8.21' -# echo 'foo "v0.8.22' -# echo 'foo "v0.8.22' -# echo 'foo "v0.8.23' -# echo 'foo "v0.8.23' -# echo 'foo "v0.8.24' -# echo 'foo "v0.8.24' -# echo 'foo "v0.8.25' -# echo 'foo "v0.8.25' -# echo 'foo "v0.8.26' -# echo 'foo "v0.8.26' -# echo 'foo "v0.8.27' -# echo 'foo "v0.8.27' -# echo 'foo "v0.8.28' -# echo 'foo "v0.8.28' -# echo 'foo "v0.8.3' -# echo 'foo "v0.8.3' -# echo 'foo "v0.8.4' -# echo 'foo "v0.8.4' -# echo 'foo "v0.8.5' -# echo 'foo "v0.8.5' -# echo 'foo "v0.8.6' -# echo 'foo "v0.8.6' -# echo 'foo "v0.8.7' -# echo 'foo "v0.8.7' -# echo 'foo "v0.8.8' -# echo 'foo "v0.8.8' -# echo 'foo "v0.8.9' -# echo 'foo "v0.8.9' -# echo 'foo "v0.9.0' -# echo 'foo "v0.9.0' -# echo 'foo "v0.9.1' -# echo 'foo "v0.9.1' -# echo 'foo "v0.9.10' -# echo 'foo "v0.9.10' -# echo 'foo "v0.9.11' -# echo 'foo "v0.9.11' -# echo 'foo "v0.9.12' -# echo 'foo "v0.9.12' -# echo 'foo "v0.9.2' -# echo 'foo "v0.9.2' -# echo 'foo "v0.9.3' -# echo 'foo "v0.9.3' -# echo 'foo "v0.9.4' -# echo 'foo "v0.9.4' -# echo 'foo "v0.9.5' -# echo 'foo "v0.9.5' -# echo 'foo "v0.9.6' -# echo 'foo "v0.9.6' -# echo 'foo "v0.9.7' -# echo 'foo "v0.9.7' -# echo 'foo "v0.9.8' -# echo 'foo "v0.9.8' -# echo 'foo "v0.9.9' -# echo 'foo "v0.9.9' -# echo 'foo "v0.1.100' -# echo 'foo "v0.1.100' -# echo 'foo "v0.1.101' -# echo 'foo "v0.1.101' -# echo 'foo "v0.1.102' -# echo 'foo "v0.1.102' -# echo 'foo "v0.1.103' -# echo 'foo "v0.1.103' -# echo 'foo "v0.1.104' -# echo 'foo "v0.1.104' -# echo 'foo "v0.1.14' -# echo 'foo "v0.1.14' -# echo 'foo "v0.1.15' -# echo 'foo "v0.1.15' -# echo 'foo "v0.1.16' -# echo 'foo "v0.1.16' -# echo 'foo "v0.1.17' -# echo 'foo "v0.1.17' -# echo 'foo "v0.1.18' -# echo 'foo "v0.1.18' -# echo 'foo "v0.1.19' -# echo 'foo "v0.1.19' -# echo 'foo "v0.1.20' -# echo 'foo "v0.1.20' -# echo 'foo "v0.1.21' -# echo 'foo "v0.1.21' -# echo 'foo "v0.1.22' -# echo 'foo "v0.1.22' -# echo 'foo "v0.1.23' -# echo 'foo "v0.1.23' -# echo 'foo "v0.1.24' -# echo 'foo "v0.1.24' -# echo 'foo "v0.1.25' -# echo 'foo "v0.1.25' -# echo 'foo "v0.1.26' -# echo 'foo "v0.1.26' -# echo 'foo "v0.1.27' -# echo 'foo "v0.1.27' -# echo 'foo "v0.1.28' -# echo 'foo "v0.1.28' -# echo 'foo "v0.1.29' -# echo 'foo "v0.1.29' -# echo 'foo "v0.1.30' -# echo 'foo "v0.1.30' -# echo 'foo "v0.1.31' -# echo 'foo "v0.1.31' -# echo 'foo "v0.1.32' -# echo 'foo "v0.1.32' -# echo 'foo "v0.1.33' -# echo 'foo "v0.1.33' -# echo 'foo "v0.1.90' -# echo 'foo "v0.1.90' -# echo 'foo "v0.1.91' -# echo 'foo "v0.1.91' -# echo 'foo "v0.1.92' -# echo 'foo "v0.1.92' -# echo 'foo "v0.1.93' -# echo 'foo "v0.1.93' -# echo 'foo "v0.1.94' -# echo 'foo "v0.1.94' -# echo 'foo "v0.1.95' -# echo 'foo "v0.1.95' -# echo 'foo "v0.1.96' -# echo 'foo "v0.1.96' -# echo 'foo "v0.1.97' -# echo 'foo "v0.1.97' -# echo 'foo "v0.1.98' -# echo 'foo "v0.1.98' -# echo 'foo "v0.1.99' -# echo 'foo "v0.1.99' -# echo 'foo "v0.10.14' -# echo 'foo "v0.10.14' -# echo 'foo "v0.2.0' -# echo 'foo "v0.2.0' -# echo 'foo "v0.2.1' -# echo 'foo "v0.2.1' -# echo 'foo "v0.2.2' -# echo 'foo "v0.2.2' -# echo 'foo "v0.2.3' -# echo 'foo "v0.2.3' -# echo 'foo "v0.2.4' -# echo 'foo "v0.2.4' -# echo 'foo "v0.2.5' -# echo 'foo "v0.2.5' -# echo 'foo "v0.2.6' -# echo 'foo "v0.2.6' -# echo 'foo "v0.3.0' -# echo 'foo "v0.3.0' -# echo 'foo "v0.3.1' -# echo 'foo "v0.3.1' -# echo 'foo "v0.3.2' -# echo 'foo "v0.3.2' -# echo 'foo "v0.3.3' -# echo 'foo "v0.3.3' -# echo 'foo "v0.3.4' -# echo 'foo "v0.3.4' -# echo 'foo "v0.3.5' -# echo 'foo "v0.3.5' -# echo 'foo "v0.3.6' -# echo 'foo "v0.3.6' -# echo 'foo "v0.3.7' -# echo 'foo "v0.3.7' -# echo 'foo "v0.3.8' -# echo 'foo "v0.3.8' -# echo 'foo "v0.4.0' -# echo 'foo "v0.4.0' -# echo 'foo "v0.4.1' -# echo 'foo "v0.4.1' -# echo 'foo "v0.4.10' -# echo 'foo "v0.4.10' -# echo 'foo "v0.4.11' -# echo 'foo "v0.4.11' -# echo 'foo "v0.4.12' -# echo 'foo "v0.4.12' -# echo 'foo "v0.4.2' -# echo 'foo "v0.4.2' -# echo 'foo "v0.4.3' -# echo 'foo "v0.4.3' -# echo 'foo "v0.4.4' -# echo 'foo "v0.4.4' -# echo 'foo "v0.4.5' -# echo 'foo "v0.4.5' -# echo 'foo "v0.4.6' -# echo 'foo "v0.4.6' -# echo 'foo "v0.4.7' -# echo 'foo "v0.4.7' -# echo 'foo "v0.4.8' -# echo 'foo "v0.4.8' -# echo 'foo "v0.4.9' -# echo 'foo "v0.4.9' -# echo 'foo "v0.5.0' -# echo 'foo "v0.5.0' -# echo 'foo "v0.6.1' -# echo 'foo "v0.6.1' -# echo 'foo "v0.6.10' -# echo 'foo "v0.6.10' -# echo 'foo "v0.6.11' -# echo 'foo "v0.6.11' -# echo 'foo "v0.6.12' -# echo 'foo "v0.6.12' -# echo 'foo "v0.6.13' -# echo 'foo "v0.6.13' -# echo 'foo "v0.6.2' -# echo 'foo "v0.6.2' -# echo 'foo "v0.6.3' -# echo 'foo "v0.6.3' -# echo 'foo "v0.6.4' -# echo 'foo "v0.6.4' -# echo 'foo "v0.6.5' -# echo 'foo "v0.6.5' -# echo 'foo "v0.6.6' -# echo 'foo "v0.6.6' -# echo 'foo "v0.6.7' -# echo 'foo "v0.6.7' -# echo 'foo "v0.6.8' -# echo 'foo "v0.6.8' -# echo 'foo "v0.6.9' -# echo 'foo "v0.6.9' -#} -# -#OUTPUT="$(nvm_ls_remote foo)" -#EXIT_CODE="$(nvm_ls_remote foo >/dev/null 2>&1 ; echo $?)" -#[ "_$OUTPUT" = "_N/A" ] || die "nonexistent version did not report N/A" -#[ "_$EXIT_CODE" = "_3" ] || die "nonexistent version did not exit with code 3, got $EXIT_CODE" -# -#OUTPUT="$(nvm_ls_remote)" -#EXPECTED_OUTPUT="$(nvm_download | \egrep -o 'v[0-9]+\.[0-9]+\.[0-9]+' | sort -t. -u -k 1.2,1n -k 2,2n -k 3,3n)" -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "bare nvm_ls_remote did not output expected sorted versions; got $(echo "$OUTPUT") expected $(echo "$EXPECTED_OUTPUT")" -# -#OUTPUT="$(nvm_ls_remote 0.3)" -#EXPECTED_OUTPUT="v0.3.0 -#v0.3.1 -#v0.3.2 -#v0.3.3 -#v0.3.4 -#v0.3.5 -#v0.3.6 -#v0.3.7 -#v0.3.8" -# -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_ls_remote 0.3 did not output 0.3.x versions; got $OUTPUT" -# -## Sanity checks -#OUTPUT="$(nvm_print_implicit_alias remote stable)" -#EXPECTED_OUTPUT="0.10" -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_print_implicit_alias remote stable did not output $EXPECTED_OUTPUT; got $OUTPUT" -# -#OUTPUT="$(nvm_print_implicit_alias remote unstable)" -#EXPECTED_OUTPUT="0.11" -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_print_implicit_alias remote unstable did not output $EXPECTED_OUTPUT; got $OUTPUT" -# -#OUTPUT="$(nvm_ls_remote stable)" -#EXPECTED_OUTPUT="v0.10.32" -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_ls_remote stable did not output $EXPECTED_OUTPUT; got $OUTPUT" -# -#OUTPUT="$(nvm_ls_remote unstable)" -#EXPECTED_OUTPUT="v0.11.14" -#[ "_$OUTPUT" = "_$EXPECTED_OUTPUT" ] || die "nvm_ls_remote unstable did not output $EXPECTED_OUTPUT; got $OUTPUT" -# -#cleanup -# + test_implementing && skip + + nvm_download() { + cat ${FIXTURES_DIR}/download.txt + } + + run nvm_ls_remote foo + assert_equal 3 "$status" + assert_match "N/A" "$output" "nonexistent version should report N/A" + + run nvm_ls_remote + assert_equal 0 "$status" + assert_line 0 "v0.1.14" + assert_line 45 "v0.3.3" + assert_line 199 "v0.11.14" + + run nvm_ls_remote 0.3 + assert_equal 0 "$status" + assert_line 0 "v0.3.0" + assert_line 1 "v0.3.1" + assert_line 2 "v0.3.2" + assert_line 3 "v0.3.3" + assert_line 4 "v0.3.4" + assert_line 5 "v0.3.5" + assert_line 6 "v0.3.6" + assert_line 7 "v0.3.7" + assert_line 8 "v0.3.8" + + run nvm_print_implicit_alias remote stable + assert_match "$output" "0.10" + + run nvm_print_implicit_alias remote unstable + assert_match "$output" "0.11" + + run nvm_ls_remote stable + assert_match "$output" "0.10.32" + + run nvm_ls_remote unstable + assert_match "$output" "0.11.14" } + @test './Unit tests/nvm_num_version_groups' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#[ "~$(nvm_num_version_groups)" = "~0" ] || die "no args should give 0" -#[ "~$(nvm_num_version_groups a)" = "~1" ] || die "one letter should give 1" -# -#[ "~$(nvm_num_version_groups 1)" = "~1" ] || die "1 should give 1" -#[ "~$(nvm_num_version_groups v1)" = "~1" ] || die "v1 should give 1" -#[ "~$(nvm_num_version_groups v1.)" = "~1" ] || die "v1. should give 1" -# -#[ "~$(nvm_num_version_groups 1.2)" = "~2" ] || die "1.2 should give 2" -#[ "~$(nvm_num_version_groups v1.2)" = "~2" ] || die "v1.2 should give 2" -#[ "~$(nvm_num_version_groups v1.2.)" = "~2" ] || die "v1.2. should give 2" -# -#[ "~$(nvm_num_version_groups 1.2.3)" = "~3" ] || die "1.2.3 should give 3" -#[ "~$(nvm_num_version_groups v1.2.3)" = "~3" ] || die "v1.2.3 should give 3" -#[ "~$(nvm_num_version_groups v1.2.3.)" = "~3" ] || die "v1.2.3. should give 3" -# + test_implementing && skip + + assert_equal "0" "$(nvm_num_version_groups)" + + assert_equal "1" "$(nvm_num_version_groups a)" + + assert_equal "1" "$(nvm_num_version_groups 1)" "1 should give 1" + assert_equal "1" "$(nvm_num_version_groups v1)" "v1 should give 1" + assert_equal "1" "$(nvm_num_version_groups v1.)" "v1. should give 1" + + assert_equal "2" "$(nvm_num_version_groups 1.2)" "1.2 should give 2" + assert_equal "2" "$(nvm_num_version_groups v1.2)" "v1.2 should give 2" + assert_equal "2" "$(nvm_num_version_groups v1.2.)" "v1.2. should give 2" + + assert_equal "3" "$(nvm_num_version_groups 1.2.3)" "1.2.3 should give 3" + assert_equal "3" "$(nvm_num_version_groups v1.2.3)" "v1.2.3 should give 3" + assert_equal "3" "$(nvm_num_version_groups v1.2.3.)" "v1.2.3. should give 3" } @test './Unit tests/nvm_prepend_path' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#TEST_PATH=/usr/bin:/usr/local/bin -# -#NEW_PATH=`nvm_prepend_path "$TEST_PATH" "$NVM_DIR/v0.2.5/bin"` -# -#[ "$NEW_PATH" = "$NVM_DIR/v0.2.5/bin:/usr/bin:/usr/local/bin" ] || die "Not correctly prepended: $NEW_PATH " -# -# -#EMPTY_PATH= -# -#NEW_PATH=`nvm_prepend_path "$EMPTY_PATH" "$NVM_DIR/v0.2.5/bin"` -# -#[ "$NEW_PATH" = "$NVM_DIR/v0.2.5/bin" ] || die "Not correctly prepended: $NEW_PATH " + test_implementing && skip + + TEST_PATH=/usr/bin:/usr/local/bin + NEW_PATH=`nvm_prepend_path "$TEST_PATH" "$NVM_DIR/v0.2.5/bin"` + + assert_equal "$NVM_DIR/v0.2.5/bin:/usr/bin:/usr/local/bin" "$NEW_PATH" "Not correctly prepended: $NEW_PATH " + + EMPTY_PATH= + NEW_PATH=`nvm_prepend_path "$EMPTY_PATH" "$NVM_DIR/v0.2.5/bin"` + + assert_equal "$NVM_DIR/v0.2.5/bin" "$NEW_PATH" "Not correctly prepended: $NEW_PATH " } @test './Unit tests/nvm_print_implicit_alias errors' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#EXPECTED_FIRST_MSG="nvm_print_implicit_alias must be specified with local or remote as the first argument." -#[ "_$(nvm_print_implicit_alias 2>&1)" = "_$EXPECTED_FIRST_MSG" ] \ -# || die "nvm_print_implicit_alias did not require local|remote as first argument" -#[ "_$(nvm_print_implicit_alias foo 2>&1)" = "_$EXPECTED_FIRST_MSG" ] \ -# || die "nvm_print_implicit_alias did not require local|remote as first argument" -# -#FIRST_EXIT_CODE="$(nvm_print_implicit_alias > /dev/null 2>&1 ; echo $?)" -#[ "_$FIRST_EXIT_CODE" = "_1" ] \ -# || die "nvm_print_implicit_alias without local|remote had wrong exit code: expected 1, got $FIRST_EXIT_CODE" -# -#EXPECTED_SECOND_MSG="Only implicit aliases 'stable' and 'unstable' are supported." -#[ "_$(nvm_print_implicit_alias local 2>&1)" = "_$EXPECTED_SECOND_MSG" ] \ -# || die "nvm_print_implicit_alias did not require stable|unstable as second argument" -#[ "_$(nvm_print_implicit_alias local foo 2>&1)" = "_$EXPECTED_SECOND_MSG" ] \ -# || die "nvm_print_implicit_alias did not require stable|unstable as second argument" -# -#SECOND_EXIT_CODE="$(nvm_print_implicit_alias local > /dev/null 2>&1 ; echo $?)" -#[ "_$SECOND_EXIT_CODE" = "_2" ] \ -# || die "nvm_print_implicit_alias without stable|unstable had wrong exit code: expected 2, got $SECOND_EXIT_CODE" -# + test_implementing && skip + + run nvm_print_implicit_alias + assert_match "$output" "nvm_print_implicit_alias must be specified with local or remote as the first argument." "nvm_print_implicit_alias did not require local|remote as first argument" + + run nvm_print_implicit_alias foo + assert_match "$output" "nvm_print_implicit_alias must be specified with local or remote as the first argument." "nvm_print_implicit_alias did not require local|remote as first argument" + assert_equal "1" "$status" + + run nvm_print_implicit_alias local + assert_match "$output" "Only implicit aliases 'stable' and 'unstable' are supported." "nvm_print_implicit_alias did not require stable|unstable as second argument" + + run nvm_print_implicit_alias local foo + assert_match "$output" "Only implicit aliases 'stable' and 'unstable' are supported." "nvm_print_implicit_alias did not require stable|unstable as second argument" + assert_equal "2" "$status" } @test './Unit tests/nvm_print_implicit_alias success' { -##!/bin/sh -# -#die () { echo $@ ; cleanup ; exit 1; } -#cleanup() { -# rm -rf ../../../v0.2.3 -# rm -rf ../../../v0.3.4 -# rm -rf ../../../v0.4.6 -# rm -rf ../../../v0.5.7 -# rm -rf ../../../v0.7.7 -# unset -f nvm_ls_remote -#} -# -#. ../../../nvm.sh -# -#mkdir ../../../v0.2.3 -#mkdir ../../../v0.3.4 -#mkdir ../../../v0.4.6 -#mkdir ../../../v0.5.7 -#mkdir ../../../v0.7.7 -# -#LATEST_STABLE="$(nvm_print_implicit_alias local stable)" -#[ "_$LATEST_STABLE" = "_0.4" ] || die "local stable is not latest even minor: expected 0.4, got $LATEST_STABLE" -# -#LATEST_UNSTABLE="$(nvm_print_implicit_alias local unstable)" -#[ "_$LATEST_UNSTABLE" = "_0.7" ] || die "local unstable is not latest odd minor: expected 0.7, got $LATEST_UNSTABLE" -# -#nvm_ls_remote() { -# echo "v0.4.3" -# echo "v0.5.4" -# echo "v0.6.6" -# echo "v0.7.7" -# echo "v0.9.7" -# echo "v0.4.3" -# echo "v0.5.4" -# echo "v0.6.6" -# echo "v0.7.7" -# echo "v0.9.7" -#} -# -#LATEST_STABLE="$(nvm_print_implicit_alias remote stable)" -#[ "_$LATEST_STABLE" = "_0.6" ] || die "remote stable is not latest even minor: expected 0.6, got $LATEST_STABLE" -# -#LATEST_UNSTABLE="$(nvm_print_implicit_alias remote unstable)" -#[ "_$LATEST_UNSTABLE" = "_0.9" ] || die "remote unstable is not latest odd minor: expected 0.9, got $LATEST_UNSTABLE" -# -#cleanup -# + test_implementing && skip + + mkdir -p v0.2.3 v0.3.4 v0.4.6 v0.5.7 v0.7.7 + + run nvm_print_implicit_alias local stable + assert_match "$output" "0.4" + + run nvm_print_implicit_alias local unstable + assert_match "$output" "0.7" + + nvm_ls_remote() { + echo "v0.4.3" + echo "v0.5.4" + echo "v0.6.6" + echo "v0.7.7" + echo "v0.9.7" + echo "v0.4.3" + echo "v0.5.4" + echo "v0.6.6" + echo "v0.7.7" + echo "v0.9.7" + } + + run nvm_print_implicit_alias remote stable + assert_match "$output" "0.6" + + run nvm_print_implicit_alias remote unstable + assert_match "$output" "0.9" } @test './Unit tests/nvm_remote_version' { -##!/bin/sh -# -#die () { echo $@ ; cleanup ; exit 1; } -# -#cleanup() { -# unset -f nvm_ls_remote -#} -# -#. ../../../nvm.sh -# -#nvm_ls_remote() { -# echo "N/A" -#} -# -#OUTPUT="$(nvm_remote_version foo)" -#EXIT_CODE="$(nvm_remote_version foo >/dev/null 2>&1 ; echo $?)" -# -#[ "_$OUTPUT" = "_N/A" ] || die "nonexistent version did not report N/A" -#[ "_$EXIT_CODE" = "_3" ] || die "nonexistent version did not exit with code 3, got $EXIT_CODE" -# -#nvm_ls_remote() { -# echo "test output" -# echo "more test output" -# echo "pattern received: _$1_" -#} -# -#OUTPUT="$(nvm_remote_version foo)" -#EXIT_CODE="$(nvm_remote_version foo >/dev/null 2>&1 ; echo $?)" -# -#[ "_$OUTPUT" = "_pattern received: _foo_" ] \ -# || die "nvm_remote_version foo did not return last line only of nvm_ls_remote foo; got $OUTPUT" -#[ "_$EXIT_CODE" = "_0" ] || die "nvm_remote_version foo did not exit with 0, got $EXIT_CODE" -# -#cleanup -# + test_implementing && skip + + nvm_ls_remote() { + echo "N/A" + } + + run nvm_remote_version foo + assert_match "$output" "N/A" + assert_equal "3" "$status" + + nvm_ls_remote() { + echo "test output" + echo "more test output" + echo "pattern received: _$1_" + } + + run nvm_remote_version foo + assert_match "$output" "pattern received: _foo_" "nvm_remote_version foo did not return last line only of nvm_ls_remote foo; got $OUTPUT" + assert_equal "0" "$status" } @test './Unit tests/nvm_strip_path' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#TEST_PATH=$NVM_DIR/v0.10.5/bin:/usr/bin:$NVM_DIR/v0.11.5/bin:$NVM_DIR/v0.9.5/bin:/usr/local/bin:$NVM_DIR/v0.2.5/bin -# -#STRIPPED_PATH=`nvm_strip_path "$TEST_PATH" "/bin"` -# -#[ "$STRIPPED_PATH" = "/usr/bin:/usr/local/bin" ] || die "Not correctly stripped: $STRIPPED_PATH " + test_implementing && skip + + TEST_PATH=$NVM_DIR/v0.10.5/bin:/usr/bin:$NVM_DIR/v0.11.5/bin:$NVM_DIR/v0.9.5/bin:/usr/local/bin:$NVM_DIR/v0.2.5/bin + + STRIPPED_PATH=`nvm_strip_path "$TEST_PATH" "/bin"` + + assert_equal "/usr/bin:/usr/local/bin" "$STRIPPED_PATH" "Not correctly stripped: $STRIPPED_PATH " + } @test './Unit tests/nvm_tree_contains_path' { -##!/bin/sh -# -#cleanup () { -# rm tmp/node -# rmdir tmp -# rm tmp2/node -# rmdir tmp2 -#} -#die () { echo $@ ; cleanup; exit 1; } -# -#. ../../../nvm.sh -# -#mkdir -p tmp -#touch tmp/node -#mkdir -p tmp2 -#touch tmp2/node -# -#[ "$(nvm_tree_contains_path 2>&1)" = "both the tree and the node path are required" ] || die 'incorrect error message with no args' -#[ "$(nvm_tree_contains_path > /dev/null 2>&1 ; echo $?)" = "2" ] || die 'incorrect error code with no args' -#[ "$(nvm_tree_contains_path tmp 2>&1)" = "both the tree and the node path are required" ] || die 'incorrect error message with one arg' -#[ "$(nvm_tree_contains_path > /dev/null 2>&1 ; echo $?)" = "2" ] || die 'incorrect error code with one arg' -# -#nvm_tree_contains_path tmp tmp/node || die '"tmp" should contain "tmp/node"' -# -#nvm_tree_contains_path tmp tmp2/node && die '"tmp" should not contain "tmp2/node"' -# -#nvm_tree_contains_path tmp2 tmp2/node || die '"tmp2" should contain "tmp2/node"' -# -#nvm_tree_contains_path tmp2 tmp/node && die '"tmp2" should not contain "tmp/node"' -# -#cleanup -# + test_implementing && skip + + mkdir -p tmp tmp2 + touch tmp/node tmp2/node + + run nvm_tree_contains_path + assert_equal "2" "$status" + assert_match "$output" "both the tree and the node path are required" "expected error messge with no args" + + nvm_tree_contains_path tmp tmp/node + ! nvm_tree_contains_path tmp tmp2/node + ! nvm_tree_contains_path tmp2 tmp/node + nvm_tree_contains_path tmp2 tmp2/node } @test './Unit tests/nvm_validate_implicit_alias' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#EXPECTED_MSG="Only implicit aliases 'stable' and 'unstable' are supported." -#[ "_$(nvm_validate_implicit_alias 2>&1)" = "_$EXPECTED_MSG" ] \ -# || die "nvm_validate_implicit_alias did not require stable|unstable" -#[ "_$(nvm_validate_implicit_alias foo 2>&1)" = "_$EXPECTED_MSG" ] \ -# || die "nvm_validate_implicit_alias did not require stable|unstable" -# -#EXIT_CODE="$(nvm_validate_implicit_alias >/dev/null 2>&1 ; echo $?)" -#[ "_$EXIT_CODE" = "_1" ] \ -# || die "nvm_validate_implicit_alias without stable|unstable had wrong exit code: expected 1, got $EXIT_CODE" -# -#nvm_validate_implicit_alias stable || die "nvm_validate_implicit_alias stable did not exit 0" -#nvm_validate_implicit_alias unstable || die "nvm_validate_implicit_alias unstable did not exit 0" -# + test_implementing && skip + + run nvm_validate_implicit_alias + assert_match "$output" "Only implicit aliases 'stable' and 'unstable' are supported." "nvm_validate_implicit_alias did not require stable|unstable" + run nvm_validate_implicit_alias foo + assert_match "$output" "Only implicit aliases 'stable' and 'unstable' are supported." "nvm_validate_implicit_alias did not require stable|unstable" + assert_equal "1" "$status" + + nvm_validate_implicit_alias stable + nvm_validate_implicit_alias unstable } @test './Unit tests/nvm_version_dir' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#[ "$(nvm_version_dir)" = "$NVM_DIR/versions" ] || die '"nvm_version_dir" did not return new dir path' -#[ "$(nvm_version_dir new)" = "$(nvm_version_dir)" ] || die '"nvm_version_dir new" did not return new dir path' -#[ "$(nvm_version_dir old)" = "$NVM_DIR" ] || die '"nvm_version_dir old" did not return old dir path' -#[ "$(nvm_version_dir foo 2>&1)" = "unknown version dir" ] || die '"nvm_version_dir foo" did not error out' -# +# test_implementing && skip + + run nvm_version_dir + assert_equal "$NVM_DIR/versions" "$output" + + run nvm_version_dir new + assert_equal "$NVM_DIR/versions" "$output" + + run nvm_version_dir old + assert_equal "$NVM_DIR" "$output" + + run nvm_version_dir foo + assert_match "$output" "unknown version dir" + assert_unequal "0" "$status" } @test './Unit tests/nvm_version_greater' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#nvm_version_greater 0.10.0 0.2.12 || die '"nvm_version_greater 0.10.0 0.2.12" did not return true' -# -#if nvm_version_greater 0.10.0 0.20.12; then -# die '"nvm_version_greater 0.10.0 0.20.12" returned true' -#fi -# -#if nvm_version_greater 0.10.0 0.10.0; then -# die '"nvm_version_greater" returned false for the same two versions' -#fi -# +# test_implementing && skip + + nvm_version_greater 0.10.0 0.2.12 + + ! nvm_version_greater 0.10.0 0.20.12 + + ! nvm_version_greater 0.10.0 0.10.0 } @test './Unit tests/nvm_version_path' { -##!/bin/sh -# -#die () { echo $@ ; exit 1; } -# -#. ../../../nvm.sh -# -#[ "$(nvm_version_path foo)" = "$NVM_DIR/foo" ] || die '"nvm_version_path foo" did not return correct location' -#[ "$(nvm_version_path 2>&1)" = "version is required" ] || die '"nvm_version_path" did not error out' -#[ "$(nvm_version_path v0.11.0)" = "$NVM_DIR/v0.11.0" ] || die 'old version has the wrong path' -#[ "$(nvm_version_path v0.12.0)" = "$NVM_DIR/versions/v0.12.0" ] || die 'new version has the wrong path' -# +# test_implementing && skip + + run nvm_version_path foo + assert_match "$output" "$NVM_DIR/foo" + + run nvm_version_path + assert_unequal "0" "$status" + + run nvm_version_path v0.11.0 + assert_match "$output" "$NVM_DIR/v0.11.0" + + run nvm_version_path v0.12.0 + assert_match "$output" "$NVM_DIR/versions/v0.12.0" } diff --git a/test/fixtures/download.txt b/test/fixtures/download.txt new file mode 100644 index 0000000..58535a2 --- /dev/null +++ b/test/fixtures/download.txt @@ -0,0 +1,430 @@ +foo "v0.10.0 +foo "v0.10.0 +foo "v0.10.1 +foo "v0.10.1 +foo "v0.10.10 +foo "v0.10.10 +foo "v0.10.11 +foo "v0.10.11 +foo "v0.10.12 +foo "v0.10.12 +foo "v0.10.13 +foo "v0.10.13 +foo "v0.10.14 +foo "v0.10.14 +foo "v0.10.15 +foo "v0.10.15 +foo "v0.10.16 +foo "v0.10.16 +foo "v0.10.16 +foo "v0.10.16 +foo "v0.10.17 +foo "v0.10.17 +foo "v0.10.18 +foo "v0.10.18 +foo "v0.10.19 +foo "v0.10.19 +foo "v0.10.2 +foo "v0.10.2 +foo "v0.10.20 +foo "v0.10.20 +foo "v0.10.21 +foo "v0.10.21 +foo "v0.10.22 +foo "v0.10.22 +foo "v0.10.23 +foo "v0.10.23 +foo "v0.10.24 +foo "v0.10.24 +foo "v0.10.25 +foo "v0.10.25 +foo "v0.10.26 +foo "v0.10.26 +foo "v0.10.27 +foo "v0.10.27 +foo "v0.10.28 +foo "v0.10.28 +foo "v0.10.29 +foo "v0.10.29 +foo "v0.10.3 +foo "v0.10.3 +foo "v0.10.30 +foo "v0.10.30 +foo "v0.10.31 +foo "v0.10.31 +foo "v0.10.32 +foo "v0.10.32 +foo "v0.10.4 +foo "v0.10.4 +foo "v0.10.5 +foo "v0.10.5 +foo "v0.10.6 +foo "v0.10.6 +foo "v0.10.7 +foo "v0.10.7 +foo "v0.10.8 +foo "v0.10.8 +foo "v0.10.9 +foo "v0.10.9 +foo "v0.11.0 +foo "v0.11.0 +foo "v0.11.1 +foo "v0.11.1 +foo "v0.11.10 +foo "v0.11.10 +foo "v0.11.11 +foo "v0.11.11 +foo "v0.11.12 +foo "v0.11.12 +foo "v0.11.13 +foo "v0.11.13 +foo "v0.11.14 +foo "v0.11.14 +foo "v0.11.2 +foo "v0.11.2 +foo "v0.11.3 +foo "v0.11.3 +foo "v0.11.4 +foo "v0.11.4 +foo "v0.11.5 +foo "v0.11.5 +foo "v0.11.6 +foo "v0.11.6 +foo "v0.11.7 +foo "v0.11.7 +foo "v0.11.8 +foo "v0.11.8 +foo "v0.11.9 +foo "v0.11.9 +foo "v0.5.1 +foo "v0.5.1 +foo "v0.5.10 +foo "v0.5.10 +foo "v0.5.2 +foo "v0.5.2 +foo "v0.5.3 +foo "v0.5.3 +foo "v0.5.4 +foo "v0.5.4 +foo "v0.5.5 +foo "v0.5.5 +foo "v0.5.6 +foo "v0.5.6 +foo "v0.5.7 +foo "v0.5.7 +foo "v0.5.8 +foo "v0.5.8 +foo "v0.5.9 +foo "v0.5.9 +foo "v0.6.0 +foo "v0.6.0 +foo "v0.6.1 +foo "v0.6.1 +foo "v0.6.10 +foo "v0.6.10 +foo "v0.6.11 +foo "v0.6.11 +foo "v0.6.12 +foo "v0.6.12 +foo "v0.6.13 +foo "v0.6.13 +foo "v0.6.14 +foo "v0.6.14 +foo "v0.6.15 +foo "v0.6.15 +foo "v0.6.16 +foo "v0.6.16 +foo "v0.6.17 +foo "v0.6.17 +foo "v0.6.18 +foo "v0.6.18 +foo "v0.6.19 +foo "v0.6.19 +foo "v0.6.2 +foo "v0.6.2 +foo "v0.6.20 +foo "v0.6.20 +foo "v0.6.21 +foo "v0.6.21 +foo "v0.6.3 +foo "v0.6.3 +foo "v0.6.4 +foo "v0.6.4 +foo "v0.6.5 +foo "v0.6.5 +foo "v0.6.6 +foo "v0.6.6 +foo "v0.6.7 +foo "v0.6.7 +foo "v0.6.8 +foo "v0.6.8 +foo "v0.6.9 +foo "v0.6.9 +foo "v0.7.0 +foo "v0.7.0 +foo "v0.7.1 +foo "v0.7.1 +foo "v0.7.10 +foo "v0.7.10 +foo "v0.7.11 +foo "v0.7.11 +foo "v0.7.12 +foo "v0.7.12 +foo "v0.7.2 +foo "v0.7.2 +foo "v0.7.3 +foo "v0.7.3 +foo "v0.7.4 +foo "v0.7.4 +foo "v0.7.5 +foo "v0.7.5 +foo "v0.7.6 +foo "v0.7.6 +foo "v0.7.7 +foo "v0.7.7 +foo "v0.7.8 +foo "v0.7.8 +foo "v0.7.9 +foo "v0.7.9 +foo "v0.8.0 +foo "v0.8.0 +foo "v0.8.1 +foo "v0.8.1 +foo "v0.8.10 +foo "v0.8.10 +foo "v0.8.11 +foo "v0.8.11 +foo "v0.8.12 +foo "v0.8.12 +foo "v0.8.13 +foo "v0.8.13 +foo "v0.8.14 +foo "v0.8.14 +foo "v0.8.15 +foo "v0.8.15 +foo "v0.8.16 +foo "v0.8.16 +foo "v0.8.17 +foo "v0.8.17 +foo "v0.8.18 +foo "v0.8.18 +foo "v0.8.19 +foo "v0.8.19 +foo "v0.8.2 +foo "v0.8.2 +foo "v0.8.20 +foo "v0.8.20 +foo "v0.8.21 +foo "v0.8.21 +foo "v0.8.22 +foo "v0.8.22 +foo "v0.8.23 +foo "v0.8.23 +foo "v0.8.24 +foo "v0.8.24 +foo "v0.8.25 +foo "v0.8.25 +foo "v0.8.26 +foo "v0.8.26 +foo "v0.8.27 +foo "v0.8.27 +foo "v0.8.28 +foo "v0.8.28 +foo "v0.8.3 +foo "v0.8.3 +foo "v0.8.4 +foo "v0.8.4 +foo "v0.8.5 +foo "v0.8.5 +foo "v0.8.6 +foo "v0.8.6 +foo "v0.8.7 +foo "v0.8.7 +foo "v0.8.8 +foo "v0.8.8 +foo "v0.8.9 +foo "v0.8.9 +foo "v0.9.0 +foo "v0.9.0 +foo "v0.9.1 +foo "v0.9.1 +foo "v0.9.10 +foo "v0.9.10 +foo "v0.9.11 +foo "v0.9.11 +foo "v0.9.12 +foo "v0.9.12 +foo "v0.9.2 +foo "v0.9.2 +foo "v0.9.3 +foo "v0.9.3 +foo "v0.9.4 +foo "v0.9.4 +foo "v0.9.5 +foo "v0.9.5 +foo "v0.9.6 +foo "v0.9.6 +foo "v0.9.7 +foo "v0.9.7 +foo "v0.9.8 +foo "v0.9.8 +foo "v0.9.9 +foo "v0.9.9 +foo "v0.1.100 +foo "v0.1.100 +foo "v0.1.101 +foo "v0.1.101 +foo "v0.1.102 +foo "v0.1.102 +foo "v0.1.103 +foo "v0.1.103 +foo "v0.1.104 +foo "v0.1.104 +foo "v0.1.14 +foo "v0.1.14 +foo "v0.1.15 +foo "v0.1.15 +foo "v0.1.16 +foo "v0.1.16 +foo "v0.1.17 +foo "v0.1.17 +foo "v0.1.18 +foo "v0.1.18 +foo "v0.1.19 +foo "v0.1.19 +foo "v0.1.20 +foo "v0.1.20 +foo "v0.1.21 +foo "v0.1.21 +foo "v0.1.22 +foo "v0.1.22 +foo "v0.1.23 +foo "v0.1.23 +foo "v0.1.24 +foo "v0.1.24 +foo "v0.1.25 +foo "v0.1.25 +foo "v0.1.26 +foo "v0.1.26 +foo "v0.1.27 +foo "v0.1.27 +foo "v0.1.28 +foo "v0.1.28 +foo "v0.1.29 +foo "v0.1.29 +foo "v0.1.30 +foo "v0.1.30 +foo "v0.1.31 +foo "v0.1.31 +foo "v0.1.32 +foo "v0.1.32 +foo "v0.1.33 +foo "v0.1.33 +foo "v0.1.90 +foo "v0.1.90 +foo "v0.1.91 +foo "v0.1.91 +foo "v0.1.92 +foo "v0.1.92 +foo "v0.1.93 +foo "v0.1.93 +foo "v0.1.94 +foo "v0.1.94 +foo "v0.1.95 +foo "v0.1.95 +foo "v0.1.96 +foo "v0.1.96 +foo "v0.1.97 +foo "v0.1.97 +foo "v0.1.98 +foo "v0.1.98 +foo "v0.1.99 +foo "v0.1.99 +foo "v0.10.14 +foo "v0.10.14 +foo "v0.2.0 +foo "v0.2.0 +foo "v0.2.1 +foo "v0.2.1 +foo "v0.2.2 +foo "v0.2.2 +foo "v0.2.3 +foo "v0.2.3 +foo "v0.2.4 +foo "v0.2.4 +foo "v0.2.5 +foo "v0.2.5 +foo "v0.2.6 +foo "v0.2.6 +foo "v0.3.0 +foo "v0.3.0 +foo "v0.3.1 +foo "v0.3.1 +foo "v0.3.2 +foo "v0.3.2 +foo "v0.3.3 +foo "v0.3.3 +foo "v0.3.4 +foo "v0.3.4 +foo "v0.3.5 +foo "v0.3.5 +foo "v0.3.6 +foo "v0.3.6 +foo "v0.3.7 +foo "v0.3.7 +foo "v0.3.8 +foo "v0.3.8 +foo "v0.4.0 +foo "v0.4.0 +foo "v0.4.1 +foo "v0.4.1 +foo "v0.4.10 +foo "v0.4.10 +foo "v0.4.11 +foo "v0.4.11 +foo "v0.4.12 +foo "v0.4.12 +foo "v0.4.2 +foo "v0.4.2 +foo "v0.4.3 +foo "v0.4.3 +foo "v0.4.4 +foo "v0.4.4 +foo "v0.4.5 +foo "v0.4.5 +foo "v0.4.6 +foo "v0.4.6 +foo "v0.4.7 +foo "v0.4.7 +foo "v0.4.8 +foo "v0.4.8 +foo "v0.4.9 +foo "v0.4.9 +foo "v0.5.0 +foo "v0.5.0 +foo "v0.6.1 +foo "v0.6.1 +foo "v0.6.10 +foo "v0.6.10 +foo "v0.6.11 +foo "v0.6.11 +foo "v0.6.12 +foo "v0.6.12 +foo "v0.6.13 +foo "v0.6.13 +foo "v0.6.2 +foo "v0.6.2 +foo "v0.6.3 +foo "v0.6.3 +foo "v0.6.4 +foo "v0.6.4 +foo "v0.6.5 +foo "v0.6.5 +foo "v0.6.6 +foo "v0.6.6 +foo "v0.6.7 +foo "v0.6.7 +foo "v0.6.8 +foo "v0.6.8 +foo "v0.6.9 +foo "v0.6.9 From 9fcc9c3775ee5b1caba5e560c74f27313a04b8a3 Mon Sep 17 00:00:00 2001 From: smikes Date: Tue, 23 Dec 2014 15:50:46 -0700 Subject: [PATCH 21/21] remove needless assignment to "x" per github line notes --- test/bats/fast.bats | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/bats/fast.bats b/test/bats/fast.bats index 7092f6a..9185ea5 100644 --- a/test/bats/fast.bats +++ b/test/bats/fast.bats @@ -61,8 +61,6 @@ teardown() { assert_nomatch "$PATH" ".*v0.2.3/.*/bin" "v0.2.3 should not be active yet" [ `expr $PATH : ".*v0.2.3/.*/bin"` = 0 ] - x=$(nvm_version_path v0.2.3) - # can't use 'run' -- sets up new env, PATH is lost nvm use 0.2.3