From d5ddb7a577905a324fec8169077396b825614dd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonard=20Br=C3=BCnings?= Date: Wed, 31 Aug 2022 16:07:20 +0200 Subject: [PATCH] WIP experiment with using test-suites for xVtests --- build.gradle | 7 +- .../smoke/mock/JavaSpies.groovy | 6 +- spock-spring/spring.gradle | 93 +++++++++++++++---- 3 files changed, 84 insertions(+), 22 deletions(-) diff --git a/build.gradle b/build.gradle index 3cdbeabd5a..b3c8e911b4 100755 --- a/build.gradle +++ b/build.gradle @@ -122,8 +122,10 @@ subprojects { } tasks.withType(JavaCompile) { - javaCompiler = javaToolchains.compilerFor { - languageVersion = JavaLanguageVersion.of(8) + if (it.name == 'compileJava') { + javaCompiler = javaToolchains.compilerFor { + languageVersion = JavaLanguageVersion.of(8) + } } options.encoding = 'UTF-8' } @@ -183,7 +185,6 @@ subprojects { from javadoc } - def javaVersionNoShadow = javaVersion // Test task also has javaVersion tasks.withType(Test) { useJUnitPlatform() def taskName = name diff --git a/spock-specs/src/test/groovy/org/spockframework/smoke/mock/JavaSpies.groovy b/spock-specs/src/test/groovy/org/spockframework/smoke/mock/JavaSpies.groovy index 25b4f02af4..33550af279 100644 --- a/spock-specs/src/test/groovy/org/spockframework/smoke/mock/JavaSpies.groovy +++ b/spock-specs/src/test/groovy/org/spockframework/smoke/mock/JavaSpies.groovy @@ -201,6 +201,11 @@ class JavaSpies extends Specification { e.message.contains("global") } + + @IgnoreIf( + value = { jvm.java17Compatible }, + reason = "We can't access private fields in java.util anymore, without an explicit --add-opens" + ) @Issue("https://github.com/spockframework/spock/issues/822") def "inferred type is ignored for instance mocks"() { when: @@ -301,4 +306,3 @@ class JavaSpies extends Specification { } } } - diff --git a/spock-spring/spring.gradle b/spock-spring/spring.gradle index 302a0b1592..43d9a01552 100755 --- a/spock-spring/spring.gradle +++ b/spock-spring/spring.gradle @@ -1,3 +1,7 @@ +plugins { + id 'jvm-test-suite' +} + apply from: script("publishMaven") ext.displayName = "Spock Framework - Spring Module" @@ -6,9 +10,22 @@ description = "Spock's Spring Module makes it possible to use Spring's TestConte Supports Spring 2.5.x, 3.x, and 4.x." def springVersion = "4.3.5.RELEASE" +def testSpringVersions = [ + "3.2.16.RELEASE": (8..8), + (springVersion): (8..11), + "5.0.2.RELEASE": (8..11), + "6.0.0-M5": (17..17) +].findAll { javaVersion in it.value } -if (springVersion.startsWith("2.")) { - sourceSets.test.groovy.exclude "**/*ContextHierarchyExample.groovy" +// necessary until we have a final version of Spring 6 +repositories { + mavenCentral() + maven { + url = "https://repo.spring.io/artifactory/libs-milestone-local/" + content { + includeGroup "org.springframework" + } + } } dependencies { @@ -16,23 +33,62 @@ dependencies { compileOnly "org.springframework:spring-test:$springVersion" compileOnly "org.springframework:spring-beans:$springVersion" compileOnly "org.springframework:spring-context:$springVersion" +} + +testing { + suites { + all { + useJUnitJupiter() + dependencies { + implementation "javax.inject:javax.inject:1" + implementation libs.groovySql // for groovy.sql.Sql + implementation libs.junitPlatformTestkit + runtimeOnly libs.h2database + runtimeOnly libs.log4j + runtimeOnly libs.bytebuddy + runtimeOnly libs.cglib + runtimeOnly libs.objenesis + } + } - // not used directly at implementation-time, but needed by groovyc - testImplementation "org.springframework:spring-test:$springVersion" - testImplementation "org.springframework:spring-beans:$springVersion" - testImplementation "org.springframework:spring-context:$springVersion" - testImplementation "org.springframework:spring-core:$springVersion" - testImplementation "org.springframework:spring-jdbc:$springVersion" - testImplementation "org.springframework:spring-tx:$springVersion" - testImplementation "javax.inject:javax.inject:1" - testImplementation libs.groovySql // for groovy.sql.Sql - testImplementation libs.junitPlatformTestkit - - testRuntimeOnly libs.h2database - testRuntimeOnly libs.log4j - testRuntimeOnly libs.bytebuddy - testRuntimeOnly libs.cglib - testRuntimeOnly libs.objenesis + test { + targets { + all { + testTask.configure { + onlyIf { false } //skip normal test task + } + } + } + } + + + testSpringVersions.each { testSpringVersion, __ -> + "spring${testSpringVersion.charAt(0)}"(JvmTestSuite) { + + sources { + java { + srcDir 'src/test/java' + } + groovy { + srcDir 'src/test/groovy' + } + resources { + srcDir 'src/test/resources' + } + } + + dependencies { + implementation project + implementation "org.springframework:spring-test:$testSpringVersion" + implementation "org.springframework:spring-beans:$testSpringVersion" + implementation "org.springframework:spring-context:$testSpringVersion" + implementation "org.springframework:spring-core:$testSpringVersion" + implementation "org.springframework:spring-jdbc:$testSpringVersion" + implementation "org.springframework:spring-tx:$testSpringVersion" + } + } + } + } } task testCglib(type: Test) { @@ -41,6 +97,7 @@ task testCglib(type: Test) { } check.dependsOn testCglib +check.dependsOn testSpringVersions.collect {k,v -> "spring${k.charAt(0)}" } jar { manifest {