We are writing a DSL in Kotlin, and we have added a few restrictions in that DSL. For eg,
table {
tr {
td {
}
}
}
Here, we restrict td
should not be called inside another td
.
How do we test this? Is there any dsl-testkit or matcher library in kotlin that lets us do something like "shouldNot compile" does in scalatest
One solution is to use the Kotlin scripting engine, make it run a script with your DSL constructs that should be rejected and assert that the script didn't compile.
Links that you may find useful:
s1monw1/KtsRunner
, a library that encapsulates running Kotlin scripts programmatically