diff --git a/config/pitest-suppressions/pitest-coding-2-suppressions.xml b/config/pitest-suppressions/pitest-coding-2-suppressions.xml index 06586a30ffb..f270c9ecfee 100644 --- a/config/pitest-suppressions/pitest-coding-2-suppressions.xml +++ b/config/pitest-suppressions/pitest-coding-2-suppressions.xml @@ -153,204 +153,6 @@ this.query = query; - - ModifiedControlVariableCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck - leaveToken - org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_10 - RemoveSwitch 10 (case value 102) - switch (ast.getType()) { - - - - ModifiedControlVariableCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck - leaveToken - org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_11 - RemoveSwitch 11 (case value 103) - switch (ast.getType()) { - - - - ModifiedControlVariableCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck - leaveToken - org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_12 - RemoveSwitch 12 (case value 104) - switch (ast.getType()) { - - - - ModifiedControlVariableCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck - leaveToken - org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_13 - RemoveSwitch 13 (case value 105) - switch (ast.getType()) { - - - - ModifiedControlVariableCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck - leaveToken - org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_14 - RemoveSwitch 14 (case value 106) - switch (ast.getType()) { - - - - ModifiedControlVariableCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck - leaveToken - org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_15 - RemoveSwitch 15 (case value 107) - switch (ast.getType()) { - - - - ModifiedControlVariableCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck - leaveToken - org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_16 - RemoveSwitch 16 (case value 108) - switch (ast.getType()) { - - - - ModifiedControlVariableCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck - leaveToken - org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_2 - RemoveSwitch 2 (case value 26) - switch (ast.getType()) { - - - - ModifiedControlVariableCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck - leaveToken - org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_7 - RemoveSwitch 7 (case value 99) - switch (ast.getType()) { - - - - ModifiedControlVariableCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck - leaveToken - org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_8 - RemoveSwitch 8 (case value 100) - switch (ast.getType()) { - - - - ModifiedControlVariableCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck - leaveToken - org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_9 - RemoveSwitch 9 (case value 101) - switch (ast.getType()) { - - - - ModifiedControlVariableCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck - visitToken - org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_10 - RemoveSwitch 10 (case value 102) - switch (ast.getType()) { - - - - ModifiedControlVariableCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck - visitToken - org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_11 - RemoveSwitch 11 (case value 103) - switch (ast.getType()) { - - - - ModifiedControlVariableCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck - visitToken - org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_12 - RemoveSwitch 12 (case value 104) - switch (ast.getType()) { - - - - ModifiedControlVariableCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck - visitToken - org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_13 - RemoveSwitch 13 (case value 105) - switch (ast.getType()) { - - - - ModifiedControlVariableCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck - visitToken - org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_14 - RemoveSwitch 14 (case value 106) - switch (ast.getType()) { - - - - ModifiedControlVariableCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck - visitToken - org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_15 - RemoveSwitch 15 (case value 107) - switch (ast.getType()) { - - - - ModifiedControlVariableCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck - visitToken - org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_16 - RemoveSwitch 16 (case value 108) - switch (ast.getType()) { - - - - ModifiedControlVariableCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck - visitToken - org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_2 - RemoveSwitch 2 (case value 26) - switch (ast.getType()) { - - - - ModifiedControlVariableCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck - visitToken - org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_7 - RemoveSwitch 7 (case value 99) - switch (ast.getType()) { - - - - ModifiedControlVariableCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck - visitToken - org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_8 - RemoveSwitch 8 (case value 100) - switch (ast.getType()) { - - - - ModifiedControlVariableCheck.java - com.puppycrawl.tools.checkstyle.checks.coding.ModifiedControlVariableCheck - visitToken - org.pitest.mutationtest.engine.gregor.mutators.experimental.RemoveSwitchMutator_9 - RemoveSwitch 9 (case value 101) - switch (ast.getType()) { - - MultipleStringLiteralsCheck.java com.puppycrawl.tools.checkstyle.checks.coding.MultipleStringLiteralsCheck diff --git a/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/ModifiedControlVariableCheckTest.java b/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/ModifiedControlVariableCheckTest.java index c20df91a531..ba71f5f167e 100644 --- a/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/ModifiedControlVariableCheckTest.java +++ b/src/test/java/com/puppycrawl/tools/checkstyle/checks/coding/ModifiedControlVariableCheckTest.java @@ -131,6 +131,38 @@ public void testImproperToken() { } } + @Test + public void testMutation() throws Exception { + + final String[] expected = { + "15:15: " + getCheckMessage(MSG_KEY, "i"), + "16:15: " + getCheckMessage(MSG_KEY, "k"), + "23:15: " + getCheckMessage(MSG_KEY, "i"), + "24:15: " + getCheckMessage(MSG_KEY, "k"), + "31:15: " + getCheckMessage(MSG_KEY, "i"), + "32:15: " + getCheckMessage(MSG_KEY, "k"), + "39:15: " + getCheckMessage(MSG_KEY, "i"), + "40:15: " + getCheckMessage(MSG_KEY, "k"), + "47:15: " + getCheckMessage(MSG_KEY, "i"), + "48:15: " + getCheckMessage(MSG_KEY, "k"), + "55:15: " + getCheckMessage(MSG_KEY, "i"), + "56:15: " + getCheckMessage(MSG_KEY, "k"), + "63:15: " + getCheckMessage(MSG_KEY, "i"), + "64:15: " + getCheckMessage(MSG_KEY, "k"), + "71:15: " + getCheckMessage(MSG_KEY, "i"), + "72:15: " + getCheckMessage(MSG_KEY, "k"), + "79:15: " + getCheckMessage(MSG_KEY, "i"), + "80:15: " + getCheckMessage(MSG_KEY, "k"), + "87:15: " + getCheckMessage(MSG_KEY, "i"), + "88:15: " + getCheckMessage(MSG_KEY, "k"), + "95:14: " + getCheckMessage(MSG_KEY, "i"), + "96:14: " + getCheckMessage(MSG_KEY, "k"), + }; + verifyWithInlineConfigParser( + getPath("InputModifiedControlVariableKillMutation.java"), + expected); + } + /** * We cannot reproduce situation when visitToken is called and leaveToken is not. * So, we have to use reflection to be sure that even in such situation diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/InputModifiedControlVariableKillMutation.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/InputModifiedControlVariableKillMutation.java new file mode 100644 index 00000000000..5a789c300fd --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/modifiedcontrolvariable/InputModifiedControlVariableKillMutation.java @@ -0,0 +1,99 @@ +/* +ModifiedControlVariable +skipEnhancedForLoopVariable = (default)false + + +*/ + +package com.puppycrawl.tools.checkstyle.checks.coding.modifiedcontrolvariable; + +public class InputModifiedControlVariableKillMutation { + + // case value 99 --> MINUS_ASSIGN + void method() { + for (int i=0,k=0; i<10 && k < 10; ++i,++k) { + i -= 3; // violation + k -= 4; // violation + } + } + + // case value 100 --> STAR_ASSIGN + void method1() { + for (int i=0,k=0; i<10 && k < 10; ++i,++k) { + i *= 3; // violation + k *= 4; // violation + } + } + +// case value 101 --> DIV_ASSIGN + void method2() { + for (int i=0,k=0; i<10 && k < 10; ++i,++k) { + i /= 3; // violation + k /= 4; // violation + } + } + +// case value 102 --> MOD_ASSIGN + void method3() { + for (int i=0,k=0; i<10 && k < 10; ++i,++k) { + i %= 3; // violation + k %= 4; // violation + } + } + +// case value 103 --> SR_ASSIGN + void method4() { + for (int i=0,k=0; i<10 && k < 10; ++i,++k) { + i >>= 3; // violation + k >>= 4; // violation + } + } + +// case value 104 --> BSR_ASSIGN + void method5() { + for (int i=0,k=0; i<10 && k < 10; ++i,++k) { + i >>>= 3; // violation + k >>>= 4; // violation + } + } + +// case value 105 --> SL_ASSIGN + void method6() { + for (int i=0,k=0; i<10 && k < 10; ++i,++k) { + i <<= 3; // violation + k <<= 4; // violation + } + } + +// case value 106 --> BAND_ASSIGN + void method7() { + for (int i=0,k=0; i<10 && k < 10; ++i,++k) { + i &= 3; // violation + k &= 4; // violation + } + } + +// case value 107 --> BXOR_ASSIGN + void method8() { + for (int i=0,k=0; i<10 && k < 10; ++i,++k) { + i ^= 3; // violation + k ^= 4; // violation + } + } + +// case value 108 --> BOR_ASSIGN + void method9() { + for (int i=0,k=0; i<10 && k < 10; ++i,++k) { + i |= 3; // violation + k |= 4; // violation + } + } + +// case value 26 --> BOR_ASSIGN + void method10() { + for (int i=0,k=0; i<10 && k < 10; ++i,++k) { + i--; // violation + k--; // violation + } + } +}