Skip to content

formatter: make JUnit error testcase names unique - #2592

Merged
bendrucker merged 1 commit into
terraform-linters:masterfrom
Kunalbehbud:fix/junit-unique-error-names
Jul 24, 2026
Merged

formatter: make JUnit error testcase names unique#2592
bendrucker merged 1 commit into
terraform-linters:masterfrom
Kunalbehbud:fix/junit-unique-error-names

Conversation

@Kunalbehbud

Copy link
Copy Markdown
Contributor

Fixes #1608

Problem

#2538 made issue testcase names unique by including the range, but the error testcases appended after them still use the bare diagnostic summary. Multiple diagnostics sharing a summary — e.g. the same Unsupported argument error on two different lines — still produce duplicate <testcase> names inside the same <testsuite>, which JUnit consumers key on.

This is exactly the gap called out in the review of #2522:

junitErrors sets Name: diag.Summary directly, so multiple diagnostics sharing a summary (e.g. two "Unsupported argument" errors on different lines) still produce duplicate <testcase> names in the same <testsuite> (#1608).

and:

this should cover errors too, then LGTM

Change

Include the diagnostic range in the error testcase name, mirroring the issue-testcase naming from #2538 (<summary> <range>, via the existing nil-safe diagRange). The application_error singleton case is untouched.

One edge worth noting: two subject-less diagnostics with an identical summary would still collide (both synthesize the empty range :0,0-0). That mirrors the pre-#2538 state for issues and seems acceptable for a case that can't point at a location — happy to add a positional suffix there if you'd prefer.

Tests

  • Updated the existing "diagnostics without subject" golden output for the new name.
  • Added a "diagnostics with the same summary" case: two diagnostics sharing a summary on different lines now produce unique <testcase> names.
go test ./formatter/ -run Test_junitPrint

@Kunalbehbud

Copy link
Copy Markdown
Contributor Author

The build job failures here are the attestation panic from #2591Test_Install_withAttestations crashes on GitHub's new bundle_url responses, unrelated to this formatter change. Proposed a fix in #2593; happy to rebase this branch to re-run CI once that lands.

junitErrors used the bare diagnostic summary as the testcase name, so
multiple diagnostics sharing a summary (e.g. the same error on two
lines) produced duplicate <testcase> names in the same <testsuite>.
Include the diagnostic range in the name, mirroring how issue testcases
are named since terraform-linters#2538.

Fixes terraform-linters#1608
@Kunalbehbud
Kunalbehbud force-pushed the fix/junit-unique-error-names branch from f5a20e5 to 1579ab3 Compare July 21, 2026 10:58
@bendrucker
bendrucker merged commit aab5ecc into terraform-linters:master Jul 24, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

JUnit testcase name not unique per failure

2 participants