diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 3838c4fb7d..c84a1d0c6f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -19,7 +19,9 @@ The format is based on [Keep a Changelog][kac] and this project adheres to * unset `output`, `stderr`, `lines`, `stderr_lines` at the start of `run` to avoid crosstalk between successive invocations (#1105) -* junit: XML escape fully removes ANSI sequences, e.g. color codes, cursor movements (#1103) +* junit: + * XML escape fully removes ANSI sequences, e.g. color codes, cursor movements (#1103) + * fix retried tests being listed multiple times (#1150) * remove deprecated windows runner (#1119) * renamed `docker-compose.yml` to `compose.yaml` (#1128) diff --git a/libexec/bats-core/bats-format-junit b/libexec/bats-core/bats-format-junit index 06fc8b6d78..8fe8d9fa64 100755 --- a/libexec/bats-core/bats-format-junit +++ b/libexec/bats-core/bats-format-junit @@ -155,6 +155,7 @@ flush_log() { fi _buffer_log="" _system_out_log="" + test_result_state="" # Clean out result from last test. Retried tests will have multiple begin calls. } log_system_out() { diff --git a/test/fixtures/junit-formatter/issue_1149.bats b/test/fixtures/junit-formatter/issue_1149.bats new file mode 100644 index 0000000000..293e281ab6 --- /dev/null +++ b/test/fixtures/junit-formatter/issue_1149.bats @@ -0,0 +1,12 @@ +#!/usr/bin/env bats + +# shellcheck disable=SC2034 +BATS_TEST_RETRIES=1 + +@test "test fail" { + false +} + +@test "test foobar" { + false +} diff --git a/test/junit-formatter.bats b/test/junit-formatter.bats index a81b111b9d..767464322d 100644 --- a/test/junit-formatter.bats +++ b/test/junit-formatter.bats @@ -9,7 +9,7 @@ TESTSUITES_REGEX="" @test "junit formatter with skipped test does not fail" { reentrant_run bats --formatter junit "$FIXTURE_ROOT/skipped.bats" - echo "$output" + [[ $status -eq 0 ]] [[ "${lines[0]}" == '' ]] @@ -52,7 +52,6 @@ TESTSUITES_REGEX="" esac reentrant_run bats --formatter junit "$TEST_FILE_PATH" - echo "$output" [[ "${lines[2]}" == "" ]] [[ "${lines[3]}" == " " ]] [[ "${lines[4]}" == " " @test "junit formatter: test suites" { reentrant_run bats --formatter junit "$FIXTURE_ROOT/suite/" - echo "$output" [[ "${lines[0]}" == '' ]] [[ "${lines[1]}" == *"" @test "junit formatter: test suites relative path" { cd "$FIXTURE_ROOT" reentrant_run bats --formatter junit "suite/" - echo "$output" [[ "${lines[0]}" == '' ]] [[ "${lines[1]}" == *"" @test "junit formatter: files with the same name are distinguishable" { reentrant_run bats --formatter junit -r "$FIXTURE_ROOT/duplicate/" - echo "$output" - + [[ "${lines[2]}" == *"" @test "junit formatter as report formatter creates report.xml" { cd "$BATS_TEST_TMPDIR" # don't litter sources with output files reentrant_run bats --report-formatter junit "$FIXTURE_ROOT/suite/" - echo "$output" + echo "$output" # duplicate for later comparison + [[ -e "report.xml" ]] run cat "report.xml" - echo "$output" + [[ "${lines[2]}" == *"" @test "junit does not mark tests with FD 3 output as failed (issue #360)" { reentrant_run bats --formatter junit "$FIXTURE_ROOT/issue_360.bats" - echo "$output" - [[ "${lines[2]}" == '' ]] [[ "${lines[3]}" == ' ' ]] # only the outputs on FD3 should be visible on a successful test @@ -158,3 +153,21 @@ TESTSUITES_REGEX="" reentrant_run -1 --separate-stderr bats --formatter junit "$FIXTURE_ROOT/../file_setup_teardown/setup_file_failed.bats" [ "${stderr}" == "" ] } + +@test "junit outputs status of last completed test when a test is retried (issue #1149)" { + bats_require_minimum_version 1.8.0 + reentrant_run bats --formatter junit "$FIXTURE_ROOT/issue_1149.bats" + + [[ "${lines[2]}" == '' ]] + # The first failing (and retried) test has one entry, as expected + [[ "${lines[3]}" == ' ' ]] + [[ "${lines[4]}" == " (in test file $RELATIVE_FIXTURE_ROOT/issue_1149.bats, line 7)" ]] + [[ "${lines[5]}" == ' `false' failed' ]] + [[ "${lines[6]}" == ' ' ]] + # Second failing test (also retried) should also only have one entry, and that includes the failure message + [[ "${lines[7]}" == ' ' ]] + [[ "${lines[8]}" == " (in test file $RELATIVE_FIXTURE_ROOT/issue_1149.bats, line 11)" ]] + [[ "${lines[9]}" == ' `false' failed' ]] + [[ "${lines[10]}" == ' ' ]] + [[ "${lines[11]}" == '' ]] +}