Allow more functions to be processed
TWiStErRob opened this issue · comments
Similar to #5, but generalizing: I think this could be expanded to support more method calls, configurable by the user with some good defaults:
check
,require
,assert
(stdlib),assertTrue
,assertFalse
(from kotlin.test),assertTrue
,assertFalse
(from JUnit 4/5),powerAssert
(e.g., companion lib from this repo),- etc...
This way multiplatform is solved too, I guess?
For parameterized compiler plugin I think allopen could give a hint.
I think this library could definitely be expanded to support other functions. Using this for require
had come to mind and I think all of the suggested functions would be reasonable.
I'm going to focus on support for assert
right now but I'll try and make sure to leave it open for using with other functions.
This is now mostly supported with the latest changes. The plugin now supports any functions of the form (Boolean [, String])
or (Boolean [, () -> (String|CharSequence|Any)])
which fail when the condition is false. assert
, required
, check
, and assertTrue
are able to be injected with the improved message.
Gradle configuration:
configure<com.bnorm.power.PowerAssertGradleExtension> {
functions = listOf("kotlin.test.AssertionsKt.assertTrue", "kotlin.PreconditionsKt.require")
}
(Haven't figured out a way to remove the generated class name from the FQ name yet)
Wow, awesome!
Haven't figured out a way to remove the generated class name from the FQ name yet
You could add aliases inside for known functions ("kotlin.test.assertTrue" to "kotlin.test.AssertionsKt.assertTrue"), others would have to be FQ, that's ok.
As this is now supported, I'm going to close this issue and open a few others that are more specific to different function signatures.