Issue #13328: Kill mutation ImportOrderCheck #13334
Issue #13328: Kill mutation ImportOrderCheck #13334rnveach merged 1 commit intocheckstyle:masterfrom
Conversation
|
Github, generate report |
|
Github, generate report |
|
@Kevin222004 Logic looks correct to me, but to be on the safer side, please generate a report with both changes in this PR and in #13333. You can do it in a separate PR and link it back here. |
rdiachenko
left a comment
There was a problem hiding this comment.
lgtm
played with this trying multiple inputs and combinations, didn't manage to find a failure case
|
This is great example of scary update :). What if we stay on safe side with clean up of all fields in class to default state ? I know we fighting a lot on such pitest in beginTree in other Checks, and before this I was ok, and we able to find coverage. Proposal: make method Let's vote, If all agree, we can do this. |
rnveach
left a comment
There was a problem hiding this comment.
As I mentioned in discord, we have a special set of utils to kill mutations like this.
isStatefulFieldClearedDuringBeginTree
It looks like
visitToken always set the field at All that is needed is to have the field change its value using the
isStatefulFieldClearedDuringBeginTree.
|
I'd go with what @rnveach suggests instead of having pitest specific methods in the check's class. It looks clenar and avoids questions like why we have such tool related methods in the mian code. If we do introduce |
|
Ok I have updated the pr with the test case suggested at #13334 (review) |
src/test/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheckTest.java
Show resolved
Hide resolved
|
|
||
|
|
||
|
|
||
|
|
There was a problem hiding this comment.
Why are we adding empty lines to this file?
There was a problem hiding this comment.
To avoid merge Conflicts
There was a problem hiding this comment.
Is the plan to remove them at some point if we can't remove the entire file?
There was a problem hiding this comment.
Yes, If the entire file is not removed then I will update this and remove it. so at the, it looks clean
But right know in this file 4 mutations are still left which is possible to cover
Issue #13328: Kill mutation ImportOrderCheck
Check
https://checkstyle.org/checks/imports/importorder.html#ImportOrder
Mutation
checkstyle/config/pitest-suppressions/pitest-imports-suppressions.xml
Lines 57 to 64 in b8915da
Explaination
begin tree always reset data. for
lastImportStatic = falseso we need to create two input somehow lastImportStatic become true while the sequentially second file will be come in process and that is easy we only have to set last import of first file as true.lets start from visitToken
In visit token the parameter
isStaticwill check wether the current import is static or not.checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheck.java
Lines 800 to 810 in b8915da
To move further
all the condition
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheck.java
Lines 814 to 825 in b8915da
call
doVisitTokenknow our target is to check that output get affected if removelastimportStaticfrom beginTreecheckstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheck.java
Line 845 in b8915da
know in
doVisitTokenonly 2 parameter is iportant for usisStaticandpreviouscheckstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheck.java
Lines 815 to 816 in b8915da
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheck.java
Lines 818 to 820 in b8915da
because they and the reason is they are only one right know which related with
lastimportstaticand violation throwingand in the whole method previous is used only at
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheck.java
Lines 856 to 858 in b8915da
know this condition is not big deal we can execute that and if we look closure on
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheck.java
Line 923 in b8915da
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheck.java
Line 925 in b8915da
know in else either
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheck.java
Line 936 in b8915da
needs to be true or in that either
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheck.java
Lines 940 to 942 in b8915da
this is need to be true
case 1
lets see the previous first we know that we need previos true and
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheck.java
Lines 814 to 817 in b8915da
lets suppose we set option as above so previous import needs to be nonStatic and current ast need to be static so from here it is for sure that
we want previous as true
previous = trueknow suppose option is set to be true so previous value is comming from visitToken so we need top setisStatic = falseandlastimportStatic = trueso in previous file lastimportstatic needs to be non static it means false then if it already same then no need to be reset so begin tree is redundant.know lets suppose option is set to Bottom or under
checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheck.java
Lines 818 to 821 in b8915da
in this case to set previous true we need to set
lastimportstatic = truemean previous file import needs to be static and in current file ast needs to be non static it meansisStatic=fasleandisLastImport=truein this casecheckstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/ImportOrderCheck.java
Lines 856 to 858 in b8915da
this is alsosimilar if both are static
so no test cases looks possible to clear the state using input
Regression
Report-1 :- https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/920122e_2023074505/reports/diff/index.html
Report-2 :- https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/920122e_2023090228/reports/diff/index.html
Diff Regression config: https://gist.githubusercontent.com/Kevin222004/e3a00111b4bb7b8c054483466b88606d/raw/4895c88b1daf686479058c972bad0c27cd0818ef/IOC.xml
Diff Regression projects: https://gist.githubusercontent.com/Kevin222004/9600f179b602d4c971bdb0a050099005/raw/360a95ed7bb60d7a0956e531199d484c4d6f6617/test-projects.properties
Report label: new-Regression-1