Skip to content
This repository has been archived by the owner on Apr 29, 2021. It is now read-only.

Commit

Permalink
Merge pull request #68 from duggan/test-summaries
Browse files Browse the repository at this point in the history
Test summaries
  • Loading branch information
sstephenson committed Aug 13, 2014
2 parents 2c6fed1 + 3be8246 commit d628bd7
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 3 deletions.
14 changes: 11 additions & 3 deletions libexec/bats-format-tap-stream
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ if [[ "$header" =~ $header_pattern ]]; then
count="${header:3}"
index=0
failures=0
skipped=0
name=""
count_column_width=$(( ${#count} * 2 + 2 ))
else
Expand Down Expand Up @@ -64,9 +65,15 @@ log() {
}

summary() {
printf "\n%d test%s, %d failure%s\n" \
"$count" "$(plural "$count")" \
"$failures" "$(plural "$failures")"
printf "\n%d test%s" "$count" "$(plural "$count")"

printf ", %d failure%s" "$failures" "$(plural "$failures")"

if [ "$skipped" -gt 0 ]; then
printf ", %d skipped" "$skipped"
fi

printf "\n"
}

printf_with_truncation() {
Expand Down Expand Up @@ -139,6 +146,7 @@ while IFS= read -r line; do
"ok "* )
skip_expr="ok $index # skip (\(([^)]*)\))?"
if [[ "$line" =~ $skip_expr ]]; then
let skipped+=1
buffer skip "${BASH_REMATCH[2]}"
else
buffer pass
Expand Down
24 changes: 24 additions & 0 deletions test/bats.bats
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,30 @@ fixtures bats
[ ${lines[1]} = "ok 1 a passing test" ]
}

@test "summary passing tests" {
run filter_control_sequences bats -p $FIXTURE_ROOT/passing.bats
[ $status -eq 0 ]
[ "${lines[1]}" = "1 test, 0 failures" ]
}

@test "summary passing and skipping tests" {
run filter_control_sequences bats -p $FIXTURE_ROOT/passing_and_skipping.bats
[ $status -eq 0 ]
[ "${lines[2]}" = "2 tests, 0 failures, 1 skipped" ]
}

@test "summary passing and failing tests" {
run filter_control_sequences bats -p $FIXTURE_ROOT/failing_and_passing.bats
[ $status -eq 0 ]
[ "${lines[4]}" = "2 tests, 1 failure" ]
}

@test "summary passing, failing and skipping tests" {
run filter_control_sequences bats -p $FIXTURE_ROOT/passing_failing_and_skipping.bats
[ $status -eq 0 ]
[ "${lines[5]}" = "3 tests, 1 failure, 1 skipped" ]
}

@test "one failing test" {
run bats "$FIXTURE_ROOT/failing.bats"
[ $status -eq 1 ]
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/bats/passing_and_failing.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@test "a passing test" {
true
}

@test "a failing test" {
false
}
7 changes: 7 additions & 0 deletions test/fixtures/bats/passing_and_skipping.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@test "a passing test" {
true
}

@test "a skipping test" {
skip
}
11 changes: 11 additions & 0 deletions test/fixtures/bats/passing_failing_and_skipping.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@test "a passing test" {
true
}

@test "a skipping test" {
skip
}

@test "a failing test" {
false
}
4 changes: 4 additions & 0 deletions test/test_helper.bash
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ setup() {
export TMP="$BATS_TEST_DIRNAME/tmp"
}

filter_control_sequences() {
"$@" | sed $'s,\x1b\\[[0-9;]*[a-zA-Z],,g'
}

teardown() {
[ -d "$TMP" ] && rm -f "$TMP"/*
}

0 comments on commit d628bd7

Please sign in to comment.