-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
More gradle lint #17363
More gradle lint #17363
Conversation
junitJupiter= "5.11.3" | ||
junitJupiter = "5.11.3" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one spacing change, I just threw it in there. Forgive me
8a936cf
to
8d69f7f
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"message is expected", | ||
e.message?.contains("unexpected exception type thrown") == true | ||
) | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I admit it took me a minute to understand the expected route through the code.
I'd consider maybe,
@Test
fun failsWithIncorrectException() {
var assertionErrorThrown = false
try {
assertThrows<IllegalArgumentException>("IllegalArgumentException is not found") {
throw NullPointerException("this is unexpected")
}
} catch (e: AssertionError) {
// we expect this
assertThat(
"message is expected",
e.message?.contains("unexpected exception type thrown") == true
)
assertionErrorThrown = true
}
assertThat("Should have had an AssertionError", assertionErrorThrown)
}
This way, I don't have to think about why there is an inconditional fail at the end of the test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 I think it's still cleaner without an extra local var and comparison but if it is unclear at all I think there is an opportunity to improve the message in the fail itself so it's completely clear. What if it was like
fail("only reachable if no exception or exception did match correctly - both are always a failure")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're going to nitpick on tests
- use
containsString
rather thane.message?.contains("unexpected exception type thrown") == true
- extract to something like
captureAssertionFailure
@Test
fun failsWithIncorrectException() {
val assertionError = captureAssertionFailure {
assertThrows<IllegalArgumentException>("IllegalArgumentException is not found") {
throw NullPointerException("wrong exception type")
}
}
assertThat(assertionError.message, containsString("unexpected exception type thrown"))
}
@Test
fun failsWithNoException() {
val assertionError = captureAssertionFailure {
assertThrows<IllegalArgumentException>("No exception is found") {
// assertThrows should fail: nothing is thrown inside this block
}
}
assertThat(assertionError.message, containsString("nothing was thrown"))
}
/**
* Asserts that the provided block throws an [AssertionError]
* @param throwErrorBlock code which should throw an [AssertionError]
* @return the [AssertionError] thrown by [throwErrorBlock]
*/
private fun captureAssertionFailure(throwErrorBlock: () -> Unit): AssertionError {
try {
throwErrorBlock()
} catch (e: AssertionError) {
return e
}
// this statement may not be inside the try ... as it would be caught by the 'catch'
fail("An AssertionError should have been thrown")
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a weak opinion, if you prefer this version, fine by me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[minor, out of personal curiosity]
@Arthur-Milchior Could I confirm the meaning of 'weak opinion' here?
Who has one, or are there readability problems with my code above?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm going to guess (correct if I am wrong!) that the weakness was between my take on it and Arthur's which were both the same basic implementation. Yours is a totally different thing and appears more expressive to me, I'll adopt it
I did not test that but there is no real rush getting this in. I'll give it a look and see |
Let's see if it fixes the EDIT: It doesn't |
Adding a
Needs Author Reply
I'm ambivalent. Implementer's choice, as long as CI is green, happy to merge |
...so we have to include a launcher specifically, this is the one they recommend https://docs.gradle.org/8.10.2/userguide/upgrading_version_8.html#test_framework_implementation_dependencies
8d69f7f
to
1371ce1
Compare
I adopted the test kotlinization you proposed David |
Added a (final?) commit that disables the custom scheduler test as Flaky in CI again. Sad to do it but it's causing a lot of issues |
so I implemented some tests, should be tested anyway https://docs.gradle.org/8.10.2/userguide/upgrading_version_8.html#test_task_fail_on_no_test_executed
partial revert of 8d5d3da they are the largest source of flakes in CI at the moment, causing issues on all kinds of unrelated PRs
635ce41
to
207eada
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Force pushed a very minor nit. Let's go!
Purpose / Description
Much to my annoyance I continue to see gradle 9 deprecation warnings in Android Studio
I hunted down a couple more with generic "./gradlew test" or "./gradlew build" type targets
None of this is really important.
Fixes
Nothing logged, but I don't want unexpected build errors when gradle 9 comes out, and it should be shortly
Approach
The gradle deprecation warnings are at least very informative, they contain links to the page describing what to do
How Has This Been Tested?
These changes were basically all test-related, so, testing was pretty obviously to keep running the test targets
Learning (optional, can help others)
just handling deprecation in toolchains is a significant chunk of my life
Also, it seems like there might be some internal chunk of Android Studio that contains deprecation itself, as one final target seems to continue triggering things -
amazonDebugRuntimeClasspathCopy
but I can't locate that target so I dunnoWe may find out when gradle 9 launches
Checklist
Please, go through these checks before submitting the PR.