Skip to content

Conversation

@vietcgi
Copy link

@vietcgi vietcgi commented Oct 24, 2025

Fixes #37801

When test files have file-level error diagnostics (e.g., invalid variable references), tests are skipped but the JUnit XML output doesn't include the error details. This causes CI/CD pipelines to miss failures.

This PR adds file-level error diagnostics to the skipped element body, ensuring errors are visible in JUnit XML reports.

Changes:

  • Modified skipDetails to check for file-level error diagnostics
  • Added diagnostic details to skipped test output when file errors exist
  • Added test coverage for file-level error scenarios

Impact:
Pipelines checking JUnit XML for errors will now correctly detect file-level validation failures.

@vietcgi vietcgi requested a review from a team as a code owner October 24, 2025 04:19
@hashicorp-cla-app
Copy link

hashicorp-cla-app bot commented Oct 24, 2025

CLA assistant check
All committers have signed the CLA.

@vietcgi vietcgi force-pushed the fix-junit-file-errors-37801 branch from e4912fa to a644a1d Compare October 24, 2025 04:27
@vietcgi vietcgi force-pushed the fix-junit-file-errors-37801 branch from a644a1d to f02f553 Compare October 24, 2025 04:30
"Invalid reference",
"You can only reference global variables within the test file variables block.",
))
file.AppendDiagnostics(diags)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Copy link
Member

@SarahFrench SarahFrench left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @vietcgi, thank you for opening this PR and including test coverage of the change 🙌🏻

I was looking at this resource on GitHub the describes the JUnit XML specification and thought that it could be useful to surface the file-level error via a <system-err> element nested under <testsuite>, as the test suite concept maps to a single test file. This could be in addition to logging the error in the <skipped> element, or replace that approach.

Do you have any preferences either way? I haven't used JUnit XML output in production myself so I'm unfamiliar with how the XML is consumed by commercial tools and whether one approach fits better with those tools versus the other approach, or not. One benefit I can see is that users could grep for <system-err> being present, similar to the example shared here, instead of needing to inspect the error message contents.

Just an FYI, implementing use of <system-err> would be a bit more complex but could resemble the existing approach used with enc.EncodeElement and the testSuite struct.

@vietcgi
Copy link
Author

vietcgi commented Oct 24, 2025

Hi @SarahFrench

Good call on the <system-err> suggestion, that's cleaner.

You're right that file-level errors belong at the suite level, not testcase level. When the file itself is broken, it's not that the tests failed, it's that they couldn't even run.

I'll move the diagnostic details to a suite-level <system-err> element (after all testcases) and keep the skipped elements simple. That way CI tools can just grep for <system-err> instead of parsing message content.

The updated structure will look like:

<testsuite name="file.tftest.hcl" tests="1" skipped="1" failures="0" errors="0">
  <testcase name="my_test" classname="file.tftest.hcl">
    <skipped message="Skipped due to file-level errors"></skipped>
  </testcase>
  <system-err><![CDATA[
Error: Invalid reference
...
]]></system-err>
</testsuite>

Does that direction work for you?

@SarahFrench
Copy link
Member

The updated structure will look like:

<testsuite name="file.tftest.hcl" tests="1" skipped="1" failures="0" errors="0">
  <testcase name="my_test" classname="file.tftest.hcl">
    <skipped message="Skipped due to file-level errors"></skipped>
  </testcase>
  <system-err><![CDATA[
Error: Invalid reference
...
]]></system-err>
</testsuite>

Does that direction work for you?

That looks good to me, thanks for being open to the feedback!

@vietcgi
Copy link
Author

vietcgi commented Oct 24, 2025

it's good now @SarahFrench :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Errors in test are skipped vs failed since 1.13.0

2 participants