How does Kotest manage to declare tests on Kotlin/...
# kotest
c
How does Kotest manage to declare tests on Kotlin/Native? I don't really understand how the codebase is structured
s
I don't understand the question, can you ask it in a different way
c
To my knowledge, the only way supported by the Kotlin team to declare tests on Native is through the
@Test
annotation. Since Kotest is able to declare tests in loops/conditions, then it can't be doing it like that. So how does it work?
s
Ah I see. Basically uses a compiler plugin, like how kotlin team do it
instead of looking for @test, it looks for kotest specs
c
How difficult are these types of compiler plugins to write?
I really want to be able to declare top-level test functions like this:
Copy code
@Test
fun StringSpecScope.myTestSuite() {
    ...
}
Using JUnit5, it's not hard. I don't know how to declare that top-level function as a test entry point on JS or Native.
o
I'd say this goes against the grain of the whole Kotest architecture. Specs are discovered (on Js and Native: via a compiler plugin). Then each spec's "body" is executed, with test functions registering their test lambdas. To use the above extension function with a spec, you'd have to sort of wrap it into a lambda and register that within the spec's "body".
c
Yes? How does that change anything, other than “less boilerplate”?
o
What do you mean by "less boilerplate"? And given the static declaration above, which individual spec (an object!) would you register it with?
s
I did once play about with putting tests inside kotlin scripts - .kts files. And it worked. You could do
Copy code
val mytest = funSpec {
  // test here
}
And it worked. Each test being a value. But until jetbrains make compiler plugins and kotlin scripts stable, things are changing too rapidly to build on this for a public release.