Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-3861

AST transforms of spock do not take effect when the library is loaded using @Grab

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.6.3
    • 1.6.6, 1.7-rc-1
    • None
    • None

    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

        1. 3861_v16x.txt
          12 kB
          Roshan Dawrani
        2. 3861_v16x_V2.txt
          13 kB
          Roshan Dawrani

        Issue Links

          Activity

            People

              roshandawrani Roshan Dawrani
              roshandawrani Roshan Dawrani
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: