Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for transforming Checkstyle XML output to JUnit XML #283

Merged
merged 12 commits into from
Aug 16, 2024

Conversation

fzakaria
Copy link
Contributor

@fzakaria fzakaria commented Jun 18, 2024

Bazel will natively create a test.xml for all test runners if they do not create one themselves.

For the checkstyle test-runner it would create a test.xml that captures the system-out.

<testsuites>
  <testsuite name="server-common/server-common-checkstyleexec" tests="1" failures="0" errors="1">
    <testcase name="server-common/server-common-checkstyleexec" status="run" duration="5" time="5"><error message="exited with error code 1"></error></testcase>
      <system-out>
Generated test.log (if the file is not UTF-8, then this may be unreadable):
<![CDATA[exec ${PAGER:-/usr/bin/less} "$0" || exit 1
Executing tests from //server-common:server-common-checkstyle
-----------------------------------------------------------------------------
Checkstyle ends with 1 errors.
Starting audit...
[ERROR] server-common/src/main/java/org/apache/kafka/queue/KafkaEventQueue.java:30:1: Disallowed import - io.confluent.kafka.util.OpenTelemetryManager. [ImportControl]
Audit done.]]>
      </system-out>
    </testsuite>
</testsuites>

JUnit is a well establish format and well known by many CI programs.
Having the checkstyle rule itself create a more curated JUnit XML file is in the user's best interest.

In this PR, we modify the checkstyle rules to emit a test.xml itself, stopping Bazel from implicitly doing so.
We have checkstyle emit the XML format always and then use a very minimal Java tool and a provided default XLST (XML stylesheet) to transform the Checkstyle XML to one following JUnit's XML specification.

<?xml version="1.0" encoding="UTF-8"?>
<testsuites>
<testsuite package="Checkstyle" name="src/main/java/io/confluent/utils/HelloWorldUtils.java" tests="2" errors="2">

<testcase name="com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck" classname="src/main/java/io/confluent/utils/HelloWorldUtils.java">
    <error type="com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck" message="Line 3: Using the '.*' form of import should be avoided - java.io.*."/>
</testcase>

<testcase name="com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck" classname="src/main/java/io/confluent/utils/HelloWorldUtils.java">
    <error type="com.puppycrawl.tools.checkstyle.checks.javadoc.MissingJavadocMethodCheck" message="Line 7: Missing a Javadoc comment."/>
</testcase>

</testsuite>
</testsuites>

@fzakaria fzakaria marked this pull request as ready for review June 18, 2024 21:47
@fzakaria
Copy link
Contributor Author

Looks like the previous result failed on some format errors; I've ran the formatters buildifier and google-java-format

Copy link
Collaborator

@shs96c shs96c left a comment

Choose a reason for hiding this comment

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

Apologies for taking so long to review this: we needed to fix the CI tests first, and that took longer than expected. Thank you for your patience.

@shs96c
Copy link
Collaborator

shs96c commented Jul 12, 2024

You may need to rebase past e736106 and re-run the ./tools/format.sh script to get a clean test run.

@fzakaria
Copy link
Contributor Author

@shs96c I rebased and ran the formatter again.
It forces the names of my target so I needed to change it for that (seems a bit over-zealous but /shrug)

Also, I think there is an escape impurity.
I had to do CC=$(which clang) ./tools/format.sh since my cc was set to gcc and it would give me the error:

gcc: error: unrecognized command line option '-fobjc-link-runtime'

@fzakaria
Copy link
Contributor Author

The windows issue looks transient.

@fzakaria fzakaria requested a review from shs96c July 21, 2024 17:47
@gibfahn gibfahn closed this Aug 16, 2024
@gibfahn gibfahn reopened this Aug 16, 2024
@gibfahn
Copy link
Collaborator

gibfahn commented Aug 16, 2024

(retrying the tests)

@shs96c shs96c merged commit e0d10b4 into bazel-contrib:main Aug 16, 2024
15 of 16 checks passed
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.

3 participants