From 36b0251e5b6f324d3d339eda7c1d479152c8d1d3 Mon Sep 17 00:00:00 2001 From: smikes Date: Sun, 21 Dec 2014 13:10:45 -0700 Subject: [PATCH] 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"