Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #12326: Resolve Pitest suppression for AccessModifierOption #12340

Merged
merged 1 commit into from Nov 23, 2022

Conversation

ThatSneakyCoder
Copy link
Contributor

@ThatSneakyCoder ThatSneakyCoder commented Oct 23, 2022

Referencing from #12326
also related to #12341

image

@ThatSneakyCoder
Copy link
Contributor Author

Github, generate report

@romani
Copy link
Member

romani commented Oct 23, 2022

We do not allow pure Junit test methods anymore.
Please make coverage by Input files and real Checks.

@ThatSneakyCoder
Copy link
Contributor Author

ok @romani

@nrmancuso
Copy link
Member

@shubh220922 please hardcode mutation first and try to understand why this mutation survives our tests.

@ThatSneakyCoder
Copy link
Contributor Author

@nrmancuso okay going through this.

@nrmancuso
Copy link
Member

@shubh220922 also, please keep hack like 4f9c2a4 in mind to kill mutation (using config input to kill mutation)

@ThatSneakyCoder
Copy link
Contributor Author

@nrmancuso Should I write input files for the tests previously present in the file as well or only for mine.

@nrmancuso
Copy link
Member

nrmancuso commented Oct 24, 2022

@shubh220922 please do not modify existing test inputs, also make sure to read through #12341

@ThatSneakyCoder
Copy link
Contributor Author

I'll work on this pr within the next 3 days. My exams are going on.

@ThatSneakyCoder
Copy link
Contributor Author

ThatSneakyCoder commented Nov 15, 2022

@nrmancuso I've been trying to understand the meaning of replaced call to ..... with receiver. What is this receiver? Also I found this term naked receiver somewhere and wanted to know what it was. I surfed all of the internet for this but couldn't understand what it means. Could you please help me figure this out.
image

@nrmancuso
Copy link
Member

nrmancuso commented Nov 15, 2022

@shubh220922 please read pitest documentation for this mutation operator; share specific points you need clarification on https://pitest.org/quickstart/mutators/#EXPERIMENTAL_NAKED_RECEIVER

Edit: I see you edited your comment, see our wiki at https://github.com/checkstyle/checkstyle/wiki/How-to-Generate-and-Analyze-Pitest-Reports#experimental-naked-receiver for code example

@ThatSneakyCoder
Copy link
Contributor Author

ThatSneakyCoder commented Nov 15, 2022

I have hardcoded the mutation in the AccessModifierOption.java class by removing trim() from the line where mutation was occurring. Will study the CI.

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

item:

@@ -63,7 +63,7 @@ private String getName() {
* @return the AccessModifier associated with given access modifier name.
*/
public static AccessModifierOption getInstance(String modifierName) {
return valueOf(AccessModifierOption.class, modifierName.trim().toUpperCase(Locale.ENGLISH));
return valueOf(AccessModifierOption.class, modifierName.toUpperCase(Locale.ENGLISH));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ThatSneakyCoder
Copy link
Contributor Author

ThatSneakyCoder commented Nov 17, 2022

Now in order to find what violation I will get at respective lines, I will have to check through running the config but the following is being displayed:

PS C:\Users\shubh\OneDrive\Desktop\checkstyle project> cat config.xml                                                                      
<?xml version="1.0"?>
<!DOCTYPE module PUBLIC "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
        "https://checkstyle.org/dtds/configuration_1_3.dtd">

<module name="Checker">
    <property name="charset" value="UTF-8" />
    <module name="TreeWalker">
        <module name="AccessModifierOption">
        </module>
    </module>
</module>
PS C:\Users\shubh\OneDrive\Desktop\checkstyle project> cat test.java                                                                       
/*
AccessModifierOption
option = \tSPACE


*/

package com.puppycrawl.tools.checkstyle.checks.naming.accessmodifieroption;

public class InputAccessModifierOption {

    class classOne {

    }

    class classTwo {

    }

    class classThree {

    }

    public void method1() {

    }

    public void method2() {

    }

}
PS C:\Users\shubh\OneDrive\Desktop\checkstyle project> java -jar "C:\Users\shubh\Downloads\checkstyle-10.4-all.jar" -c config.xml test.java
com.puppycrawl.tools.checkstyle.api.CheckstyleException: cannot initialize module TreeWalker - cannot initialize module AccessModifierOption - Unable to instantiate 'AccessModifierOption' class, it is also not possible to instantiate
        ... 5 more
Caused by: com.puppycrawl.tools.checkstyle.api.CheckstyleException: Unable to instantiate 'AccessModifierOption' class, it is also not possible to instantiate it as .AccessModifierOption, AccessModifierOptionCheck, .AccessModifierOptionCheck. Please recheck that class name is specified as canonical name or read how to configure short name usage https://checkstyle.org/config.html#Packages. Please also recheck that provided ClassLoader to Checker is configured correctly.
        at com.puppycrawl.tools.checkstyle.PackageObjectFactory.createModule(PackageObjectFactory.java:214)
        at com.puppycrawl.tools.checkstyle.TreeWalker.setupChild(TreeWalker.java:120)
        ... 7 more
Checkstyle ends with 1 errors.

It is giving me this error @nrmancuso.
At this point how do I find out what error will come at what line.

@nrmancuso
Copy link
Member

nrmancuso commented Nov 17, 2022

@shubh220922 you must use a check that uses AccessModifierOption

Example: https://checkstyle.sourceforge.io/config_javadoc.html#JavadocMethod

@ThatSneakyCoder
Copy link
Contributor Author

ThatSneakyCoder commented Nov 20, 2022

@nrmancuso i have made some changes.. Thanks to your link given at #12340 (comment).

But I am getting this error when I am running the test that I have made:

image

EDIT1: It is not able to find the messages bundle for some reason. What have I missed @nrmancuso.

@nrmancuso
Copy link
Member

nrmancuso commented Nov 20, 2022

@shubh220922 please only create a new test and input in JavadocMethodCheckTest, with tab character added to access modifier property value. You only need a very simple input, the idea is that we need check to read the property in only.

Make sure that mvn clean verify passes before next push.

@ThatSneakyCoder ThatSneakyCoder force-pushed the shubh/mutant branch 2 times, most recently from c7b0c4c to 9ebf025 Compare November 20, 2022 17:32
@ThatSneakyCoder
Copy link
Contributor Author

ThatSneakyCoder commented Nov 20, 2022

Mutation didn't get killed. What am I missing @nrmancuso. Could you review my changes please @nrmancuso .

@Kevin222004
Copy link
Collaborator

Kevin222004 commented Nov 21, 2022

@nrmancuso this is really quite suspicious. The current test case must resolve the mutation according to the config but it is not.
I have also make test to resolve it and it won't work if we are creating the test cases for the check which don't belong to package naming in which enum AccessModiferOption is created the mutation is not killed https://github.com/checkstyle/checkstyle/tree/master/src/main/java/com/puppycrawl/tools/checkstyle/checks/naming.

I have created a test case in one of this check from naming package and mutation were killed.

i am also curious to know why this is happening :), because according to the concept of mutation testing if we don't have strong enough test case for the code which we write so it will be mutated and in this currently updated pr this test is enough to kill this mutation bcs of trim func

@nrmancuso
Copy link
Member

@shubh220922 this means that the string is getting trimmed before we reach this method (AccessModifierOption#getInstance). Debug the code and follow the call stack to investigate. Provide your full analysis here.

@ThatSneakyCoder
Copy link
Contributor Author

@nrmancuso the following is what I got from debugging:

I have started debugging from valueOf(AccessModifierOption.class, modifierName.trim().toUpperCase(Locale.ENGLISH)); as in the image below:

image

I specially tagged this modifierName="\tpublic" to understand whether it is getting trimmed before reaching AccessModifierOption.getInstance() or not.

The value of token below is \tpublic which means that AccessModifierOption.getInstance(token) is receiving the non-trimmed version of \tpublic as in the image below:

Image1>
image

But in the Image2 result seems to contains public.
image

Following the stack of execution the value of value as in the image stays \tpublic until it reaches the line value=convertForCopy(value, type); as in the image below:

image

After crossing this line, the value of value starts to be shown asAccessModifierOption[1]@2407

image

I am thinking where exactly is the problem coming from?!

@nrmancuso
Copy link
Member

nrmancuso commented Nov 22, 2022

@shubh220922 ok, we have missed a nuance here. AccessModifierOption lives in the naming package, so due to pitest config in pom.xml we only target tests in the naming package. Please do:

  1. Remove new test + input
  2. Add test + input (with same \t trick in config) using https://checkstyle.sourceforge.io/config_naming.html#ParameterName or some other naming check
  3. Create issue to move AccessModifierOption to api package, since we use this enum outside of naming and plan to use it more extensively.

@romani
Copy link
Member

romani commented Nov 23, 2022

Create issue to move AccessModifierOption to api package,

We do all possible to avoid API package.
We want to really treat API as contract. So if we can avoid api we should avoid.

@nrmancuso
Copy link
Member

Create issue to move AccessModifierOption to api package,

We do all possible to avoid API package. We want to really treat API as contract. So if we can avoid api we should avoid.

@romani let's create issue to move AccessModifierOption, we can discuss final location in issue. It doesn't make sense to keep AccessModifierOption in naming if we use it elsewhere.

@ThatSneakyCoder
Copy link
Contributor Author

@nrmancuso mvn passed successfully. Mutation killed.
image

@ThatSneakyCoder
Copy link
Contributor Author

Q.1)
@nrmancuso as you mentioned in #12340 (comment) about the config of pitest in pom.xml preventing us from killing mutation of accessModifierOption in other packages, does this rule apply to all the packages? We necessarily need to make input and test in the same package as the surviving mutation always?

Q.2) How did you figure this out in #12340 (comment) as I wasn't able to reach any conclusion through debugging.

@nrmancuso
Copy link
Member

@shubh220922 test was right, but mutation was not killed. This means that we did not use this test to cover the mutation we are working on. We cannot put all tests on all packages, as pitest would take a very long time to run. I initially missed this since mutation class was suppressed in naming package, but used in other packages. This is what prompted me to mention that we should create an issue to move AccessModifiers to a more general location.

@ThatSneakyCoder
Copy link
Contributor Author

@nrmancuso

This means that we did not use this test to cover the mutation we are working on.

Please see if my interpretation of this is correct or not:

Statement 1

Due to certain config of pitest present in pom.xml that we have set, it only allows for killing those mutations for which the tests and inputs are written within the same package as the main java file containing mutation

It is thereby not possible to write tests and inputs in a different package than the package that contains the file containing the mutation due to the config of pit in pom.xml

Question 1.1

Did we set this config of PIT in pom.xml? Or it is given by default by PIT?

Question 2

I initially missed this since mutation class was suppressed in naming package
Could you please help me understand this.

Question 2.1

Where is the suppression exactly?

Question 2.2

Which mutation class is being suppressed here?

Question 2.3

The suppression of the mentioned mutation class is suppressing what function here?

@ThatSneakyCoder
Copy link
Contributor Author

@nrmancuso should i create issue to move AccesssModifierOption to api package?

@nrmancuso
Copy link
Member

@shubh220922 #12445

@nrmancuso
Copy link
Member

nrmancuso commented Nov 23, 2022

@shubh220922

Did we set this config of PIT in pom.xml? Or it is given by default by PIT?

See for yourself in the pom file.

Where is the suppression exactly?

This is what you have removed in this PR, read the suppression you've removed for all details. To be clear: most pitest mutation suppression files are named by package, like pitest-<package name>-suppressions.xml, so when I say that it was suppressed in naming package, this is what I was referring to.

Copy link
Member

@nrmancuso nrmancuso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Items:

@ThatSneakyCoder
Copy link
Contributor Author

Travis CI failing! Fixing it.

@nrmancuso
Copy link
Member

Travis CI failing! Fixing it.

Disregard this failure, this is in Travis side

@romani romani merged commit edd2b09 into checkstyle:master Nov 23, 2022
ParameterName
format = ^h$
ignoreOverridden = (default)false
accessModifiers = \tpublic
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

config like this: public\t,\t,

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In other PR, we had public, \t, case taken from this PR is with tab character "on" the access modifier. The first trim in both methods took care of the single \t, the second trim takes care of the \t "on" the access modifier.

@ThatSneakyCoder ThatSneakyCoder deleted the shubh/mutant branch November 26, 2022 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants