Hey all. I’ve been pondering idly how much I miss ...
# announcements
r
Hey all. I’ve been pondering idly how much I miss Spock’s syntax in Kotlin, and found myself wondering whether it’s even possible to implement the same thing? Spock uses some groovy feature that allows rewriting the AST, I think.
1
(I know I can just use the actual Spock with groovy, just wondering if it could ever be ported to Kotlin or if the facilities just don’t exist.)
v
As a member of the Spock team and a fan of Kotlin for Gradle related stuff I majorly hope so too. Some things can never work like not declaring variables from the where block, because it is not valid Kotlin syntax. But things like the power assertions and the mocking and stubbing should hopefully work using a compiler plugin like the all-open plugin that makes classes open that are not in the source. But it would need someone putting the effort into trying to make it work including the risk that it maybe does not work in the end.
👍 1
y
like the power assertions
IIRC there's already a compiler plugin for that called kotlin-power-assert
v
Yep, that might be nice for using conventional test tools / assertion libraries. But for Spock there is more like in the respective blocks each expression statement is an implicit assertion without the need to explicitly assert and so on. But at least it proves that such things are possible.
r
Some things can never work like not declaring variables from the where block, because it is not valid Kotlin syntax
It sort of isn’t valid groovy syntax either, is it? I thought that Spock had to rearrange the AST to allow you to declare your variables after you use them and without a
def
or a type. Unfortunately the
where
syntax (and not needing to assert in the
then
block) are the things that make the tests so readable, shifting the clutter out of the way.
v
All Spock code is valid Groovy code. It first has to pass the Groovy parser before we can apply the AST magic. Groovy is highly dynamic, a variable could be added at runtime to some object, thus using undeclared variables works just fine as long as it is present at runtime. The AST transformation then declares it properly as needed. The
where
and
then
syntax should probably be possible, just that you need to declare the variables as parameters.
👍 1