Issue #13109: Kill mutation for RedundantImportCheck#13249
Issue #13109: Kill mutation for RedundantImportCheck#13249romani merged 1 commit intocheckstyle:masterfrom
Conversation
|
|
||
| */ | ||
|
|
||
| import com.puppycrawl.tools.checkstyle.checks.imports.redundantimport.*; |
There was a problem hiding this comment.
Please explain why we need this import.
My concern is extension of suppression of id="noCheckstyleInInputs
There was a problem hiding this comment.
For config.xml
kevin@inspiron-15-5510:~/Desktop/check_style$ cat config.xml
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC
"-//Checkstyle//DTD Checkstyle Configuration 1.3//EN"
"https://checkstyle.org/dtds/configuration_1_3.dtd">
<module name="Checker">
<property name="charset" value="UTF-8"/>
<property name="severity" value="warning"/>
<property name="haltOnException" value="false"/>
<module name="TreeWalker">
<module name="RedundantImport"></module>
</module>
</module>
If the import is from the same package and if the name of the package has not been mentioned then we don't log a violation.
kevin@inspiron-15-5510:~/Desktop/check_style$ cat InputRedundantImportWithoutPackage.java
import com.puppycrawl.tools.checkstyle.checks.imports.redundantimport.*;
import java.io.*;
import java.lang.*; // violation 'Redundant import from the java.lang package - java.lang.*'
import java.lang.String; // violation 'Redundant import from the java.lang package - java.lang.String'
public class InputRedundantImportWithoutPackage {
}
-------------------------
kevin@inspiron-15-5510:~/Desktop/check_style$ java -jar /home/kevin/Downloads/checkstyle-10.12.0-all.jar -c config.xml InputRedundantImportWithoutPackage.java
Starting audit...
[WARN] /home/kevin/Desktop/check_style/InputRedundantImportWithoutPackage.java:3:1: Redundant import from the java.lang package - java.lang.*. [RedundantImport]
[WARN] /home/kevin/Desktop/check_style/InputRedundantImportWithoutPackage.java:4:1: Redundant import from the java.lang package - java.lang.String. [RedundantImport]
Audit done.
kevin@inspiron-15-5510:~/Desktop/check_style$
If the import is from the same package and if the name of the package is mentioned in the java file, then only we log a violation.
kevin@inspiron-15-5510:~/Desktop/check_style$ cat InputRedundantImportWithoutPackage.java
package com.puppycrawl.tools.checkstyle.checks.imports.redundantimport;
import com.puppycrawl.tools.checkstyle.checks.imports.redundantimport.*; // violation
import java.io.*;
import java.lang.*; // violation 'Redundant import from the java.lang package - java.lang.*'
import java.lang.String; // violation 'Redundant import from the java.lang package - java.lang.String'
public class InputRedundantImportWithoutPackage {
}
----------------
kevin@inspiron-15-5510:~/Desktop/check_style$ java -jar /home/kevin/Downloads/checkstyle-10.12.0-all.jar -c config.xml InputRedundantImportWithoutPackage.java
Starting audit...
[WARN] /home/kevin/Desktop/check_style/InputRedundantImportWithoutPackage.java:3:1: Redundant import from the same package - com.puppycrawl.tools.checkstyle.checks.imports.redundantimport.*. [RedundantImport]
[WARN] /home/kevin/Desktop/check_style/InputRedundantImportWithoutPackage.java:5:1: Redundant import from the java.lang package - java.lang.*. [RedundantImport]
[WARN] /home/kevin/Desktop/check_style/InputRedundantImportWithoutPackage.java:6:1: Redundant import from the java.lang package - java.lang.String. [RedundantImport]
Audit done.
know the code logic is
over here if the package name is not null and the import text is similar to the package, then only it will log the violation when the package name is null then it won't execute
know in my test case the first file execute which has declared the name of the package, so the field pkgName will updated
know when sequentially second file would be passed
where
will set to be null and in the second file I mentioned the import with a similar package name but I don't have set the name of the package, so the package is null there, so no violation is expected on that line as I mentioned above.
but if we remove pkgName = null from begin tree then the code logic will continue with previously set package name so here in this file even though there is no package name but import name is similar to the package name so it will cause a violation so here the usage of pkgName=null come in usage and mutation killed which is in begin tree so there is no other possible test case other then this.
so unfortunately I have to suppress the id="noCheckstyleInInputs
else we got error of
[ERROR] [checkstyle] [ERROR] /home/kevin/Desktop/check_style/checkstyle/checkstyle/src/test/resources/com/puppycrawl/tools/checkstyle/checks/imports/redundantimport/InputRedundantImportWithoutPackage.java:7: Inputs should not reference checkstyles own files [noCheckstyleInInputs]
[INFO] ------------------------------------------------------------------------
Issue #13109: Kill mutation for RedundantImportCheck
check
https://checkstyle.org/config_imports.html#RedundantImport
Mutation
checkstyle/config/pitest-suppressions/pitest-imports-suppressions.xml
Lines 147 to 154 in 461944c
Explaintaion
Test cases added