1
0
mirror of https://github.com/sstephenson/bats.git synced 2024-09-29 12:38:26 +02:00

Abort when load is invoked with a nonexistent script

This commit is contained in:
Sam Stephenson 2012-11-16 14:35:48 -06:00
parent a75495b9dd
commit 04be7dc717
3 changed files with 14 additions and 2 deletions

View File

@ -12,7 +12,7 @@ if [ -z "$BATS_TEST_FILENAME" ]; then
echo "usage: bats-exec <filename>" >&2 echo "usage: bats-exec <filename>" >&2
exit 1 exit 1
elif [ ! -f "$BATS_TEST_FILENAME" ]; then 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 exit 1
else else
shift shift
@ -22,6 +22,12 @@ BATS_TEST_DIRNAME="$(dirname "$BATS_TEST_FILENAME")"
BATS_TEST_NAMES=() BATS_TEST_NAMES=()
load() { 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" source "$BATS_TEST_DIRNAME/$1.bash"
} }

View File

@ -75,6 +75,11 @@ fixtures bats
[ $status -eq 0 ] [ $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" { @test "output is discarded for passing tests and printed for failing tests" {
run bats "$FIXTURE_ROOT/output.bats" run bats "$FIXTURE_ROOT/output.bats"
[ $status -eq 1 ] [ $status -eq 1 ]

View File

@ -1,4 +1,5 @@
load test_helper [ -n "$HELPER_NAME" ] || HELPER_NAME="test_helper"
load "$HELPER_NAME"
@test "calling a loaded helper" { @test "calling a loaded helper" {
help_me help_me