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

Improve JUnitMethodDeclaration check #406

Merged
merged 3 commits into from
Dec 22, 2022

Conversation

Stephan202
Copy link
Member

@Stephan202 Stephan202 commented Dec 11, 2022

Resolves issues found while testing Error Prone Support against Checkstyle (currently testing on this branch).

Suggested commit message:

Improve `JUnitMethodDeclaration` check (#406)

Implemented changes:
- Ignore method overrides even if not annotated with `@Override`.
- Don't rename methods to `true`, `false` or `null`.
- Don't rename methods to a name declared in a super type. This
  prevents e.g. renaming `testToString` to `toString`.

@Stephan202 Stephan202 added this to the 0.7.0 milestone Dec 11, 2022
@Stephan202
Copy link
Member Author

There's no mutation testing report here, while #407, which I filed soon after this PR, has two (identical) reports for a single commit.

I looked into the issue a bit and sent the following email to @hcoles of Arcmutate/CDG (in response to an earlier email in which Henry gave us a heads-up about this issue possibly existing):

Hi Henry,

It appears (although this has not been confirmed) that the artifacts from one PR overwrote another.

I suspect we just hit this issue. I filed the following PRs in close succession:

What happened next was that the latter PR received two mutation test report comments (both referencing code modified only in the latter PR), while the former PR did not receive any comment.

The two builds that generated the reports do have the correct zip file attached:

So the issue should then be with the jobs that update the PR, which is these two:

Checking the logs of these two runs, we see indeed that both specify:

(found) Run ID: 3667677035

This is incorrect for one of the two. Note also the check summary difference between the two PRs:

  • 8 successful and 1 skipped checks
  • 9 successful and 1 skipped checks

Searching around a bit, I wonder whether these links reference the same issue:

I likely won't have time in the near future to dive deeper into this issue. I hope this helps!

Cheers,
Stephan

@rickie rickie force-pushed the sschroevers/JUnitMethodDeclaration-improvements branch from 33ac331 to 6f4a212 Compare December 19, 2022 15:18
@github-actions
Copy link

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 29
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.util.JavaKeywords 2 11
🎉tech.picnic.errorprone.bugpatterns.JUnitMethodDeclaration 0 18

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

&& !isReservedKeyword(str)
&& !BOOLEAN_AND_NULL_LITERALS.contains(str)
&& Character.isJavaIdentifierStart(str.codePointAt(0))
&& str.codePoints().skip(1).allMatch(Character::isUnicodeIdentifierPart);
Copy link
Member Author

Choose a reason for hiding this comment

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

Pitest flags that mutants that remove .skip(1) aren't killed. Without assuming that isUnicodeIdentifierPart matches a superset of isJavaIdentifierStart I can't drop this operation. But that assumption does hold in practice, IIUC, so writing a test for it is hard/impossible. There's also a (minute) performance aspect. TL;DR: I don't see how I can avoid this Pitest warning.

Stephan202 and others added 2 commits December 21, 2022 11:13
Implemented changes:
- Ignore method overrides even if not annotated `@Override`.
- Don't rename methods to `true`, `false` or `null`.
- Don't rename methods to a name declared in a super type. This
  prevents e.g. renaming `testToString` to `toString`.
@rickie rickie force-pushed the sschroevers/JUnitMethodDeclaration-improvements branch from 6f4a212 to 7fa268f Compare December 21, 2022 10:14
Copy link
Member

@rickie rickie left a comment

Choose a reason for hiding this comment

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

Rebased and added a commit.

Some minor comments with questions mostly :).

Changes LGTM!

Made one tweak to suggested commit message.


final class JavaKeywordsTest {
private static Stream<Arguments> isValidIdentifierTestCases() {
return Stream.of(
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return Stream.of(
/* { str, expected } */
return Stream.of(

Matchers.not(hasModifier(Modifier.FINAL)),
Matchers.not(hasModifier(Modifier.PRIVATE)),
enclosingClass(hasModifier(Modifier.ABSTRACT))));
Sets.immutableEnumSet(Modifier.PRIVATE, Modifier.PROTECTED, Modifier.PUBLIC);
Copy link
Member

Choose a reason for hiding this comment

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

What is the reason for this change? :)

Copy link
Member Author

Choose a reason for hiding this comment

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

More efficient storage and retrieval, just like what we do here.

}

return Optional.empty();
}

private static boolean isExistingMethodName(Type clazz, String name, VisitorState state) {
return ASTHelpers.matchingMethods(state.getName(name), x -> true, clazz, state.getTypes())
Copy link
Member

Choose a reason for hiding this comment

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

We could signal that it's unused by naming x unused. Not sure if we gain a lot there though.

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, the scope is very small, so it's clear that the parameter is unused. Perhaps better would be s/x/method/, since it's a predicate over methods.

@github-actions
Copy link

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 29
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.util.JavaKeywords 2 11
🎉tech.picnic.errorprone.bugpatterns.JUnitMethodDeclaration 0 18

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@Stephan202
Copy link
Member Author

Made one tweak to suggested commit message.

Hmm, I think it reads better without the word "with". Just like something "is annotated @Nullable". There should IMHO not be a "with" in that sentence.

(Need to leave train; will check rest later.)

Copy link
Member Author

@Stephan202 Stephan202 left a comment

Choose a reason for hiding this comment

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

Added a commit. Tnx for the reviews!

W.r.t. the commit message: can live with it, so merge as you see fit.

Matchers.not(hasModifier(Modifier.FINAL)),
Matchers.not(hasModifier(Modifier.PRIVATE)),
enclosingClass(hasModifier(Modifier.ABSTRACT))));
Sets.immutableEnumSet(Modifier.PRIVATE, Modifier.PROTECTED, Modifier.PUBLIC);
Copy link
Member Author

Choose a reason for hiding this comment

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

More efficient storage and retrieval, just like what we do here.

}

return Optional.empty();
}

private static boolean isExistingMethodName(Type clazz, String name, VisitorState state) {
return ASTHelpers.matchingMethods(state.getName(name), x -> true, clazz, state.getTypes())
Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, the scope is very small, so it's clear that the parameter is unused. Perhaps better would be s/x/method/, since it's a predicate over methods.

@github-actions
Copy link

  • Surviving mutants in this change: 2
  • Killed mutants in this change: 29
class surviving killed
🧟tech.picnic.errorprone.bugpatterns.util.JavaKeywords 2 11
🎉tech.picnic.errorprone.bugpatterns.JUnitMethodDeclaration 0 18

Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@rickie rickie merged commit 6313bd5 into master Dec 22, 2022
@rickie rickie deleted the sschroevers/JUnitMethodDeclaration-improvements branch December 22, 2022 07:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

Successfully merging this pull request may close these issues.

3 participants