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 #12275: Resolve Pitest suppression for EmptyForInitializerPad-2 #12277

Merged
merged 1 commit into from Oct 11, 2022

Conversation

Kevin222004
Copy link
Collaborator

@Kevin222004 Kevin222004 commented Oct 8, 2022

@Kevin222004
Copy link
Collaborator Author

  1. pitest report

    https://kevin222004.github.io/general/com.puppycrawl.tools.checkstyle.checks.whitespace/EmptyForInitializerPadCheck.java.html
    replaced call to com/puppycrawl/tools/checkstyle/api/DetailAST::getNextSibling with receiver

  2. Mutated code

    current code
    final DetailAST semi = ast.getNextSibling();
    is Mutated to
    final DetailAST semi = ast;

  3. Analysis

    If we change final DetailAST semi = ast.getNextSibling(); to final DetailAST semi = ast;
    it want make any difference because in this check we just care about the parenPad-> ( and ;
    .getNextSibling() will point the condition of for statment statment if this is for loop and in the
    source code it returns as null.

    So the usage of .getNextSibling() is currently nothing so I think it is not possible to create a Unit
    test file

  4. How to kill this

    removed the .getNextSibling()

Report of killed Mutation
https://kevin222004.github.io/emptpad/com.puppycrawl.tools.checkstyle.checks.whitespace/EmptyForInitializerPadCheck.java.html

@romani
Copy link
Member

romani commented Oct 8, 2022

Ok, such code most likely existed for some good reason we need to find such java code.
Please provide regression diff report.
https://github.com/checkstyle/contribution/tree/master/checkstyle-tester#report-generation

Hint: https://github.com/checkstyle/checkstyle/wiki/How-to-Generate-and-Analyze-Pitest-Reports#how-to-find-java-code-that-can-kill-mutation

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.

Items

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.

Items

@Kevin222004
Copy link
Collaborator Author

Github, generate report

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.

ok to merge

@romani romani requested a review from rnveach October 9, 2022 17:46
@romani romani assigned rnveach and unassigned romani Oct 9, 2022
@rnveach
Copy link
Member

rnveach commented Oct 9, 2022

Diff Regression config: https://gist.githubusercontent.com/Kevin222004/a85bd5c1897e158b6495850ba792bf4b/raw/b3d6fd5577d468d81339aa9f80b1581729b22bb5/config.xml

https://checkstyle.org/config_whitespace.html#EmptyForInitializerPad
This config is not enough.
Please read https://github.com/checkstyle/contribution/tree/master/checkstyle-tester#checkstyle-pitest-regression and expand config to all permutations which this check can be.

so I think it is not possible to create a Unit test file

If nothing changes on new regression, prove to me you stepped through the source and there is no way to create an input file to kill this mutation and changing production code is the only option.
See #7797 , 4b .

To me it seems odd that we are removing references to a ; when code examples talk about ;.

@Kevin222004
Copy link
Collaborator Author

Github, generate report

@Kevin222004
Copy link
Collaborator Author

@rnveach please look at the updated config

@rnveach
Copy link
Member

rnveach commented Oct 10, 2022

Updated config is better. It shows there is still no regression.

@romani
Copy link
Member

romani commented Oct 10, 2022

AST structure might be changed from initial implementation.
https://checkstyle.sourceforge.io/apidocs/com/puppycrawl/tools/checkstyle/api/TokenTypes.html#FOR_INIT
SEMI is sibling of FOR_INIT (the only token this Check run on).

I think we are good to merge this, in most worse case, user will report issue and we will fix it with full knowledge.

@Kevin222004
Copy link
Collaborator Author

To me it seems odd that we are removing references to a ; when code examples talk about ;.

@rnveach @romani if it is not looking good then we can make changes like this #12277 (review)

@rnveach
Copy link
Member

rnveach commented Oct 10, 2022

prove to me you stepped through the source and there is no way to create an input file to kill this mutation and changing production code is the only option

In short, there is no input file we can create here.

In this case AST is FOR_INIT and the next sibling is SEMI. When looking at the code after the mutation, there is checks done against Line and Column numbers. My first attempt to examine this was to try and get the 2 ASTs on different lines, as this would cause violations to be on different lines and prove we need the violation to be on only one of them.

This failed to be done because of this check and the way our ASTs are formed. EmptyForInitializer is only for for loops which have no initialization (IE: for (;). Even with the FOR_INIT and SEMI on different lines, our AST structure always makes them the same line/column.

for (
 ;;) {}

creates:

        |      |--LITERAL_FOR -> for [3:0]
        |      |  |--LPAREN -> ( [3:4]
        |      |  |--FOR_INIT -> FOR_INIT [4:1]
        |      |  |--SEMI -> ; [4:1]

We have both tokens appear to be on the same line/column. It doesn't matter if there is comments inside the FOR_INIT as it is still the same behavior.

Since we can't get these 2 tokens to have different line/column, there isn't a way to kill the mutation as it is now.

Copy link
Member

@rnveach rnveach left a comment

Choose a reason for hiding this comment

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

1 minor change.

@romani romani merged commit b51b4af into checkstyle:master Oct 11, 2022
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

3 participants