diff --git a/libexec/bats-format-tap-stream b/libexec/bats-format-tap-stream index 1780680..614768f 100755 --- a/libexec/bats-format-tap-stream +++ b/libexec/bats-format-tap-stream @@ -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 @@ -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() { @@ -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 diff --git a/test/bats.bats b/test/bats.bats index dbc08d6..280515d 100755 --- a/test/bats.bats +++ b/test/bats.bats @@ -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 ] diff --git a/test/fixtures/bats/passing_and_failing.bats b/test/fixtures/bats/passing_and_failing.bats new file mode 100644 index 0000000..7b7d8ee --- /dev/null +++ b/test/fixtures/bats/passing_and_failing.bats @@ -0,0 +1,7 @@ +@test "a passing test" { + true +} + +@test "a failing test" { + false +} diff --git a/test/fixtures/bats/passing_and_skipping.bats b/test/fixtures/bats/passing_and_skipping.bats new file mode 100644 index 0000000..88d74be --- /dev/null +++ b/test/fixtures/bats/passing_and_skipping.bats @@ -0,0 +1,7 @@ +@test "a passing test" { + true +} + +@test "a skipping test" { + skip +} diff --git a/test/fixtures/bats/passing_failing_and_skipping.bats b/test/fixtures/bats/passing_failing_and_skipping.bats new file mode 100644 index 0000000..3c9f17f --- /dev/null +++ b/test/fixtures/bats/passing_failing_and_skipping.bats @@ -0,0 +1,11 @@ +@test "a passing test" { + true +} + +@test "a skipping test" { + skip +} + +@test "a failing test" { + false +} diff --git a/test/test_helper.bash b/test/test_helper.bash index a01b4b0..84eee8c 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -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"/* }