Skip to content

Commit

Permalink
Issue #12333: Resolve pitest for profile metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin222004 authored and nrmancuso committed Dec 29, 2022
1 parent bc5f1d1 commit 45bd845
Show file tree
Hide file tree
Showing 3 changed files with 131 additions and 45 deletions.
45 changes: 0 additions & 45 deletions config/pitest-suppressions/pitest-metrics-suppressions.xml
Expand Up @@ -99,51 +99,6 @@
<lineContent>private int recordMaximum = RECORD_MAX_NCSS;</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>JavaNCSSCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.metrics.JavaNCSSCheck</mutatedClass>
<mutatedMethod>isExpressionCountable</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_2</mutator>
<description>RemoveSwitch 2 (case value 83)</description>
<lineContent>switch (parentType) {</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>JavaNCSSCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.metrics.JavaNCSSCheck</mutatedClass>
<mutatedMethod>isExpressionCountable</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_3</mutator>
<description>RemoveSwitch 3 (case value 84)</description>
<lineContent>switch (parentType) {</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>JavaNCSSCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.metrics.JavaNCSSCheck</mutatedClass>
<mutatedMethod>isExpressionCountable</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_4</mutator>
<description>RemoveSwitch 4 (case value 85)</description>
<lineContent>switch (parentType) {</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>JavaNCSSCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.metrics.JavaNCSSCheck</mutatedClass>
<mutatedMethod>isExpressionCountable</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_5</mutator>
<description>RemoveSwitch 5 (case value 91)</description>
<lineContent>switch (parentType) {</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>JavaNCSSCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.metrics.JavaNCSSCheck</mutatedClass>
<mutatedMethod>isExpressionCountable</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_6</mutator>
<description>RemoveSwitch 6 (case value 92)</description>
<lineContent>switch (parentType) {</lineContent>
</mutation>

<mutation unstable="false">
<sourceFile>NPathComplexityCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.metrics.NPathComplexityCheck</mutatedClass>
Expand Down
Expand Up @@ -106,6 +106,17 @@ public void testRecordsAndCompactCtors() throws Exception {
expected);
}

@Test
public void testForMutation() throws Exception {
final String[] expected = {
"13:1: " + getCheckMessage(MSG_CLASS, 84, 80),
"16:5: " + getCheckMessage(MSG_CLASS, 83, 80),
};
verifyWithInlineConfigParser(
getPath("InputJavaNCSSResolveMutation.java"),
expected);
}

@Test
public void testGetAcceptableTokens() {
final JavaNCSSCheck javaNcssCheckObj = new JavaNCSSCheck();
Expand Down
@@ -0,0 +1,120 @@
/*
JavaNCSS
methodMaximum = (default)50
classMaximum = 80
fileMaximum = (default)2000
recordMaximum = (default)150
*/

package com.puppycrawl.tools.checkstyle.checks.metrics.javancss;

public class InputJavaNCSSResolveMutation {
// violation above 'NCSS for this class is 84 (max allowed is 80)'

public static class Some // violation 'NCSS for this class is 83 (max allowed is 80)'
{
static class SomeClass {
boolean flag = true;

static boolean test(boolean k) {
return k;
}
}

private int foo() {
if (SomeClass.test(true)) return 4;
return 0;
}

private int foo1() {
return 4;
}

private int foo2() {
if (SomeClass.test(true))
return 4;
return 0;
}

private int foo3() {
if (SomeClass.test(true)) if (true) return 4;
return 0;
}

private void foo(Object o) {
if (o != null) this.notify();
}

private void foo2(Object o) {
if (o != null)
this.notify();
}

private void loopTest(Object o) {
while (o != null) {
this.notify();
}
while (o != null)
this.notify();
while (o != null) this.notify();
do {
this.notify();
} while (o != null);
do this.notify(); while (o != null);
do
this.notify();
while (o != null);
for (; ; )
break;
for (; ; ) break;
for (int i = 0; i < 10; i++) {
this.notify();
}
for (int i = 0; i < 10; i++)
this.notify();
for (int i = 0; ; ) this.notify();
}

private int getSmth(int num) {
int counter = 0;
switch (num) {
case 1:
counter++;
break;
case 2: // ok
counter += 2;
break;
case 3: // ok
counter += 3;
break;
case 6:
counter += 10;
break;
default:
counter = 100;
break;
}
return counter;
}

private void testElse(int k) {
if (k == 4) System.identityHashCode("yes");
else System.identityHashCode("no");
for (; ; ) ;
}

void enhancedForLoop(int[] array) {
for (int value : array) return;
}

private void forEachLoop() {
for (String s : new String[]{""}) break;
for (String s : new String[]{""})
break;
for (; ; )
;
}
}
}

0 comments on commit 45bd845

Please sign in to comment.