Skip to content
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

Nested asserts cannot be transformed #1232

Closed
paplorinc opened this issue Nov 2, 2020 · 13 comments · Fixed by #1239
Closed

Nested asserts cannot be transformed #1232

paplorinc opened this issue Nov 2, 2020 · 13 comments · Fixed by #1239
Labels

Comments

@paplorinc
Copy link
Contributor

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

@kriegaex
Copy link
Contributor

kriegaex commented Nov 3, 2020

This test also fails on the previous milestone M3. It passes on Spock 1.3, though, if this is where you come from. Did it ever pass on any 2.x version for you?

@kriegaex
Copy link
Contributor

kriegaex commented Nov 3, 2020

@leonard84, is this somehow contextually related to #783?

@paplorinc
Copy link
Contributor Author

We've only tried with 1.3, where this was working before.

@rtretyak
Copy link
Contributor

Hope the above pr fixes it for feature methods as well, because it is also a thing in 2.0-M4-groovy-3.0. this code does not compile in 2.0-M4 but works fine in 1.3

    def test() {
        expect:
        with([1,2]) {
            it.size() > 0
            it.each { assert it > 0 }
        }
    }

@Vampire
Copy link
Member

Vampire commented Dec 5, 2020

Yes @rtretyak the PR fixes both.
In both was the problem only when you did not have any top-level condition and as with does return void it is not considered a condition.

@kriegaex
Copy link
Contributor

kriegaex commented Dec 6, 2020

As the merged PR does not contain any regression tests - is that a good idea? - I just built the current master and manually ran the tests presented by @paplorinc and @rtretyak this issue. They both pass now.

@Vampire
Copy link
Member

Vampire commented Dec 6, 2020

@kriegaex
Copy link
Contributor

kriegaex commented Dec 6, 2020

Yes, because when glancing at the file list - I did not scroll to read the code - I was looking for *Test or *Spec. 😉

image

I just saw RecorderScope, did not notice smoke. Sorry for that. Strange naming, though.

@Vampire
Copy link
Member

Vampire commented Dec 6, 2020

Yeah, naming is not too consistent in some points in Spock sources :-D

@Vampire
Copy link
Member

Vampire commented Dec 6, 2020

Basically everything in spock-specs is either test or fixture

@kriegaex
Copy link
Contributor

kriegaex commented Dec 6, 2020

My bad entirely. But an additional re-test does not hurt, it was worth 5 minutes of my lifetime. :-)

@Vampire
Copy link
Member

Vampire commented Dec 6, 2020

Yes, definitely, thanks for verifying fixes, also an important contribution. :-)

@paplorinc
Copy link
Contributor Author

The latest SNAPSHOT seems to have fixed these, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants