Skip to content

Issue #18027: Resolve pitest for formatter count in CheckstyleAntTask#18210

Merged
romani merged 1 commit into
checkstyle:masterfrom
vivek-0509:killAntPitestSuppressionFormaterCount
Nov 30, 2025
Merged

Issue #18027: Resolve pitest for formatter count in CheckstyleAntTask#18210
romani merged 1 commit into
checkstyle:masterfrom
vivek-0509:killAntPitestSuppressionFormaterCount

Conversation

@vivek-0509

@vivek-0509 vivek-0509 commented Nov 29, 2025

Copy link
Copy Markdown
Member

Issue #18027:

Added test to kill mutant in CheckstyleAntTask.getListeners()

This PR adds a test case to kill a mutant that removes the call to formatters.size() in CheckstyleAntTask.getListeners() method.

Test Implementation:

  • Added testMultipleFormattersProduceOutputs() method
  • Creates two formatters with separate output files
  • Verifies both formatters produce non-empty output files
  • If the mutant is present (formatters.size() removed), formatterCount would be 1 instead of 2, causing only the first formatter to be processed and the second file to be missing/empty, causing the test to fail

Helper Method:

  • Added createPlainFormatter() helper method for reusability

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

items:

Comment on lines +1006 to +1009
final File firstOutput = new File("target/ant_task_multi_formatter_1.txt");
final File secondOutput = new File("target/ant_task_multi_formatter_2.txt");
Files.deleteIfExists(firstOutput.toPath());
Files.deleteIfExists(secondOutput.toPath());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Thank you for the suggestion. I tried using Files.createTempFile(temporaryFolder.toPath(), ...), but it fails the forbiddenapis check. I noticed MainTest.java uses this pattern, but it's excluded from forbiddenapis checks
Since CheckstyleAntTaskTest isn't excluded, I've used new File(temporaryFolder, "filename.txt") instead, which passes the check and works correctly. Happy to adjust if you prefer a different approach.

@vivek-0509 vivek-0509 force-pushed the killAntPitestSuppressionFormaterCount branch from b8ea1b6 to fe71838 Compare November 30, 2025 18:29
@vivek-0509 vivek-0509 force-pushed the killAntPitestSuppressionFormaterCount branch from fe71838 to 22f34aa Compare November 30, 2025 18:36

@romani romani left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks a lot.

Next time please share violation error message, it will helps to confirm it.

@romani romani merged commit 6cf8a40 into checkstyle:master Nov 30, 2025
122 checks passed
@vivek-0509

Copy link
Copy Markdown
Member Author

Sure will keep in mind from the next time.

@vivek-0509 vivek-0509 deleted the killAntPitestSuppressionFormaterCount branch December 9, 2025 16:39
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.

2 participants