spockframework / spockframework/spock

Error when pretty-printing multi-line conditions

Open
#253 16 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Module-Core Type-Defect
Dominant language
Java
Stars
3.6k
Forks
483
PR merge metrics
No merged PRs in 30d

Description

Originally reported on Google Code with ID 131

When a multi-line condition fails, chances are that ExpressionInfoBuilder fails to compile
the condition after flattening. Example:

expect:
[1,2,3].every {
  println it
  it > 1
}

Result:

Spec expression: 1: expecting '}', found 'it' @ line 1, column 28.
   [1,2,3].every { println it it > 1 }
                              ^

1 error

    at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:296)
    at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:103)
    at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:142)
    at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:113)
    at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:125)
    at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:353)
    at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:105)
    at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:72)
    at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:249)
    at org.spockframework.runtime.ExpressionInfoBuilder.build(ExpressionInfoBuilder.java:50)
    at org.spockframework.runtime.Condition.getExpression(Condition.java:65)
    at org.spockframework.runtime.JUnitSupervisor.isCausedByFailedEqualityComparison(JUnitSupervisor.java:117)
    at org.spockframework.runtime.JUnitSupervisor.error(JUnitSupervisor.java:92)
    at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:237)
    at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:217)
    at org.spockframework.runtime.BaseSpecRunner.invokeFeatureMethod(BaseSpecRunner.java:204)
    at org.spockframework.runtime.BaseSpecRunner.runSimpleFeature(BaseSpecRunner.java:182)
    at org.spockframework.runtime.BaseSpecRunner.doRunFeature(BaseSpecRunner.java:174)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:235)
    at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:217)
    at org.spockframework.runtime.BaseSpecRunner.runFeature(BaseSpecRunner.java:152)
    at org.spockframework.runtime.BaseSpecRunner.runFeatures(BaseSpecRunner.java:129)
    at org.spockframework.runtime.BaseSpecRunner.doRun(BaseSpecRunner.java:96)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.spockframework.runtime.BaseSpecRunner.invokeRaw(BaseSpecRunner.java:235)
    at org.spockframework.runtime.BaseSpecRunner.invoke(BaseSpecRunner.java:217)
    at org.spockframework.runtime.BaseSpecRunner.run(BaseSpecRunner.java:73)
    at org.spockframework.runtime.Sputnik.run(Sputnik.java:57)
    at org.apache.maven.surefire.junit4.JUnit4TestSet.execute(JUnit4TestSet.java:59)
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:115)
    at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:102)
    at org.apache.maven.surefire.Surefire.run(Surefire.java:180)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:350)
    at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:1021)


Reported by pniederw on 2010-10-08 16:55:44

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with ExpressionInfoBuilder.build at the location shown in the stack trace, using the multi-line [1,2,3].every condition as the reproduction. Trace how the condition is flattened before compilation and verify that a failed multi-line condition is pretty-printed without a compilation error.

Written by the indexing model from the issue text.

Assessment

Tech stack
groovy, java
Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.