Skip to content

Issue #13321: Kill mutation for SummaryJavaDocCheck-1#13311

Merged
romani merged 1 commit intocheckstyle:masterfrom
Kevin222004:s1
Jul 4, 2023
Merged

Issue #13321: Kill mutation for SummaryJavaDocCheck-1#13311
romani merged 1 commit intocheckstyle:masterfrom
Kevin222004:s1

Conversation

@Kevin222004
Copy link
Copy Markdown
Contributor

@Kevin222004 Kevin222004 commented Jun 26, 2023

Issue #13321: Kill mutation for SummaryJavaDocCheck-1


Check :-

https://checkstyle.org/checks/javadoc/summaryjavadoc.html#SummaryJavadoc


Mutation

<mutation unstable="false">
<sourceFile>SummaryJavadocCheck.java</sourceFile>
<mutatedClass>com.puppycrawl.tools.checkstyle.checks.javadoc.SummaryJavadocCheck</mutatedClass>
<mutatedMethod>containsForbiddenFragment</mutatedMethod>
<mutator>org.pitest.mutationtest.engine.gregor.mutators.experimental.NakedReceiverMutator</mutator>
<description>replaced call to java/lang/String::trim with receiver</description>
<lineContent>.matcher(firstSentence).replaceAll(&quot; &quot;).trim();</lineContent>
</mutation>


Explaination

The removal of trim will effect the programme it will increase the number of times in loop.

There are total 3 usage of the containsForbiddenFragment

  1. In validateUntaggedSummary method at
    if (endOfSentence != -1
    && containsForbiddenFragment(firstSentence.substring(0, endOfSentence))) {
    log(ast.getLineNumber(), MSG_SUMMARY_JAVADOC);

    Note:- If this condition execute then violation thrown and violation message doesn't contains any relation with the text.

Know when containsForbiddenFragment will be execute then

private boolean containsForbiddenFragment(String firstSentence) {
final String javadocText = JAVADOC_MULTILINE_TO_SINGLELINE_PATTERN
.matcher(firstSentence).replaceAll(" ").trim();
return forbiddenSummaryFragments.matcher(trimExcessWhitespaces(javadocText)).find();

javadocText will not be trimmed lets suppose if we have sentence This is summary javadoc .
then javaDoctext would become This is summary javadoc

and as a return statment we call trimExcessWhitespaces to match forbiddenSummaryFragment and in trimExcessWhitespaces for loop will run as more time as we have extra spaces which is not been removed as we remove trim.
and the string will return with the extra space but it will not affect the output.

And for the second and third usage the explaintaion is same as above

else if (containsForbiddenFragment(inlineReturn)) {
log(inlineReturnTag.getLineNumber(), MSG_SUMMARY_JAVADOC);
}

and
else if (containsForbiddenFragment(inlineSummary)) {
log(inlineSummaryTag.getLineNumber(), MSG_SUMMARY_JAVADOC);
}


Regression :-

Report-1 :- https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/5d08f12_2023202818/reports/diff/index.html

Report-2:- https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/5d08f12_2023084141/reports/diff/index.html


Diff Regression config: https://gist.githubusercontent.com/Kevin222004/61eaa69fe98585b6ee1882ca082362bc/raw/c74195e574d09886a3406be17a9d46787da9545e/Summary.xml
Diff Regression projects: https://gist.githubusercontent.com/Kevin222004/9600f179b602d4c971bdb0a050099005/raw/360a95ed7bb60d7a0956e531199d484c4d6f6617/test-projects.properties
Report label: Regression-2

@Kevin222004
Copy link
Copy Markdown
Contributor Author

Github, generate report

@github-actions
Copy link
Copy Markdown
Contributor

@Kevin222004
Copy link
Copy Markdown
Contributor Author

Github, generate report

@Kevin222004 Kevin222004 changed the title Issue #13109: Kill mutation for SummaryJavaDocCheck-1 Issue #13321: Kill mutation for SummaryJavaDocCheck-1 Jun 27, 2023
@github-actions
Copy link
Copy Markdown
Contributor

@Kevin222004 Kevin222004 marked this pull request as ready for review June 27, 2023 13:07
Copy link
Copy Markdown
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, looks like extra trim

Copy link
Copy Markdown
Member

@rdiachenko rdiachenko left a comment

Choose a reason for hiding this comment

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

lgtm

@rdiachenko rdiachenko assigned Vyom-Yadav and unassigned rdiachenko Jun 28, 2023
@Vyom-Yadav
Copy link
Copy Markdown
Member

@Kevin222004 I have found a regression test case with the current changes:

With the original code:

@Test                                                                                         
public void testAsd() throws Exception {                                                      
    final String[] expected = {                                                               
            "16: " + getCheckMessage(MSG_SUMMARY_JAVADOC),                                    
    };                                                                                        
                                                                                              
    verifyWithInlineConfigParser(                                                             
            getPath("InputSummaryJavadocTestForbiddenFragmentsFoo.java"), expected);          
}                                                                                             

Input file:

/*
SummaryJavadoc
violateExecutionOnNonTightHtml = true
forbiddenSummaryFragments = ^Returns the customer ID. This method returns.$
period = .

*/

package com.puppycrawl.tools.checkstyle.checks.javadoc.summaryjavadoc;

// ok
public class InputSummaryJavadocTestForbiddenFragmentsFoo {

    // violation 2 lines below
    /**
     * {@summary Returns the customer ID.
     *  This method returns. }
     */
    public void foo() {
    }
}

With your changes:

Violation lines for /home/vyom/IdeaProjects/checkstyle/src/test/resources/com/puppycrawl/tools/checkstyle/checks/javadoc/summaryjavadoc/InputSummaryJavadocTestForbiddenFragmentsFoo.java differ.
missing (1): 16
---
expected   : [16]
but was    : []

This is both a good and bad regression.
The above-mentioned is the bad part, here is the good part: (^Returns the customer ID. This method returns. $, notice the whitespace after . and before $)

/*
SummaryJavadoc
violateExecutionOnNonTightHtml = true
forbiddenSummaryFragments = ^Returns the customer ID. This method returns. $
period = .

*/

package com.puppycrawl.tools.checkstyle.checks.javadoc.summaryjavadoc;

// ok
public class InputSummaryJavadocTestForbiddenFragmentsFoo {

    // ok, no violation here with the original code, IMO there should be a violation.
    /**
     * {@summary Returns the customer ID.
     *  This method returns. }
     */
    public void foo() {
    }
}

with your changes:

/*
SummaryJavadoc
violateExecutionOnNonTightHtml = true
forbiddenSummaryFragments = ^Returns the customer ID. This method returns. $
period = .

*/

package com.puppycrawl.tools.checkstyle.checks.javadoc.summaryjavadoc;

// ok
public class InputSummaryJavadocTestForbiddenFragmentsFoo {

    // violation 2 lines below
    /**
     * {@summary Returns the customer ID.
     *  This method returns. }
     */
    public void foo() {
    }
}

@romani @rdiachenko Please share your opinion about the above mentioned test case (the one with extra space.)

Copy link
Copy Markdown
Member

@Vyom-Yadav Vyom-Yadav left a comment

Choose a reason for hiding this comment

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

Items:
Main item: #13311 (comment)

@romani
Copy link
Copy Markdown
Member

romani commented Jul 2, 2023

@Kevin222004 , please add Inputs from @Vyom-Yadav to our code base.

Please share your opinion about the above mentioned test case (the one with extra space.)

It should be a violation. As with inline tags we consider all until }. Period property is not in use.

@Kevin222004
Copy link
Copy Markdown
Contributor Author

@romani done test added

Copy link
Copy Markdown
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
Copy Markdown
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

Copy link
Copy Markdown
Member

@Vyom-Yadav Vyom-Yadav left a comment

Choose a reason for hiding this comment

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

LGTM! @Kevin222004 Please create an issue for the other case I mentioned in the PR. @romani CircleCI failed due to a connection reset. Please re-run.

@Vyom-Yadav Vyom-Yadav assigned romani and unassigned Vyom-Yadav Jul 4, 2023
@romani romani merged commit fa39b3e into checkstyle:master Jul 4, 2023
@romani
Copy link
Copy Markdown
Member

romani commented Jul 4, 2023

@Kevin222004 , please review what is not done

@romani
Copy link
Copy Markdown
Member

romani commented Jul 4, 2023

@Vyom-Yadav , I think you mentioned only one case and we opened issue for it #13347

@Kevin222004
Copy link
Copy Markdown
Contributor Author

Yes I messaged him for same but not get replied yet

@Vyom-Yadav
Copy link
Copy Markdown
Member

#13347 (comment)

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.

4 participants