mirror of
https://github.com/sstephenson/bats.git
synced 2024-11-17 03:32:27 +01:00
Abort when load is invoked with a nonexistent script
This commit is contained in:
parent
a75495b9dd
commit
04be7dc717
|
@ -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"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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 ]
|
||||||
|
|
3
test/fixtures/bats/load.bats
vendored
3
test/fixtures/bats/load.bats
vendored
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue
Block a user