From 317ac87d50d793c1c4e359c3ea8f22f0b5cf2afd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Weinehall?= Date: Wed, 1 Oct 2025 12:51:52 +0200 Subject: [PATCH 1/4] Fix bats-core#1149 Make sure to clear result state between different tests --- docs/CHANGELOG.md | 1 + libexec/bats-core/bats-format-junit | 1 + test/fixtures/junit-formatter/issue_1149.bats | 12 +++++++++++ test/junit-formatter.bats | 20 +++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 test/fixtures/junit-formatter/issue_1149.bats diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 3838c4fb7d..2a4a257e43 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -22,6 +22,7 @@ The format is based on [Keep a Changelog][kac] and this project adheres to * junit: XML escape fully removes ANSI sequences, e.g. color codes, cursor movements (#1103) * remove deprecated windows runner (#1119) * renamed `docker-compose.yml` to `compose.yaml` (#1128) +* junit: fix retried tests being listed multiple times (#1149) ### Documentation 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..9d5491881e 100644 --- a/test/junit-formatter.bats +++ b/test/junit-formatter.bats @@ -158,3 +158,23 @@ 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" + + echo "$output" + + [[ "${lines[2]}" == '' ]] + # The first failing (and retried) test has one entry, as expected + [[ "${lines[3]}" == ' ' ]] + [[ "${lines[4]}" == ' (in test file test/fixtures/junit-formatter/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 test/fixtures/junit-formatter/issue_1149.bats, line 11)' ]] + [[ "${lines[9]}" == ' `false' failed' ]] + [[ "${lines[10]}" == ' ' ]] + [[ "${lines[11]}" == '' ]] +} From 0c875c4c3c77b52bc389661d1aef7c109550f70a Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sat, 11 Oct 2025 23:29:25 +0200 Subject: [PATCH 2/4] chore: remove unnecessary echo $output --- test/junit-formatter.bats | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/test/junit-formatter.bats b/test/junit-formatter.bats index 9d5491881e..9949c2b49b 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 @@ -163,8 +158,6 @@ TESTSUITES_REGEX="" bats_require_minimum_version 1.8.0 reentrant_run bats --formatter junit "$FIXTURE_ROOT/issue_1149.bats" - echo "$output" - [[ "${lines[2]}" == '' ]] # The first failing (and retried) test has one entry, as expected [[ "${lines[3]}" == ' ' ]] From d8d1b3d435d96a6d06a4dc67cd555fbc65eec898 Mon Sep 17 00:00:00 2001 From: Martin Schulze <37703201+martin-schulze-vireso@users.noreply.github.com> Date: Sat, 11 Oct 2025 23:30:24 +0200 Subject: [PATCH 3/4] fix: path in test expectation --- test/junit-formatter.bats | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/junit-formatter.bats b/test/junit-formatter.bats index 9949c2b49b..767464322d 100644 --- a/test/junit-formatter.bats +++ b/test/junit-formatter.bats @@ -161,12 +161,12 @@ TESTSUITES_REGEX="" [[ "${lines[2]}" == '' ]] # The first failing (and retried) test has one entry, as expected [[ "${lines[3]}" == ' ' ]] - [[ "${lines[4]}" == ' (in test file test/fixtures/junit-formatter/issue_1149.bats, line 7)' ]] + [[ "${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 test/fixtures/junit-formatter/issue_1149.bats, line 11)' ]] + [[ "${lines[8]}" == " (in test file $RELATIVE_FIXTURE_ROOT/issue_1149.bats, line 11)" ]] [[ "${lines[9]}" == ' `false' failed' ]] [[ "${lines[10]}" == ' ' ]] [[ "${lines[11]}" == '' ]] From 11cb4722c4a58985a8092eeadefbb9d242555133 Mon Sep 17 00:00:00 2001 From: Martin Schulze Date: Sat, 11 Oct 2025 23:32:58 +0200 Subject: [PATCH 4/4] fix changelog entry --- docs/CHANGELOG.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 2a4a257e43..c84a1d0c6f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -19,10 +19,11 @@ 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) -* junit: fix retried tests being listed multiple times (#1149) ### Documentation