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

More gradle lint #17363

Merged
merged 4 commits into from
Nov 12, 2024
Merged

More gradle lint #17363

merged 4 commits into from
Nov 12, 2024

Conversation

mikehardy
Copy link
Member

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 dunno

We may find out when gradle 9 launches

Checklist

Please, go through these checks before submitting the PR.

  • You have a descriptive commit message with a short title (first line, max 50 chars).
  • You have commented your code, particularly in hard-to-understand areas
  • You have performed a self-review of your own code
  • UI changes: include screenshots of all affected screens (in particular showing any new or changed strings)
  • UI Changes: You have tested your change using the Google Accessibility Scanner

@mikehardy mikehardy added Needs Review Deprecation Warnings on deprecated API usage Dev Development, testing & CI Tests labels Nov 6, 2024
junitJupiter= "5.11.3"
junitJupiter = "5.11.3"
Copy link
Member Author

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

Copy link
Member

@david-allison david-allison left a comment

Choose a reason for hiding this comment

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

Looks great!

Does this fix:

@david-allison david-allison added Needs Second Approval Has one approval, one more approval to merge and removed Needs Review labels Nov 11, 2024
"message is expected",
e.message?.contains("unexpected exception type thrown") == true
)
return
Copy link
Member

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

Copy link
Member Author

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")

Copy link
Member

@david-allison david-allison Nov 11, 2024

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 than e.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")
    }

Copy link
Member

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

Copy link
Member

@david-allison david-allison Nov 11, 2024

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?

Copy link
Member Author

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

@mikehardy
Copy link
Member Author

Looks great!

Does this fix:

I did not test that but there is no real rush getting this in. I'll give it a look and see

@mikehardy mikehardy added the Needs Author Reply Waiting for a reply from the original author label Nov 11, 2024
@david-allison
Copy link
Member

david-allison commented Nov 11, 2024

Let's see if it fixes the common testing issue 🤞

EDIT: It doesn't

@david-allison david-allison added Needs Author Reply Waiting for a reply from the original author Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) and removed Needs Author Reply Waiting for a reply from the original author Needs Second Approval Has one approval, one more approval to merge labels Nov 11, 2024
@david-allison
Copy link
Member

Adding a Needs Author Reply Waiting for a reply from the original author on the test changes (or not): https://github.com/ankidroid/Anki-Android/pull/17363/files#r1836879056

I'm ambivalent. Implementer's choice, as long as CI is green, happy to merge

@mikehardy
Copy link
Member Author

I adopted the test kotlinization you proposed David
Also noticed our lint wasn't applied in testlib or common so added a comment where I apply our lint config

@mikehardy mikehardy added Needs Review and removed Needs Author Reply Waiting for a reply from the original author labels Nov 11, 2024
@mikehardy
Copy link
Member Author

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

Copy link
Member

@david-allison david-allison left a 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!

@david-allison david-allison added this pull request to the merge queue Nov 12, 2024
Merged via the queue into ankidroid:main with commit 383025c Nov 12, 2024
9 checks passed
@github-actions github-actions bot added this to the 2.20 Release milestone Nov 12, 2024
@github-actions github-actions bot removed the Pending Merge Things with approval that are waiting future merge (e.g. targets a future release, CI wait, etc) label Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Deprecation Warnings on deprecated API usage Dev Development, testing & CI Tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants