Skip to content

Commit

Permalink
Issue checkstyle#12943: Resolve pitest suppression for FallThroughCheck
Browse files Browse the repository at this point in the history
  • Loading branch information
ShivamPandey00 authored and romani committed Apr 18, 2023
1 parent 673e86a commit ba6a74d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 9 deletions.
9 changes: 0 additions & 9 deletions config/pitest-suppressions/pitest-coding-2-suppressions.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<suppressedMutations>
<mutation unstable="false">
<sourceFile>FallThroughCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.coding.FallThroughCheck</mutatedClass>
<mutatedMethod>checkTry</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.NonVoidMethodCallMutator</mutator>
<description>removed call to com/puppycrawl/tools/checkstyle/api/DetailAST::getNextSibling</description>
<lineContent>catchStmt = catchStmt.getNextSibling();</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>FallThroughCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.coding.FallThroughCheck</mutatedClass>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,14 @@ public void testTryWithResources() throws Exception {
expected);
}

@Test
public void testTryCatchInSwitch() throws Exception {
final String[] expected = {
"37:13: " + getCheckMessage(MSG_FALL_THROUGH),
};
verifyWithInlineConfigParser(getPath("InputFallThroughTryCatchInSwitch.java"), expected);
}

@Test
public void testStringSwitch() throws Exception {
final String[] expected = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
FallThrough
checkLastCaseGroup = (default)false
reliefPattern = (default)falls?[ -]?thr(u|ough)
*/

package com.puppycrawl.tools.checkstyle.checks.coding.fallthrough;

import java.io.IOException;

public class InputFallThroughTryCatchInSwitch {
public int foo(int x) {
switch (x) {
case 1:
try {
// Some code
throw new IOException("Exception occurred.");
} catch (IOException e) {
// Some code
if (e.getMessage().contains("Exception")) {
break;
} else {
return 0;
}
} catch (Exception e) {
// Some code
for (int i = 0; i < 3; i++) {
if (i == 1) {
break;
}
}
} finally {
// Some code
}
default: // violation 'Fall through from previous branch of the switch statement.'
// Some code
}

return 0;
}
}

0 comments on commit ba6a74d

Please sign in to comment.