mirror of
https://github.com/sstephenson/bats.git
synced 2024-11-17 11:42:33 +01:00
Suite support for aggregating multiple tests under a single run
This commit is contained in:
parent
f8f78b5cd3
commit
19a05cc77d
|
@ -56,4 +56,9 @@ else
|
||||||
shift
|
shift
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec bats-exec-test $count_only "$(expand_path "$filename")" "$@"
|
if [ -d "$filename" ]; then
|
||||||
|
shopt -s nullglob
|
||||||
|
exec bats-exec-suite $count_only "$(expand_path "$filename")"/*.bats
|
||||||
|
else
|
||||||
|
exec bats-exec-test $count_only "$(expand_path "$filename")" "$@"
|
||||||
|
fi
|
||||||
|
|
45
libexec/bats-exec-suite
Executable file
45
libexec/bats-exec-suite
Executable file
|
@ -0,0 +1,45 @@
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
set -e
|
||||||
|
|
||||||
|
count_only=""
|
||||||
|
if [ "$1" = "-c" ]; then
|
||||||
|
count_only=1
|
||||||
|
shift
|
||||||
|
fi
|
||||||
|
|
||||||
|
trap "kill 0; exit 1" int
|
||||||
|
|
||||||
|
count=0
|
||||||
|
for filename in "$@"; do
|
||||||
|
count=$(($count + $(bats-exec-test -c "$filename")))
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ -n "$count_only" ]; then
|
||||||
|
echo "$count"
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "1..$count"
|
||||||
|
status=0
|
||||||
|
offset=0
|
||||||
|
for filename in "$@"; do
|
||||||
|
index=0
|
||||||
|
{
|
||||||
|
IFS= read -r # 1..n
|
||||||
|
while IFS= read -r line; do
|
||||||
|
case "$line" in
|
||||||
|
"ok "* | "not ok "* )
|
||||||
|
index=$(($index + 1))
|
||||||
|
echo "${line/ $index / $(($offset + $index)) }"
|
||||||
|
[ "${line:0:6}" != "not ok" ] || status=1
|
||||||
|
;;
|
||||||
|
* )
|
||||||
|
echo "$line"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
} < <( bats-exec-test "$filename" )
|
||||||
|
offset=$(($offset + $index))
|
||||||
|
done
|
||||||
|
|
||||||
|
exit "$status"
|
|
@ -1,11 +1,7 @@
|
||||||
#!/usr/bin/env bats
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures"
|
load test_helper
|
||||||
export TMP="$BATS_TEST_DIRNAME/tmp"
|
fixtures bats
|
||||||
|
|
||||||
teardown() {
|
|
||||||
rm -f "$TMP"/*
|
|
||||||
}
|
|
||||||
|
|
||||||
@test "no arguments prints usage instructions" {
|
@test "no arguments prints usage instructions" {
|
||||||
run bats
|
run bats
|
||||||
|
|
3
test/fixtures/suite/multiple/a.bats
vendored
Normal file
3
test/fixtures/suite/multiple/a.bats
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
@test "truth" {
|
||||||
|
true
|
||||||
|
}
|
7
test/fixtures/suite/multiple/b.bats
vendored
Normal file
7
test/fixtures/suite/multiple/b.bats
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
@test "more truth" {
|
||||||
|
true
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "quasi-truth" {
|
||||||
|
[ -z "$FLUNK" ]
|
||||||
|
}
|
3
test/fixtures/suite/single/test.bats
vendored
Normal file
3
test/fixtures/suite/single/test.bats
vendored
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
@test "a passing test" {
|
||||||
|
true
|
||||||
|
}
|
43
test/suite.bats
Normal file
43
test/suite.bats
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
#!/usr/bin/env bats
|
||||||
|
|
||||||
|
load test_helper
|
||||||
|
fixtures suite
|
||||||
|
|
||||||
|
@test "running a suite with no test files" {
|
||||||
|
run bats "$FIXTURE_ROOT/empty"
|
||||||
|
[ $status -eq 0 ]
|
||||||
|
[ $output = "1..0" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "running a suite with one test file" {
|
||||||
|
run bats "$FIXTURE_ROOT/single"
|
||||||
|
[ $status -eq 0 ]
|
||||||
|
[ ${lines[0]} = "1..1" ]
|
||||||
|
[ ${lines[1]} = "ok 1 a passing test" ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "counting tests in a suite" {
|
||||||
|
run bats -c "$FIXTURE_ROOT/single"
|
||||||
|
[ $status -eq 0 ]
|
||||||
|
[ $output -eq 1 ]
|
||||||
|
|
||||||
|
run bats -c "$FIXTURE_ROOT/multiple"
|
||||||
|
[ $status -eq 0 ]
|
||||||
|
[ $output -eq 3 ]
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "aggregated output of multiple tests in a suite" {
|
||||||
|
run bats "$FIXTURE_ROOT/multiple"
|
||||||
|
[ $status -eq 0 ]
|
||||||
|
[ ${lines[0]} = "1..3" ]
|
||||||
|
echo "$output" | grep "^ok . truth"
|
||||||
|
echo "$output" | grep "^ok . more truth"
|
||||||
|
echo "$output" | grep "^ok . quasi-truth"
|
||||||
|
}
|
||||||
|
|
||||||
|
@test "a failing test in a suite results in an error exit code" {
|
||||||
|
FLUNK=1 run bats "$FIXTURE_ROOT/multiple"
|
||||||
|
[ $status -eq 1 ]
|
||||||
|
[ ${lines[0]} = "1..3" ]
|
||||||
|
echo "$output" | grep "^not ok . quasi-truth"
|
||||||
|
}
|
11
test/test_helper.bash
Normal file
11
test/test_helper.bash
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fixtures() {
|
||||||
|
FIXTURE_ROOT="$BATS_TEST_DIRNAME/fixtures/$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
setup() {
|
||||||
|
export TMP="$BATS_TEST_DIRNAME/tmp"
|
||||||
|
}
|
||||||
|
|
||||||
|
teardown() {
|
||||||
|
rm -f "$TMP"/*
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user