diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 84aefa5fb7..f6192aaa66 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,8 +1,8 @@ [versions] asciidoctorj = '2.5.11' groovy2 = '2.5.23' -groovy3 = '3.0.20' -groovy4 = '4.0.18' +groovy3 = '3.0.21' +groovy4 = '4.0.19' jacoco = '0.8.11' junit = '5.10.2' asm = '9.6' diff --git a/spock-specs/src/test/groovy/org/spockframework/smoke/ast/AstSpec.groovy b/spock-specs/src/test/groovy/org/spockframework/smoke/ast/AstSpec.groovy index a1cfb163e7..c1def86860 100644 --- a/spock-specs/src/test/groovy/org/spockframework/smoke/ast/AstSpec.groovy +++ b/spock-specs/src/test/groovy/org/spockframework/smoke/ast/AstSpec.groovy @@ -15,17 +15,16 @@ package org.spockframework.smoke.ast +import org.codehaus.groovy.control.CompilePhase import org.spockframework.EmbeddedSpecification import org.spockframework.runtime.GroovyRuntimeUtil import org.spockframework.specs.extension.SpockSnapshotter -import spock.lang.Snapshot import org.spockframework.util.GroovyReleaseInfo import org.spockframework.util.VersionNumber import spock.lang.Requires +import spock.lang.Snapshot import spock.util.Show -import org.codehaus.groovy.control.CompilePhase - class AstSpec extends EmbeddedSpecification { @Snapshot(extension = 'groovy') SpockSnapshotter snapshotter @@ -134,6 +133,10 @@ class Foo { } def "enums"() { + given: + // groovy 4 renders differently + def snapshotId = GroovyRuntimeUtil.groovy4orNewer ? "groovy4" : "" + when: def result = compiler.transpile(''' enum Alpha { @@ -144,7 +147,7 @@ class Foo { }) then: - snapshotter.assertThat(result.source).matchesSnapshot() + snapshotter.assertThat(result.source).matchesSnapshot(snapshotId) } def "full feature exercise"() { diff --git a/spock-specs/src/test/resources/org/spockframework/smoke/ast/AstSpec/enums-groovy4.groovy b/spock-specs/src/test/resources/org/spockframework/smoke/ast/AstSpec/enums-groovy4.groovy new file mode 100644 index 0000000000..6d8ddbb51d --- /dev/null +++ b/spock-specs/src/test/resources/org/spockframework/smoke/ast/AstSpec/enums-groovy4.groovy @@ -0,0 +1,47 @@ +public final class Alpha extends java.lang.Enum { + + public static final Alpha A + public static final Alpha B + public static final Alpha C + public static final Alpha MIN_VALUE + public static final Alpha MAX_VALUE + private static final Alpha[] $VALUES + + public static final Alpha[] values() { + return $VALUES.clone() + } + + public Alpha next() { + java.lang.Integer ordinal = this.ordinal() + 1 + if ( ordinal >= $VALUES.length) { + return MIN_VALUE + } + return $VALUES [ ordinal ] + } + + public Alpha previous() { + java.lang.Integer ordinal = this.ordinal() - 1 + if ( ordinal < 0) { + return MAX_VALUE + } + return $VALUES [ ordinal ] + } + + public static Alpha valueOf(java.lang.String name) { + return java.lang.Enum.valueOf(Alpha, name) + } + + public static final Alpha $INIT(java.lang.Object[] para) { + return this (* para ) + } + + static { + A = Alpha.$INIT('A', 0) + B = Alpha.$INIT('B', 1) + C = Alpha.$INIT('C', 2) + MIN_VALUE = A + MAX_VALUE = C + $VALUES = new Alpha[]{A, B, C} + } + +} \ No newline at end of file