Skip to content

Nested asserts cannot be transformed #1232

Closed
@l0rinc

Description

@l0rinc

Hey,

We've just tried out latest Spock 2.0-M4, we're getting the following exception:

Task :compileTestGroovy
startup failed:
NestedAssertTest.groovy: -1: The current scope already contains a variable of the name $spock_errorCollector
@ line -1, column -1.
NestedAssertTest.groovy: -1: The current scope already contains a variable of the name $spock_valueRecorder
@ line -1, column -1.
2 errors

The cause seems to be that nested asserts seem to generate conflicting code, irrespective of their level or other previously generated ones (can be "".with {} or whatever closure):

def nestedAssert() {
    tap {
        assert 0
        tap { assert 0 }
    }
}

The following reproducer can be used by running ./gradlew build:
https://github.com/paplorinc/spock-bug/blob/master/src/test/groovy/NestedAssertTest.groovy

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions