1
0
mirror of https://github.com/sstephenson/bats.git synced 2024-12-26 06:29:47 +01:00

bats -c filename prints the number of tests in the file

This commit is contained in:
Sam Stephenson 2012-04-08 23:25:19 -05:00
parent 3f82256855
commit 6b965e18c4
3 changed files with 30 additions and 3 deletions

View File

@ -40,14 +40,20 @@ if [ "$1" = "-v" ] || [ "$1" = "--version" ]; then
exit 0
fi
count_only=""
if [ "$1" = "-c" ]; then
count_only="-c"
shift
fi
filename="$1"
if [ -z "$filename" ]; then
{ version
echo "usage: $0 <filename>"
echo "usage: $0 [-c] <filename>"
} >&2
exit 1
else
shift
fi
exec bats-exec "$(expand_path "$filename")" "$@"
exec bats-exec $count_only "$(expand_path "$filename")" "$@"

View File

@ -1,6 +1,12 @@
#!/usr/bin/env bash
set -e
BATS_COUNT_ONLY=""
if [ "$1" = "-c" ]; then
BATS_COUNT_ONLY=1
shift
fi
BATS_TEST_FILENAME="$1"
if [ -z "$BATS_TEST_FILENAME" ]; then
echo "usage: bats-exec <filename>" >&2
@ -136,7 +142,12 @@ exec 3<&1
if [ "$#" -eq 0 ]; then
bats_preprocess_source
bats_evaluate_preprocessed_source
bats_perform_tests "${BATS_TEST_NAMES[@]}"
if [ -n "$BATS_COUNT_ONLY" ]; then
echo "${#BATS_TEST_NAMES[@]}"
else
bats_perform_tests "${BATS_TEST_NAMES[@]}"
fi
else
bats_evaluate_preprocessed_source
bats_perform_test "$@"

View File

@ -86,3 +86,13 @@ teardown() {
[ "${lines[5]}" = " failure stdout 2" ]
[ "${lines[7]}" = " failure stderr" ]
}
@test "-c prints the number of tests" {
run bats -c "$FIXTURE_ROOT/empty.bats"
[ $status -eq 0 ]
[ "$output" = "0" ]
run bats -c "$FIXTURE_ROOT/output.bats"
[ $status -eq 0 ]
[ "$output" = "4" ]
}