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

Sort arguments of RefasterRuleCollectionTestCase#elidedTypesAndStaticImports #850

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mohamedsamehsalah
Copy link
Contributor

@mohamedsamehsalah mohamedsamehsalah commented Oct 21, 2023

This PR is split into two commits:

  • Code implementation.
  • Manually applied suggestions

Suggested commit message:

Sort arguments of RefasterRuleCollectionTestCase#elidedTypesAndStaticImports (#850)

@github-actions
Copy link

  • Surviving mutants in this change: 5
  • Killed mutants in this change: 16
class surviving killed
🧟tech.picnic.errorprone.refaster.test.RefasterRuleCollection$1 3 9
🧟tech.picnic.errorprone.refaster.test.RefasterRuleCollection 2 5
🎉tech.picnic.errorprone.refaster.test.RefasterRuleCollection$UnexpectedMatchReporter 0 2

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

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

94.5% 94.5% Coverage
0.0% 0.0% Duplication

methodInvocationTree.getArguments();

ImmutableList<? extends ExpressionTree> desiredArgumentOrdering =
actualArgumentsOrdering.stream()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we group argument types togther before sorting ?
i.e: Group & sort method invocation lexicographically > group & sort identifiers lexicographically, etc...

Copy link
Member

Choose a reason for hiding this comment

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

One tip for the ordering, in lexicographical sorting, the capital letters A-Z come before the a-z 😄.

Characters are sorted in lexicographic order. Sorting is case sensitive, that is, uppercase letters appear before lowercase letter in sorted data.


Should we group argument types togther before sorting ?

Do you have an example of the case you mean? In any case, it sounds like something we should have a test case for 😉.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you have an example of the case you mean?

My thought was (As an example)

  1. Group & sort Objects (Strings for eg).
  2. Group & sort Class statemens (*.class).
  3. Group & sort method arguments.
  4. Group & sort primitives.

Essentially turning

ImmutableSet.of(List.class, "A", assertDoesNotThrow(() -> null), Iterables.class, "a", 1)

to

ImmutableSet.of("A", "a", List.class, Iterables.class, assertDoesNotThrow(() -> null),1)

methodInvocationTree.getMethodSelect())),
")"));

fixBuilder.merge(SuggestedFix.replace(methodInvocationTree, suggestion));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Curious why running ./apply-error-prone-suggestions.sh did not fix the *(Input|Otput) tests here 🤔

Copy link
Member

Choose a reason for hiding this comment

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

So what we are doing in the RefasterRuleCollection, is reporting things "in" the output file, that is what we are also verifying in the refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/NonSortedElidedTypesAndStaticImportsTestRulesTestOutput.java file.

So e.g. in the MatchInWrongMethodRulesTest input file we try to see what is wrong and we report that in the MatchInWrongMethodRulesTest output file, while not doing anything with the content itself, we only add a warning as a comment.

So in the NonSortedElidedTypesAndStaticImportsTestRulesTestOutput file we should not change the output to be correct, we only need a nice comment explaining what is wrong. Instead of

/* ERROR: Unexpected token. */

(which also signals something is wrong and the code we add has likely a bug)
It should add something like:

/*
   *  ERROR: The entries of the `elidedTypesAndStaticImports` method are not sorted lexicographically. The method should look like this:
   *   public ImmutableSet<Object> elidedTypesAndStaticImports() {
   *     return ImmutableSet.of(
              Assertions.class,
.....  (a method with correct sorting)
*/

This thing is not a "regular" BugPattern. It tries to guide a developer when writing TestInput & TestOutput files by giving this warning :).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for explanation 🙇 🙇

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.

I gave some context that should make some things a bit clearer, if there are any questions let us know 😄.

Nice that you opened another PR @mohamedsamehsalah 🚀 !

methodInvocationTree.getArguments();

ImmutableList<? extends ExpressionTree> desiredArgumentOrdering =
actualArgumentsOrdering.stream()
Copy link
Member

Choose a reason for hiding this comment

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

One tip for the ordering, in lexicographical sorting, the capital letters A-Z come before the a-z 😄.

Characters are sorted in lexicographic order. Sorting is case sensitive, that is, uppercase letters appear before lowercase letter in sorted data.


Should we group argument types togther before sorting ?

Do you have an example of the case you mean? In any case, it sounds like something we should have a test case for 😉.

methodInvocationTree.getMethodSelect())),
")"));

fixBuilder.merge(SuggestedFix.replace(methodInvocationTree, suggestion));
Copy link
Member

Choose a reason for hiding this comment

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

So what we are doing in the RefasterRuleCollection, is reporting things "in" the output file, that is what we are also verifying in the refaster-test-support/src/test/resources/tech/picnic/errorprone/refaster/test/NonSortedElidedTypesAndStaticImportsTestRulesTestOutput.java file.

So e.g. in the MatchInWrongMethodRulesTest input file we try to see what is wrong and we report that in the MatchInWrongMethodRulesTest output file, while not doing anything with the content itself, we only add a warning as a comment.

So in the NonSortedElidedTypesAndStaticImportsTestRulesTestOutput file we should not change the output to be correct, we only need a nice comment explaining what is wrong. Instead of

/* ERROR: Unexpected token. */

(which also signals something is wrong and the code we add has likely a bug)
It should add something like:

/*
   *  ERROR: The entries of the `elidedTypesAndStaticImports` method are not sorted lexicographically. The method should look like this:
   *   public ImmutableSet<Object> elidedTypesAndStaticImports() {
   *     return ImmutableSet.of(
              Assertions.class,
.....  (a method with correct sorting)
*/

This thing is not a "regular" BugPattern. It tries to guide a developer when writing TestInput & TestOutput files by giving this warning :).

@mohamedsamehsalah mohamedsamehsalah force-pushed the mohamedsamehsalah/321-sort-entries-of-refasterrulecollectionTestCase branch from 24a8c9b to faaee6e Compare November 25, 2023 21:42
Copy link

  • Surviving mutants in this change: 4
  • Killed mutants in this change: 18
class surviving killed
🧟tech.picnic.errorprone.refaster.test.RefasterRuleCollection$1 3 9
🧟tech.picnic.errorprone.refaster.test.RefasterRuleCollection 1 7
🎉tech.picnic.errorprone.refaster.test.RefasterRuleCollection$UnexpectedMatchReporter 0 2

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

Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 2 Code Smells

94.7% 94.7% Coverage
0.0% 0.0% Duplication

@mohamedsamehsalah mohamedsamehsalah force-pushed the mohamedsamehsalah/321-sort-entries-of-refasterrulecollectionTestCase branch from faaee6e to 1593ff2 Compare May 8, 2024 14:06
Copy link

github-actions bot commented May 8, 2024

  • Surviving mutants in this change: 4
  • Killed mutants in this change: 15
class surviving killed
🧟tech.picnic.errorprone.refaster.test.RefasterRuleCollection$1 3 9
🧟tech.picnic.errorprone.refaster.test.RefasterRuleCollection 1 4
🎉tech.picnic.errorprone.refaster.test.RefasterRuleCollection$UnexpectedMatchReporter 0 2

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

@rickie rickie force-pushed the mohamedsamehsalah/321-sort-entries-of-refasterrulecollectionTestCase branch from 1593ff2 to 0e90279 Compare May 24, 2024 11:29
Copy link

Copy link

  • Surviving mutants in this change: 4
  • Killed mutants in this change: 15
class surviving killed
🧟tech.picnic.errorprone.refaster.test.RefasterRuleCollection$1 3 9
🧟tech.picnic.errorprone.refaster.test.RefasterRuleCollection 1 4
🎉tech.picnic.errorprone.refaster.test.RefasterRuleCollection$UnexpectedMatchReporter 0 2

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants