Skip to content

Enable Kotlin Power Assert plugin#247

Open
DmitryNekrasov wants to merge 4 commits intomasterfrom
dmitry.nekrasov/power-assert-support
Open

Enable Kotlin Power Assert plugin#247
DmitryNekrasov wants to merge 4 commits intomasterfrom
dmitry.nekrasov/power-assert-support

Conversation

@DmitryNekrasov
Copy link
Copy Markdown
Collaborator

This PR enables the Kotlin Power Assert compiler plugin, which transforms assertion calls to include detailed diagnostic messages showing intermediate expression values on failure.

Power Assert injects a diagnostic message string as the last parameter of each configured assertion function. For assertEquals(expected, actual) this string is always constructed eagerly, even when the assertion passes. This has no impact on contract and unit tests, but stress tests execute assertions inside tight loops with up to 1000000 iterations, making the constant string allocation a significant performance bottleneck.

To fix this, assertions inside loops in stress tests are replaced with check equivalents (check(a == b) instead of assertEquals(a, b)). Unlike assertEquals, check accepts a lambda for its message, so the diagnostic string is only materialized on failure. Assertions outside loops and in non-stress tests are left unchanged for readability. kotlin.check is already in the Power Assert functions list, so diagnostic output on failure is preserved.

@DmitryNekrasov DmitryNekrasov self-assigned this Feb 26, 2026
list.add(index)
builder.add(index)
assertEquals<List<*>>(list, builder.toList())
check(list == builder.toList())
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

check will throw IAE, Idea will not consider it a regular test failure and <Click to see difference> will be unavailable.

While it may not be an issue for assertion where two trivial values are compared, it will become an issue if two collections containing thousands of elements are not equal and you have to find the diff.

I would suggest waiting for a proper PA support from k-test and enable it then.

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

Successfully merging this pull request may close these issues.

2 participants