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

Align TestMode import across test classes #630

Merged
merged 1 commit into from
May 23, 2023
Merged

Conversation

philleonard
Copy link
Member

@philleonard philleonard commented May 16, 2023

Small cleanup to align with other test classes in this package.

🧹 Whilst an ad-hoc cleanup when working on something else, I'm not sure it can be generalised (and likely one you have already considered so I'm interested to know your opinions!).

What factors come into play when deciding between an import and a static import for accessing static members of a class? Ones I consider that cannot be generalised (trivially):

  • Trade-off between the class qualification providing extra descriptive value, and adding to verbosity. Requires understanding the descriptive value of a the qualifying class name in the context it is (statically or not) imported.
  • Frequency as a multiplier. Within one class I assume a check would be trivial, across many classes of the same structure not trivial with EP. In this case, it is common to all(?) #replacement tests and therefore you could argue we could drop the qualifier. This leads onto another question: should we not provide some form of test abstraction (harness) for BugChecker tests? Might also be nice to look at a cleaner test data setup, or perhaps there is a reason to providing varargs String's in CompilationTestHelper#addSourceLines over reading from a .java source file?

Suggested commit message (not much to say about this change so probably too verbose/redundant):

Qualify non-static `TestMode` imports across `BugChecker` test classes (#630)

Prefer non-static imports and qualification of
`BugCheckerRefactoringTestHelper#TestMode` members across bug checker test
classes.

@philleonard philleonard requested review from rickie and Stephan202 May 16, 2023 13:55
@github-actions
Copy link

Looks good. No mutations were possible for these changes.
Mutation testing report by Pitest. Review any surviving mutants by inspecting the line comments under Files changed.

@rickie rickie added this to the 0.12.0 milestone May 16, 2023
@rickie
Copy link
Member

rickie commented May 16, 2023

Heyy @philleonard , thanks for opening the PR! 🚀

First some context related to this specific issue and the question about generalization:

Nice thoughts, and yes you are right, it is not easy to generalize this and auto-detect candidates for static importing. For that reason we have a curated set of candidates for statically importing things.

We have the rule that we should not "lose" any context if we statically import something. This usually holds for imports that have
words (or parts) that are (partially) duplicate with the method. Additionally it should not be ambiguous. For example, if there are multiple places from which you can import the constant UTC, it is not directly clear from where you imported something, so we don't want to do it.

I have to go now so will get back to your question about the test abstraction later 😄.

Copy link
Member

@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.

Generally we try to combine PRs such as this one with a check that enforces the change, but as @rickie says we already have #450 for this. I'm fine with merging this PR as-is :)

I tweaked the suggested commit message :)

This leads onto another question: should we not provide some form of test abstraction (harness) for BugChecker tests? Might also be nice to look at a cleaner test data setup, or perhaps there is a reason to providing varargs String's in CompilationTestHelper#addSourceLines over reading from a .java source file?

Error Prone does support moving the test code to separate resource files, but in practice this makes test maintenance harder, and as such we see that new upstream Error Prone tests also prefer the current approach.

That said... yes, we can do better 😄. See #198, where we'll move to text blocks. That in turn unlocks IntelliJ IDEA language injection support :)

@philleonard
Copy link
Member Author

where we'll move to text blocks. That in turn unlocks IntelliJ IDEA language injection support :)

Nice! Having played around with #198 this is already a much nicer experience for writing these test classes (which I have been doing in a scratch file for now). Copilot suggestions and IntelliJ autocomplete also "work" within language injections so that is nice. After a quick scan, GitHub and the IntelliLang both have somewhat "incomplete" syntax highlighting, but already much better than what we currently have.

@rickie rickie force-pushed the pleonard/align-test-import branch from 1ac7cca to 9ac789f Compare May 23, 2023 07:22
@github-actions
Copy link

Looks good. No mutations were possible for these changes.
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 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@rickie rickie merged commit c53a3f6 into master May 23, 2023
@rickie rickie deleted the pleonard/align-test-import branch May 23, 2023 07:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants