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

Integrate with kotlin 2.x power assert #539

Open
yogurtearl opened this issue May 31, 2024 · 3 comments
Open

Integrate with kotlin 2.x power assert #539

yogurtearl opened this issue May 31, 2024 · 3 comments

Comments

@yogurtearl
Copy link
Contributor

Kotlin 2.x includes power assert.
https://kotlinlang.org/docs/power-assert.html

It would be nice if I could use assertk APIs, but get power-assert style error messages when the power assert plugin is applied.

Seems like this might support this sort of thing:
https://kotlinlang.org/docs/power-assert.html#beyond-assert-function

@evant
Copy link
Collaborator

evant commented Jun 4, 2024

Oh that's cool! I had actually considered looking into something similar but decided it would be best as a separate library as it's solving problem of good assertion error messages in different ways. If you use something like power-assert you don't really need something like assertk, ex:

assert(hello.length == world.substring(1, 4).length) { "Incorrect length" }

Incorrect length
assert(hello.length == world.substring(1, 4).length) { "Incorrect length" }
       |     |      |  |     |               |
       |     |      |  |     |               3
       |     |      |  |     orl
       |     |      |  world!
       |     |      false
       |     5
       Hello

vs

assertThat(world.substring(1, 4)).hasSameLengthAs(hello)

expected to have same length as:<"Hello"> (5) but was:<"orl"> (3)

certainly open if someone wants to explore this and show off cases where they would be useful together though!

@JakeWharton
Copy link
Contributor

Unless we're writing a new compiler plugin specific to assertk, the entire design of power assert isn't going to work with this API shape. All the context is lost within the library. Basically what makes assertk so good on its own precludes the use of this tool.

@evant
Copy link
Collaborator

evant commented Jun 4, 2024

Yeah after looking at it a bit more, agreed.

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

No branches or pull requests

3 participants