kotlin-power-assert icon indicating copy to clipboard operation
kotlin-power-assert copied to clipboard

Kotest assertions support

Open sergeidyga opened this issue 2 years ago • 2 comments

Hi! Thanks for the awesome plugin!

Is Kotest assertions support planned somewhere in the future?

sergeidyga avatar Jun 01 '22 09:06 sergeidyga

Hello! I don't use Kotest so support for its assertions hasn't been on my radar. kotlin-power-assert can support any function call which allows passing a String to the last parameter, so support may already exist. But again, I'm not familiar with Kotest enough to say for sure.

Stepping back from the original question a bit: what's the end goal? If Kotest isn't providing enough diagnostic information when an assertion fails, that seems like an issue with Kotest. And one of the primary goals of this compiler plugin is to avoid needing a complex assertion library in the first place. Ultimately I'm curious to know your use case for combining these 2 libraries and what benefits you think kotlin-power-assert will add.

bnorm avatar Jun 01 '22 13:06 bnorm

If I may chime in here as another Kotest user: Currently, Kotest's output when asserting equality of data classes (which may contain other data classes) is quite limited. Basically, it just asserts that the toString() representations of the classes are equal. As a result, the message for a failed assertion is long an rather non-telling.

So it would be nice to be able to leverage kotlin-power-assert for writing a Kotest matcher that is able to print some nice diagram about the differences in a hierarchy of nested data classes. In particular, equal data classes in the hierarchy should be skipped to not clutter the assertion output with unnecessary stuff.

sschuberth avatar Jun 08 '23 07:06 sschuberth

Functions with receivers (infix or not) are supported (#68), so all Kotest would need to do is add overloads which also take a string as the last parameter. Then kotlin-power-assert could transform Kotest assertions. See the tests here for an example. Explicit support of Kotest is not within the scope of this plugin, so closing as "not planned".

As for the data class example, I think that falls under #76, as we could diff data classes intelligently if we new their equals function wasn't custom.

bnorm avatar Mar 22 '24 21:03 bnorm