From 04be7dc717d22e7b2909d8e231fb528ec79361c8 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Fri, 16 Nov 2012 14:35:48 -0600 Subject: [PATCH] Abort when load is invoked with a nonexistent script --- libexec/bats-exec-test | 8 +++++++- test/bats.bats | 5 +++++ test/fixtures/bats/load.bats | 3 ++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/libexec/bats-exec-test b/libexec/bats-exec-test index 278fedc..2c70426 100755 --- a/libexec/bats-exec-test +++ b/libexec/bats-exec-test @@ -12,7 +12,7 @@ if [ -z "$BATS_TEST_FILENAME" ]; then echo "usage: bats-exec " >&2 exit 1 elif [ ! -f "$BATS_TEST_FILENAME" ]; then - echo "bats: $BATS_TEST_FILENAME does not exist" + echo "bats: $BATS_TEST_FILENAME does not exist" >&2 exit 1 else shift @@ -22,6 +22,12 @@ BATS_TEST_DIRNAME="$(dirname "$BATS_TEST_FILENAME")" BATS_TEST_NAMES=() load() { + local filename="$BATS_TEST_DIRNAME/$1.bash" + [ -f "$filename" ] || { + echo "bats: $filename does not exist" >&2 + exit 1 + } + source "$BATS_TEST_DIRNAME/$1.bash" } diff --git a/test/bats.bats b/test/bats.bats index 84d3d7c..cdafe8b 100755 --- a/test/bats.bats +++ b/test/bats.bats @@ -75,6 +75,11 @@ fixtures bats [ $status -eq 0 ] } +@test "load aborts if the specified script does not exist" { + HELPER_NAME="nonexistent" run bats "$FIXTURE_ROOT/load.bats" + [ $status -eq 1 ] +} + @test "output is discarded for passing tests and printed for failing tests" { run bats "$FIXTURE_ROOT/output.bats" [ $status -eq 1 ] diff --git a/test/fixtures/bats/load.bats b/test/fixtures/bats/load.bats index 4d677a5..975b6b8 100644 --- a/test/fixtures/bats/load.bats +++ b/test/fixtures/bats/load.bats @@ -1,4 +1,5 @@ -load test_helper +[ -n "$HELPER_NAME" ] || HELPER_NAME="test_helper" +load "$HELPER_NAME" @test "calling a loaded helper" { help_me