1+ import org.gradle.kotlin.dsl.libs
2+
13plugins {
24 kotlin(" jvm" )
35}
@@ -9,47 +11,82 @@ kotlin {
911
1012val mokkeryRuntimeClasspath by configurations.registering
1113
14+ val testBase by sourceSets.registering
15+
1216dependencies {
13- testImplementation(project(" :mokkery-plugin" ))
14- testImplementation(project(" :mokkery-core-tooling" ))
15- testImplementation(libs.kotlin.compiler)
16- testImplementation(libs.kotlin.compiler.test.framework)
17- testImplementation(libs.kotlin.test.junit5)
18- testRuntimeOnly(libs.kotlin.reflect)
19- testRuntimeOnly(libs.kotlin.script.runtime)
20- testRuntimeOnly(libs.kotlin.annotations.jvm)
17+ val testBaseCompileOnly by configurations
18+ testBaseCompileOnly(project(" :mokkery-plugin" ))
19+ testBaseCompileOnly(project(" :mokkery-core-tooling" ))
20+ testBaseCompileOnly(libs.kotlin.compiler)
21+ testBaseCompileOnly(libs.kotlin.compiler.test.framework)
2122 mokkeryRuntimeClasspath(project(" :mokkery-runtime" ))
2223}
2324
24- tasks.register<JavaExec >(" generateTests" ) {
25+ testVariant(kotlinVersion = libs.versions.kotlin.get(), alias = " Default" )
26+ testVariant(kotlinVersion = libs.versions.kotlinMininumSupported.get(), alias = " Minimum" )
27+
28+ val generateTests by tasks.registering {
2529 group = " verification"
26- systemProperty(" mokkeryRuntime.classpath" , mokkeryRuntimeClasspath.get().asPath)
27- inputs
28- .dir(layout.projectDirectory.dir(" src/test/data" ))
29- .withPropertyName(" testData" )
30- .withPathSensitivity(PathSensitivity .RELATIVE )
31- outputs
32- .dir(layout.projectDirectory.dir(" src/test/java" ))
33- .withPropertyName(" generatedTests" )
34- classpath = sourceSets.test.get().runtimeClasspath
35- mainClass.set(" dev.mokkery.tests.GenerateTestsKt" )
36- workingDir = rootDir
30+ dependsOn(tasks.named(" generateTestsDefault" ))
31+ dependsOn(tasks.named(" generateTestsMinimum" ))
32+ }
33+ tasks.test {
34+ dependsOn(tasks.named(" testDefault" ))
35+ dependsOn(tasks.named(" testMinimum" ))
3736}
3837
39- tasks.withType<Test > {
40- dependsOn(mokkeryRuntimeClasspath)
41- inputs
42- .dir(layout.projectDirectory.dir(" src/test/data" ))
43- .withPropertyName(" testData" )
44- .withPathSensitivity(PathSensitivity .RELATIVE )
45-
46- workingDir = rootDir
47-
48- useJUnitPlatform()
38+ fun Project.testVariant (kotlinVersion : String , alias : String = "") {
39+ val sourceSet = sourceSets.register(" test$alias " ) {
40+ java.srcDir(" src/test$alias /java" )
41+ java.srcDir(" src/test$alias /kotlin" )
42+ compileClasspath + = testBase.get().output
43+ runtimeClasspath + = testBase.get().output
44+ }
45+ dependencies {
46+ val testImplementation by configurations.named(sourceSet.get().implementationConfigurationName)
47+ val testRuntimeOnly by configurations.named(sourceSet.get().runtimeOnlyConfigurationName)
48+ testImplementation(project(" :mokkery-plugin" ))
49+ testImplementation(project(" :mokkery-core-tooling" ))
50+ testImplementation(" org.jetbrains.kotlin:kotlin-compiler:$kotlinVersion " )
51+ testImplementation(" org.jetbrains.kotlin:kotlin-compiler-internal-test-framework:$kotlinVersion " )
52+ testImplementation(libs.kotlin.test.junit5)
53+ testRuntimeOnly(libs.kotlin.reflect)
54+ testRuntimeOnly(libs.kotlin.script.runtime)
55+ testRuntimeOnly(libs.kotlin.annotations.jvm)
56+ }
4957
50- systemProperty(" mokkeryRuntime.classpath" , mokkeryRuntimeClasspath.get().asPath)
58+ tasks.register<JavaExec >(" generateTests$alias " ) {
59+ group = " verification"
60+ val testData = layout.projectDirectory.dir(" src/${testBase.get().name} /data" )
61+ val testsRoot = layout.projectDirectory.dir(" src/test$alias /java" )
62+ systemProperty(" testDataRoot" , testData.asFile.relativeTo(rootDir))
63+ systemProperty(" testsRoot" , testsRoot.asFile.relativeTo(rootDir))
64+ systemProperty(" mokkery.runtimeClasspath" , mokkeryRuntimeClasspath.get().asPath)
65+ inputs
66+ .dir(testData)
67+ .withPropertyName(" testData" )
68+ .withPathSensitivity(PathSensitivity .RELATIVE )
69+ outputs
70+ .dir(testsRoot)
71+ .withPropertyName(" generatedTestsRoot" )
72+ classpath + = sourceSet.get().runtimeClasspath
73+ mainClass.set(" dev.mokkery.tests.GenerateTestsKt" )
74+ workingDir = rootDir
75+ }
5176
52- // Properties required to run the internal test framework.
53- systemProperty(" idea.ignore.disabled.plugins" , " true" )
54- systemProperty(" idea.home.path" , rootDir)
77+ tasks.register(" test$alias " , Test ::class ) {
78+ group = " verification"
79+ testClassesDirs + = sourceSet.get().output.classesDirs
80+ classpath + = sourceSet.get().runtimeClasspath
81+ dependsOn(mokkeryRuntimeClasspath)
82+ inputs
83+ .dir(layout.projectDirectory.dir(" src/${testBase.get().name} /data" ))
84+ .withPropertyName(" testData" )
85+ .withPathSensitivity(PathSensitivity .RELATIVE )
86+ workingDir = rootDir
87+ useJUnitPlatform()
88+ systemProperty(" mokkery.runtimeClasspath" , mokkeryRuntimeClasspath.get().asPath)
89+ systemProperty(" idea.ignore.disabled.plugins" , " true" )
90+ systemProperty(" idea.home.path" , rootDir)
91+ }
5592}
0 commit comments