-
Notifications
You must be signed in to change notification settings - Fork 471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] Code constraint argument verification fails when a closure is used inside #994
Comments
def "match code argument with inner closure"() {
List list = Mock()
when:
list.add(['foo'])
then:
1 * list.add({ outer -> outer.any{ it.length() > 1 } })
} The problem seems to be that the inner closure is also treated as a condition closure, which in turn causes it to return null. This becomes even more obvious if the inner condition actually fails, since then it renders as a |
Nice example. Any ideas how hard would it be to fix? |
Also verified code from leonard84 fails only in Spock 1.3 on both Groovy 2.4. and 2.5 (1.3-groovy-2.4 and 1.3-groovy-2.5 respectively). Passes on 1.2-groovy-2.4 and 1.2-groovy-2.5. Here's a workaround (which also proves the issue has something to do with using closures inside a closure argument constraint.):
|
I don't really know how hard it will be, but it's in a tricky part of the https://github.com/spockframework/spock/blob/master/spock-core/src/main/java/org/spockframework/compiler/DeepBlockRewriter.java introduced by 1a84301 |
Issue description
After upgrade to spock 1.3-groovy-2.5 and changing argument verification code constraint blocks according to docs (a check per line without
assert
or&&
), tests with closures inside constraint blocks are failing.How to reproduce
Result:
Link to a gist or similar (optional)
https://gist.github.com/mutyonok/609373367161a0281a494863f4778a2a
Additional Environment information
Java/JDK
1.8.0_201
Groovy version
2.5.3
Build tool version
Gradle
5.3.1
Operating System
macOS X Mojave
IDE
IntelliJ IDEA 2019.1 (Ultimate Edition)
Build #IU-191.6183.87, built on March 27, 2019
JRE: 1.8.0_152-release-991-b1 x86_64
JVM: OpenJDK 64-Bit Server VM by JetBrains s.r.o
macOS 10.14.4
Build-tool dependencies used
Gradle/Grails
The text was updated successfully, but these errors were encountered: