Skip to content

Commit

Permalink
Move DataProviders expected ast to snapshots
Browse files Browse the repository at this point in the history
  • Loading branch information
leonard84 committed Apr 28, 2024
1 parent e0c19c7 commit c9ee05f
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package org.spockframework.smoke.parameterization

import org.spockframework.EmbeddedSpecification
import org.spockframework.runtime.SpockExecutionException
import org.spockframework.specs.extension.SpockSnapshotter
import spock.lang.*
import spock.util.Show

Expand Down Expand Up @@ -103,7 +104,10 @@ where: x << []
}

@Issue("https://github.com/spockframework/spock/issues/1287")
def "data provider with asserting closure produces error rethrower variable in data provider method"() {
def "data provider with asserting closure produces error rethrower variable in data provider method"(@Snapshot SpockSnapshotter snapshotter) {
given:
snapshotter.specBody()

when:
def result = compiler.transpileFeatureBody('''
where:
Expand All @@ -112,30 +116,7 @@ where: x << []
''', EnumSet.of(Show.METHODS))

then:
result.source == '''\
public void $spock_feature_0_0(java.lang.Object dataPipe, java.lang.Object dataVariable) {
this.getSpecificationContext().getMockController().leaveScope()
}
public java.lang.Object $spock_feature_0_0prov0() {
org.spockframework.runtime.ErrorCollector $spock_errorCollector = org.spockframework.runtime.ErrorRethrower.INSTANCE
return [{ ->
org.spockframework.runtime.ValueRecorder $spock_valueRecorder1 = new org.spockframework.runtime.ValueRecorder()
try {
org.spockframework.runtime.SpockRuntime.verifyCondition($spock_errorCollector, $spock_valueRecorder1.reset(), 'true', 2, 29, null, $spock_valueRecorder1.record($spock_valueRecorder1.startRecordingValue(0), true))
}
catch (java.lang.Throwable $spock_condition_throwable) {
org.spockframework.runtime.SpockRuntime.conditionFailedWithException($spock_errorCollector, $spock_valueRecorder1, 'true', 2, 29, null, $spock_condition_throwable)}
finally {
}
}]
}
public java.lang.Object $spock_feature_0_0proc(java.lang.Object $spock_p0) {
java.lang.Object dataPipe = (( $spock_p0 ) as java.lang.Object)
java.lang.Object dataVariable = ((null) as java.lang.Object)
return new java.lang.Object[]{ dataPipe , dataVariable }
}'''
snapshotter.assertThat(result.source).matchesSnapshot()
}

@Issue("https://github.com/spockframework/spock/issues/1287")
Expand All @@ -152,7 +133,10 @@ public java.lang.Object $spock_feature_0_0proc(java.lang.Object $spock_p0) {
}

@Issue("https://github.com/spockframework/spock/issues/1287")
def "data variable with asserting closure produces error rethrower variable in data processor method"() {
def "data variable with asserting closure produces error rethrower variable in data processor method"(@Snapshot SpockSnapshotter snapshotter) {
given:
snapshotter.specBody()

when:
def result = compiler.transpileFeatureBody('''
where:
Expand All @@ -161,30 +145,7 @@ public java.lang.Object $spock_feature_0_0proc(java.lang.Object $spock_p0) {
''', EnumSet.of(Show.METHODS))

then:
result.source == '''\
public void $spock_feature_0_0(java.lang.Object dataPipe, java.lang.Object dataVariable) {
this.getSpecificationContext().getMockController().leaveScope()
}
public java.lang.Object $spock_feature_0_0prov0() {
return [null]
}
public java.lang.Object $spock_feature_0_0proc(java.lang.Object $spock_p0) {
org.spockframework.runtime.ErrorCollector $spock_errorCollector = org.spockframework.runtime.ErrorRethrower.INSTANCE
java.lang.Object dataPipe = (( $spock_p0 ) as java.lang.Object)
java.lang.Object dataVariable = (({ ->
org.spockframework.runtime.ValueRecorder $spock_valueRecorder1 = new org.spockframework.runtime.ValueRecorder()
try {
org.spockframework.runtime.SpockRuntime.verifyCondition($spock_errorCollector, $spock_valueRecorder1.reset(), 'true', 3, 31, null, $spock_valueRecorder1.record($spock_valueRecorder1.startRecordingValue(0), true))
}
catch (java.lang.Throwable $spock_condition_throwable) {
org.spockframework.runtime.SpockRuntime.conditionFailedWithException($spock_errorCollector, $spock_valueRecorder1, 'true', 3, 31, null, $spock_condition_throwable)}
finally {
}
}) as java.lang.Object)
return new java.lang.Object[]{ dataPipe , dataVariable }
}'''
snapshotter.assertThat(result.source).matchesSnapshot()
}

@Issue("https://github.com/spockframework/spock/issues/1287")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package aPackage
import spock.lang.*

class ASpec extends Specification {
/*--------- tag::snapshot[] ---------*/
public void $spock_feature_0_0(java.lang.Object dataPipe, java.lang.Object dataVariable) {
this.getSpecificationContext().getMockController().leaveScope()
}

public java.lang.Object $spock_feature_0_0prov0() {
org.spockframework.runtime.ErrorCollector $spock_errorCollector = org.spockframework.runtime.ErrorRethrower.INSTANCE
return [{ ->
org.spockframework.runtime.ValueRecorder $spock_valueRecorder1 = new org.spockframework.runtime.ValueRecorder()
try {
org.spockframework.runtime.SpockRuntime.verifyCondition($spock_errorCollector, $spock_valueRecorder1.reset(), 'true', 2, 29, null, $spock_valueRecorder1.record($spock_valueRecorder1.startRecordingValue(0), true))
}
catch (java.lang.Throwable $spock_condition_throwable) {
org.spockframework.runtime.SpockRuntime.conditionFailedWithException($spock_errorCollector, $spock_valueRecorder1, 'true', 2, 29, null, $spock_condition_throwable)}
finally {
}
}]
}

public java.lang.Object $spock_feature_0_0proc(java.lang.Object $spock_p0) {
java.lang.Object dataPipe = (( $spock_p0 ) as java.lang.Object)
java.lang.Object dataVariable = ((null) as java.lang.Object)
return new java.lang.Object[]{ dataPipe , dataVariable }
}
/*--------- end::snapshot[] ---------*/
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package aPackage
import spock.lang.*

class ASpec extends Specification {
/*--------- tag::snapshot[] ---------*/
public void $spock_feature_0_0(java.lang.Object dataPipe, java.lang.Object dataVariable) {
this.getSpecificationContext().getMockController().leaveScope()
}

public java.lang.Object $spock_feature_0_0prov0() {
return [null]
}

public java.lang.Object $spock_feature_0_0proc(java.lang.Object $spock_p0) {
org.spockframework.runtime.ErrorCollector $spock_errorCollector = org.spockframework.runtime.ErrorRethrower.INSTANCE
java.lang.Object dataPipe = (( $spock_p0 ) as java.lang.Object)
java.lang.Object dataVariable = (({ ->
org.spockframework.runtime.ValueRecorder $spock_valueRecorder1 = new org.spockframework.runtime.ValueRecorder()
try {
org.spockframework.runtime.SpockRuntime.verifyCondition($spock_errorCollector, $spock_valueRecorder1.reset(), 'true', 3, 31, null, $spock_valueRecorder1.record($spock_valueRecorder1.startRecordingValue(0), true))
}
catch (java.lang.Throwable $spock_condition_throwable) {
org.spockframework.runtime.SpockRuntime.conditionFailedWithException($spock_errorCollector, $spock_valueRecorder1, 'true', 3, 31, null, $spock_condition_throwable)}
finally {
}
}) as java.lang.Object)
return new java.lang.Object[]{ dataPipe , dataVariable }
}
/*--------- end::snapshot[] ---------*/
}

0 comments on commit c9ee05f

Please sign in to comment.