-
Notifications
You must be signed in to change notification settings - Fork 751
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
CheckReturnValue: support more variants of "fail" in try/execute/fail/catch #804
Comments
Thanks for bringing this up. We'll probably want to add support for the new fail methods, but if you're using JUnit 5 I recommend using |
I agree with @cushon. |
@cushon So are you saying I should not create the pull request? I was not aware of the (Not to muddy the waters, but this chain of comments has me wondering whether a new bug pattern would be worthwhile - one that detects try/execute/fail/catch in JUnit 5 and testng code and recommends using |
We're happy to take a PR for this. There isn't a great way to add a test since Error Prone uses JUnit 4, but that's fine.
We have a refactoring for this but it hasn't been open-sourced yet. I can do that if there'd be interest. We also have checks for |
@cushon I'm personally interested in seeing these refactorings/checks open-sourced! But if it would take time away that would otherwise be spent on designing & coding up support for |
This adds support for JUnit 5's fail(), testng's fail(), and throw new AssertionError(). Using assertThrows() is preferable to using fail() in JUnit 5 and testng, and assertThrows() is already supported by CheckReturnValue, so mention that in the docs. This commit intentionally does not add tests for the new fail() methods to CheckReturnValueTest. That would require adding JUnit 5 and testng as Maven dependencies, which would be confusing because the project already depends on JUnit 4. Fixes google#804
I'm also interested in those |
The refactorings I mentioned earlier are now available: 42a9a65. |
Also I'd still take a PR to add more heuristics to |
Recently I had to add some
@SuppressWarnings("CheckReturnValue")
to my code because I upgraded from JUnit 4 to 5, and Error Prone no longer recognized the try/execute/fail/catch pattern in my code. I eventually realized this is becauseCheckReturnValue
looks for a specific set of "fail" methods and JUnit 5's is not one of them. See the relevant lines ofAbstractReturnValueIgnored
.It took me a long time to figure out what was going wrong and I'd like to save other people from the headache.
Would you be willing to accept a pull request that adds support for each of the following?
fail
methodfail
methodthrow new AssertionError(...)
In order to add test cases that compile for JUnit 5 and testng, I think I would need to add those libraries as test-scope dependencies of the "core" module, in case that influences the decision.
The text was updated successfully, but these errors were encountered: