Skip to content

Commit

Permalink
Issue checkstyle#14019: Kill mutation on SuppressionXpathSingleFilter
Browse files Browse the repository at this point in the history
  • Loading branch information
akankshat05 authored and romani committed Nov 17, 2024
1 parent b4d9ba5 commit e523f1c
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 9 deletions.
9 changes: 0 additions & 9 deletions config/pitest-suppressions/pitest-filters-suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -162,15 +162,6 @@
<lineContent>tagMessageRegexp = null;</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>SuppressionXpathSingleFilter.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.filters.SuppressionXpathSingleFilter</mutatedClass>
<mutatedMethod>setMessage</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.MemberVariableMutator</mutator>
<description>Removed assignment to member variable message</description>
<lineContent>this.message = null;</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>XpathFilterElement.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.filters.XpathFilterElement</mutatedClass>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,47 @@ public void testUpdateFilterChecksSettingInRunTime() throws Exception {
.isTrue();
}

/**
* This test is required to cover pitest mutation
* for reset of 'message' field in SuppressionXpathSingleFilter.
* This not possible to reproduce by natural execution of Checkstyle
* as config is never changed in runtime.
* Projects that use us by api can reproduce this case.
* We need to allow users to reset module property to default state.
*
* @throws Exception when there is problem to load Input file
*/

@Test
public void testSetMessageHandlesNullCorrectly() throws Exception {
final File file = new File(getPath("InputSuppressionXpathSingleFilterComplexQuery.java"));

final SuppressionXpathSingleFilter filter = new SuppressionXpathSingleFilter();
filter.setMessage("MagicNumber");
filter.finishLocalSetup();

final Violation violation = new Violation(27, 21, TokenTypes.NUM_DOUBLE, "",
"", null, null, null,
MagicNumberCheck.class, "MagicNumber");

final FileContents fileContents =
new FileContents(new FileText(file, StandardCharsets.UTF_8.name()));

final TreeWalkerAuditEvent ev = new TreeWalkerAuditEvent(fileContents, file.getName(),
violation, JavaParser.parseFile(file, JavaParser.Options.WITHOUT_COMMENTS));

assertWithMessage("match is expected as 'message' is set")
.that(filter.accept(ev))
.isFalse();

filter.setMessage(null);
filter.finishLocalSetup();

assertWithMessage("no match is expected as whole filter is defaulted (empty)")
.that(filter.accept(ev))
.isTrue();
}

private static SuppressionXpathSingleFilter createSuppressionXpathSingleFilter(
String files, String checks, String message, String moduleId, String query) {
final SuppressionXpathSingleFilter filter = new SuppressionXpathSingleFilter();
Expand Down

0 comments on commit e523f1c

Please sign in to comment.