mirror of
https://github.com/sstephenson/bats.git
synced 2024-11-17 03:32:27 +01:00
Make load
handle absolute paths too
Add 2 simple tests on this.
This commit is contained in:
parent
2476770c84
commit
35f963010d
|
@ -30,13 +30,20 @@ BATS_TEST_DIRNAME="$(dirname "$BATS_TEST_FILENAME")"
|
||||||
BATS_TEST_NAMES=()
|
BATS_TEST_NAMES=()
|
||||||
|
|
||||||
load() {
|
load() {
|
||||||
local filename="$BATS_TEST_DIRNAME/$1.bash"
|
local inc="$1"
|
||||||
|
local filename
|
||||||
|
|
||||||
|
if [[ "${inc}" == "/"* ]] ; then
|
||||||
|
filename="${inc}"
|
||||||
|
else
|
||||||
|
filename="$BATS_TEST_DIRNAME/${inc}.bash"
|
||||||
|
fi
|
||||||
[ -f "$filename" ] || {
|
[ -f "$filename" ] || {
|
||||||
echo "bats: $filename does not exist" >&2
|
echo "bats: $filename does not exist" >&2
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
source "$BATS_TEST_DIRNAME/$1.bash"
|
source "${filename}"
|
||||||
}
|
}
|
||||||
|
|
||||||
run() {
|
run() {
|
||||||
|
|
|
@ -117,6 +117,16 @@ fixtures bats
|
||||||
[ $status -eq 1 ]
|
[ $status -eq 1 ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "load sources scripts by absolute path" {
|
||||||
|
HELPER_NAME="${FIXTURE_ROOT}/test_helper.bash" run bats "$FIXTURE_ROOT/load.bats"
|
||||||
|
[ $status -eq 0 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "load aborts if the script, specified by an absolute path, does not exist" {
|
||||||
|
HELPER_NAME="${FIXTURE_ROOT}/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 ]
|
||||||
|
|
Loading…
Reference in New Issue
Block a user