Details
Description
Try the following script in groovy console
import spock.lang.* @Grab(group='org.spockframework', module='spock-core', version='0.2') class HelloSpock extends Specification { def "can you figure out what I'm up to?"() { expect: name.size() == length where: ignored = println ("where: \n p0=$p0\n p1=$p1") name << ["Kirk", "Spock", "Scotty"] length << [4, 5, 6] } }
Output:
JUnit 4 Runner, Tests: 1, Failures: 1, Time: 0 Test Failure: initializationError(HelloSpock) org.spockframework.runtime.InvalidSpeckError: Class 'HelloSpock' is not a Speck, or has not been compiled properly at org.spockframework.runtime.SpeckInfoBuilder.getSpeckMetadata(SpeckInfoBuilder.java:66) at org.spockframework.runtime.SpeckInfoBuilder.build(SpeckInfoBuilder.java:46) at spock.lang.Sputnik.<init>(Sputnik.java:38) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ....
This is happening because spock works by ASTTransformation and before @Grab(spock) has brought spock jar on groovy classpath, groovy does not see its AST transforms and hence the class does not undergo spock related AST transformation and does not run as a spock test.
However, from the 2nd run onwards, it runs from the same console because in the 2nd run, when groovy scans for AST transforms, it finds spock jar also on the classpath and its AST transformation happens and the class runs as a spock test.
Attachments
Issue Links
| This issue relates to: | ||||
| GROOVY-3851 | @Grapes does not work (at least not in Groovy Console) |
|
|
|
I was trying a way to fix this issue but I have hit a little stumbling block. The issue is related to adding new phase operations in the list that is being iterated.
So Grab annotation gets processed in phase CONVERSION and spock has this transform called EarlyTransform, which is also to be added in the phase CONVERSION.
Now the list that contains phase operations of CONVERSION is getting iterated when it calls GrabAnnotationTransformation, which then results in addition of new spock transform EarlyTransform to the same list causing ConcurrentModificationException.
Any suggestions there?