From 470fc8200c537e2a51488933d17a9e3843c87591 Mon Sep 17 00:00:00 2001 From: Tyler Bertrand Date: Thu, 2 Nov 2023 16:18:47 -0500 Subject: [PATCH 1/8] Add kotest to supported engines in gradle-test-pts-support scripts --- .../capture-test-pts-support/gradle-test-pts-support.gradle | 3 ++- .../gradle-test-pts-support.gradle.kts | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle b/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle index ea89dec39..25739aa52 100644 --- a/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle +++ b/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle @@ -32,7 +32,8 @@ class Capture { 'org.spockframework.runtime.SpockEngine' : 'spock', 'net.jqwik.engine.JqwikTestEngine' : 'jqwik', 'com.tngtech.archunit.junit.ArchUnitTestEngine' : 'archunit', - 'co.helmethair.scalatest.ScalatestEngine' : 'scalatest' + 'co.helmethair.scalatest.ScalatestEngine' : 'scalatest', + 'io.kotest.runner.junit.platform.KotestJunitPlatformTestEngine' : 'kotest-runner' ] private Logger logger diff --git a/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts b/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts index 1e2e415b8..2b46834df 100644 --- a/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts +++ b/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts @@ -35,7 +35,8 @@ class Capture(val logger: Logger) { "org.spockframework.runtime.SpockEngine" to "spock", "net.jqwik.engine.JqwikTestEngine" to "jqwik", "com.tngtech.archunit.junit.ArchUnitTestEngine" to "archunit", - "co.helmethair.scalatest.ScalatestEngine" to "scalatest" + "co.helmethair.scalatest.ScalatestEngine" to "scalatest", + "io.kotest.runner.junit.platform.KotestJunitPlatformTestEngine" to "kotest-runner" ) fun capturePts(t: Test, api: BuildScanExtension) { From 21098b32d8e51b1b8ad34e61aa7f259bd78ec943 Mon Sep 17 00:00:00 2001 From: Tyler Bertrand Date: Mon, 6 Nov 2023 14:12:02 -0600 Subject: [PATCH 2/8] Update gradle-test-pts-support kotlin script to check that the kotest engine, if used, is a PTS-supported version --- .../gradle-test-pts-support.gradle.kts | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts b/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts index 2b46834df..57820b070 100644 --- a/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts +++ b/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts @@ -57,6 +57,15 @@ class Capture(val logger: Logger) { try { var engines = t.classpath.files.stream().filter { f -> f.name.endsWith(".jar") } .filter { f -> supportedEngines.values.stream().anyMatch { e -> f.name.contains(e) } } + .filter { f -> + if (f.name.contains("kotest-runner")) { + val actualKotestEngine = KotestEngine(f) + val minCompatibleKotestEngine = KotestEngine("5.6.0") + actualKotestEngine >= minCompatibleKotestEngine + } else { + true + } + } .map { f -> findTestEngine(f) } .flatMap { o -> if (o.isPresent()) Stream.of(o.get()) else Stream.empty() } @@ -87,3 +96,30 @@ class Capture(val logger: Logger) { } } } + +class KotestEngine(private val version: String) : Comparable { + + constructor(jarFile: File) : this(jarFile.name.split("-")[jarFile.name.split("-").lastIndex].replace(".jar", "")) + + override fun compareTo(other: KotestEngine): Int { + val thisVersion = parseVersion(version) + val otherVersion = parseVersion(other.version) + + for (i in 0..2) { + val comparison = thisVersion[i].compareTo(otherVersion[i]) + if (comparison != 0) { + return thisVersion[i].compareTo(otherVersion[i]) + } + } + return 0 + } + + private fun parseVersion(version: String): List { + val parsedVersion: MutableList = mutableListOf() + val splitVersion = version.split(".") + for (i in 0..2) { + parsedVersion.add(splitVersion[i].toInt()) + } + return parsedVersion + } +} From 921b8a089c7ee470e13a4b54e2bd050ca202f74d Mon Sep 17 00:00:00 2001 From: Tyler Bertrand Date: Tue, 7 Nov 2023 17:41:49 -0600 Subject: [PATCH 3/8] Update gradle-test-pts-support kotlin script to use Gradle's VersionNumber to compare kotest versions --- .../gradle-test-pts-support.gradle.kts | 37 ++++--------------- 1 file changed, 7 insertions(+), 30 deletions(-) diff --git a/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts b/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts index 57820b070..f99d791ae 100644 --- a/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts +++ b/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts @@ -59,9 +59,13 @@ class Capture(val logger: Logger) { .filter { f -> supportedEngines.values.stream().anyMatch { e -> f.name.contains(e) } } .filter { f -> if (f.name.contains("kotest-runner")) { - val actualKotestEngine = KotestEngine(f) - val minCompatibleKotestEngine = KotestEngine("5.6.0") - actualKotestEngine >= minCompatibleKotestEngine + val kotestVersionString = f.name.split("-")[f.name.split("-").lastIndex].replace(".jar", "") + val kotestVersion = VersionNumber.parse(kotestVersionString) + if (VersionNumber.UNKNOWN == kotestVersion) { + logger.warn("Unable to parse kotest version from file name ${f.name}") + return@filter false + } + VersionNumber.parse("5.6.0") <= kotestVersion } else { true } @@ -96,30 +100,3 @@ class Capture(val logger: Logger) { } } } - -class KotestEngine(private val version: String) : Comparable { - - constructor(jarFile: File) : this(jarFile.name.split("-")[jarFile.name.split("-").lastIndex].replace(".jar", "")) - - override fun compareTo(other: KotestEngine): Int { - val thisVersion = parseVersion(version) - val otherVersion = parseVersion(other.version) - - for (i in 0..2) { - val comparison = thisVersion[i].compareTo(otherVersion[i]) - if (comparison != 0) { - return thisVersion[i].compareTo(otherVersion[i]) - } - } - return 0 - } - - private fun parseVersion(version: String): List { - val parsedVersion: MutableList = mutableListOf() - val splitVersion = version.split(".") - for (i in 0..2) { - parsedVersion.add(splitVersion[i].toInt()) - } - return parsedVersion - } -} From 96313fe06639eef9f20d540df523563288401a75 Mon Sep 17 00:00:00 2001 From: Tyler Bertrand Date: Wed, 8 Nov 2023 09:46:05 -0600 Subject: [PATCH 4/8] Use org.gradle.util.internal.VersionNumber, as org.gradle.util.VersionNumber will be removed in Gradle 9.0 --- .../capture-test-pts-support/gradle-test-pts-support.gradle.kts | 1 + 1 file changed, 1 insertion(+) diff --git a/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts b/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts index f99d791ae..6d7d5e598 100644 --- a/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts +++ b/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts @@ -1,5 +1,6 @@ import com.gradle.enterprise.gradleplugin.GradleEnterpriseExtension import com.gradle.scan.plugin.BuildScanExtension +import org.gradle.util.internal.VersionNumber import java.nio.charset.StandardCharsets import java.util.Collections import java.util.Optional From 1f5b5b313ced4657292ed79fae588f12d7cbb896 Mon Sep 17 00:00:00 2001 From: Tyler Bertrand Date: Wed, 8 Nov 2023 10:31:08 -0600 Subject: [PATCH 5/8] Extract inline predicate filtering out incompatible kotest versions to property --- .../gradle-test-pts-support.gradle.kts | 29 ++++++++++--------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts b/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts index 6d7d5e598..e23d2b52c 100644 --- a/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts +++ b/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts @@ -4,6 +4,7 @@ import org.gradle.util.internal.VersionNumber import java.nio.charset.StandardCharsets import java.util.Collections import java.util.Optional +import java.util.function.Predicate import java.util.jar.JarFile import java.util.stream.Stream import java.util.stream.Collectors @@ -58,19 +59,7 @@ class Capture(val logger: Logger) { try { var engines = t.classpath.files.stream().filter { f -> f.name.endsWith(".jar") } .filter { f -> supportedEngines.values.stream().anyMatch { e -> f.name.contains(e) } } - .filter { f -> - if (f.name.contains("kotest-runner")) { - val kotestVersionString = f.name.split("-")[f.name.split("-").lastIndex].replace(".jar", "") - val kotestVersion = VersionNumber.parse(kotestVersionString) - if (VersionNumber.UNKNOWN == kotestVersion) { - logger.warn("Unable to parse kotest version from file name ${f.name}") - return@filter false - } - VersionNumber.parse("5.6.0") <= kotestVersion - } else { - true - } - } + .filter(filterIncompatibleKotestVersions) .map { f -> findTestEngine(f) } .flatMap { o -> if (o.isPresent()) Stream.of(o.get()) else Stream.empty() } @@ -100,4 +89,18 @@ class Capture(val logger: Logger) { } } } + + private val filterIncompatibleKotestVersions = Predicate { jar -> + if (jar.name.contains("kotest-runner")) { + val kotestVersionString = jar.name.split("-")[jar.name.split("-").lastIndex].replace(".jar", "") + val kotestVersion = VersionNumber.parse(kotestVersionString) + if (VersionNumber.UNKNOWN == kotestVersion) { + logger.warn("Unable to parse kotest version from file name ${jar.name}") + return@Predicate false + } + VersionNumber.parse("5.6.0") <= kotestVersion + } else { + true + } + } } From 8075ccf925ca054ed84f79392d5550218d2fc9a6 Mon Sep 17 00:00:00 2001 From: Tyler Bertrand Date: Wed, 8 Nov 2023 11:47:43 -0600 Subject: [PATCH 6/8] Log error and add custom value indicating that kotest version could not be parsed from kotest-runner jar name --- .../gradle-test-pts-support.gradle.kts | 33 ++++++++++--------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts b/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts index e23d2b52c..54b2cc0fb 100644 --- a/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts +++ b/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts @@ -18,18 +18,18 @@ import groovy.transform.Field project.extensions.configure() { buildScan { val api = buildScan - val capture = Capture(gradle.rootProject.logger) + val capture = Capture(api, gradle.rootProject.logger) allprojects { tasks.withType().configureEach { doFirst { - capture.capturePts(this as Test, api) + capture.capturePts(this as Test) } } } } } -class Capture(val logger: Logger) { +class Capture(val api: BuildScanExtension, val logger: Logger) { val supportedEngines: Map = mapOf( "org.junit.support.testng.engine.TestNGTestEngine" to "testng", "org.junit.jupiter.engine.JupiterTestEngine" to "junit-jupiter", @@ -41,7 +41,7 @@ class Capture(val logger: Logger) { "io.kotest.runner.junit.platform.KotestJunitPlatformTestEngine" to "kotest-runner" ) - fun capturePts(t: Test, api: BuildScanExtension) { + fun capturePts(t: Test) { if (t.getTestFramework()::class.java.name == "org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestFramework") { val engines = testEngines(t) api.value("${t.identityPath}#engines", "${engines}") @@ -59,7 +59,7 @@ class Capture(val logger: Logger) { try { var engines = t.classpath.files.stream().filter { f -> f.name.endsWith(".jar") } .filter { f -> supportedEngines.values.stream().anyMatch { e -> f.name.contains(e) } } - .filter(filterIncompatibleKotestVersions) + .filter(filterIncompatibleKotestVersions(t)) .map { f -> findTestEngine(f) } .flatMap { o -> if (o.isPresent()) Stream.of(o.get()) else Stream.empty() } @@ -90,17 +90,20 @@ class Capture(val logger: Logger) { } } - private val filterIncompatibleKotestVersions = Predicate { jar -> - if (jar.name.contains("kotest-runner")) { - val kotestVersionString = jar.name.split("-")[jar.name.split("-").lastIndex].replace(".jar", "") - val kotestVersion = VersionNumber.parse(kotestVersionString) - if (VersionNumber.UNKNOWN == kotestVersion) { - logger.warn("Unable to parse kotest version from file name ${jar.name}") - return@Predicate false + private fun filterIncompatibleKotestVersions(t: Test): Predicate { + return Predicate { jar -> + if (jar.name.contains("kotest-runner")) { + val kotestVersionString = jar.name.split("-")[jar.name.split("-").lastIndex].replace(".jar", "") + val kotestVersion = VersionNumber.parse(kotestVersionString) + if (VersionNumber.UNKNOWN == kotestVersion) { + logger.error("Unable to parse kotest version from file name ${jar.name}") + api.value("${t.identityPath}#unknownKotestVersion", "${jar.name}") + return@Predicate false + } + return@Predicate VersionNumber.parse("5.6.0") <= kotestVersion + } else { + return@Predicate true } - VersionNumber.parse("5.6.0") <= kotestVersion - } else { - true } } } From dad18c848da301e6c148a9101dd0b68e8ffabc13 Mon Sep 17 00:00:00 2001 From: Tyler Bertrand Date: Wed, 8 Nov 2023 14:26:46 -0600 Subject: [PATCH 7/8] Update groovy gradle-test-pots-support script to include kotest v5.6.0+ as a PTS-compatible test engine --- .../gradle-test-pts-support.gradle | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle b/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle index 25739aa52..4246a2712 100644 --- a/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle +++ b/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle @@ -1,7 +1,9 @@ import com.gradle.scan.plugin.BuildScanExtension +import org.gradle.util.internal.VersionNumber import java.nio.charset.StandardCharsets import java.util.Collections import java.util.Optional +import java.util.function.Predicate import java.util.jar.JarFile import java.util.stream.Stream import java.util.stream.Collectors @@ -15,11 +17,11 @@ def buildScanApi = project.extensions.findByName('buildScan') if (!buildScanApi) { return } -def capture = new Capture(gradle.rootProject.logger) +def capture = new Capture(buildScanApi, gradle.rootProject.logger) allprojects { tasks.withType(Test).configureEach { t -> doFirst { - capture.capturePts(t, buildScanApi) + capture.capturePts(t) } } } @@ -36,12 +38,14 @@ class Capture { 'io.kotest.runner.junit.platform.KotestJunitPlatformTestEngine' : 'kotest-runner' ] private Logger logger + private BuildScanExtension buildScanApi - Capture(Logger logger) { + Capture(BuildScanExtension buildScanApi, Logger logger) { + this.buildScanApi = buildScanApi this.logger = logger } - void capturePts(Test t, BuildScanExtension buildScanApi) { + void capturePts(Test t) { if (t.getTestFramework().getClass().getName() == 'org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestFramework') { def engines = testEngines(t) buildScanApi.value("${t.identityPath}#engines", "${engines}") @@ -60,6 +64,7 @@ class Capture { Stream engines = t.classpath.files.stream() .filter { f -> f.name.endsWith('.jar') } .filter { f -> supportedEngines.values().stream().anyMatch { e -> f.name.contains(e) } } + .filter(filterIncompatibleKotestVersions(t)) .map { f -> findTestEngine(f) } .flatMap { o -> o.isPresent() ? Stream.of(o.get()) : Stream.empty() } @@ -85,4 +90,21 @@ class Capture { .map { e -> jarFile.getInputStream(e).withCloseable { it.getText(StandardCharsets.UTF_8.name()).trim() } } } } + + Predicate filterIncompatibleKotestVersions(Test t) { + return { jar -> + if (jar.name.contains("kotest-runner")) { + def kotestVersionString = jar.name.split("-")[jar.name.split("-").length - 1].replace(".jar", "") + def kotestVersion = VersionNumber.parse(kotestVersionString) + if (VersionNumber.UNKNOWN == kotestVersion) { + logger.error("Unable to parse kotest version from file name ${jar.name}") + buildScanApi.value("${t.identityPath}#unknownKotestVersion", "${jar.name}") + return false + } + return VersionNumber.parse("5.6.0") <= kotestVersion + } else { + return true + } + } + } } From 39cc16c57036da5053840a6fc614a9f2782fa8d5 Mon Sep 17 00:00:00 2001 From: Tyler Bertrand Date: Thu, 9 Nov 2023 09:35:24 -0600 Subject: [PATCH 8/8] Fix misleading filterIncompatibleKotestVersion name and use method returning boolean to perform filtering instead of predicate --- .../gradle-test-pts-support.gradle | 27 +++++++++---------- .../gradle-test-pts-support.gradle.kts | 27 +++++++++---------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle b/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle index 4246a2712..f015f6d5e 100644 --- a/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle +++ b/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle @@ -3,7 +3,6 @@ import org.gradle.util.internal.VersionNumber import java.nio.charset.StandardCharsets import java.util.Collections import java.util.Optional -import java.util.function.Predicate import java.util.jar.JarFile import java.util.stream.Stream import java.util.stream.Collectors @@ -64,7 +63,7 @@ class Capture { Stream engines = t.classpath.files.stream() .filter { f -> f.name.endsWith('.jar') } .filter { f -> supportedEngines.values().stream().anyMatch { e -> f.name.contains(e) } } - .filter(filterIncompatibleKotestVersions(t)) + .filter { f -> isCompatibleVersion(f, t) } .map { f -> findTestEngine(f) } .flatMap { o -> o.isPresent() ? Stream.of(o.get()) : Stream.empty() } @@ -91,20 +90,18 @@ class Capture { } } - Predicate filterIncompatibleKotestVersions(Test t) { - return { jar -> - if (jar.name.contains("kotest-runner")) { - def kotestVersionString = jar.name.split("-")[jar.name.split("-").length - 1].replace(".jar", "") - def kotestVersion = VersionNumber.parse(kotestVersionString) - if (VersionNumber.UNKNOWN == kotestVersion) { - logger.error("Unable to parse kotest version from file name ${jar.name}") - buildScanApi.value("${t.identityPath}#unknownKotestVersion", "${jar.name}") - return false - } - return VersionNumber.parse("5.6.0") <= kotestVersion - } else { - return true + boolean isCompatibleVersion(File f, Test t) { + if (f.name.contains("kotest-runner")) { + def kotestVersionString = f.name.split("-")[f.name.split("-").length - 1].replace(".jar", "") + def kotestVersion = VersionNumber.parse(kotestVersionString) + if (VersionNumber.UNKNOWN == kotestVersion) { + logger.error("Unable to parse kotest version from file name ${f.name}") + buildScanApi.value("${t.identityPath}#unknownKotestVersion", "${f.name}") + return false } + return VersionNumber.parse("5.6.0") <= kotestVersion + } else { + return true } } } diff --git a/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts b/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts index 54b2cc0fb..8be3aaf4c 100644 --- a/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts +++ b/build-data-capturing-gradle-samples/capture-test-pts-support/gradle-test-pts-support.gradle.kts @@ -4,7 +4,6 @@ import org.gradle.util.internal.VersionNumber import java.nio.charset.StandardCharsets import java.util.Collections import java.util.Optional -import java.util.function.Predicate import java.util.jar.JarFile import java.util.stream.Stream import java.util.stream.Collectors @@ -59,7 +58,7 @@ class Capture(val api: BuildScanExtension, val logger: Logger) { try { var engines = t.classpath.files.stream().filter { f -> f.name.endsWith(".jar") } .filter { f -> supportedEngines.values.stream().anyMatch { e -> f.name.contains(e) } } - .filter(filterIncompatibleKotestVersions(t)) + .filter { f -> isCompatibleVersion(f, t) } .map { f -> findTestEngine(f) } .flatMap { o -> if (o.isPresent()) Stream.of(o.get()) else Stream.empty() } @@ -90,20 +89,18 @@ class Capture(val api: BuildScanExtension, val logger: Logger) { } } - private fun filterIncompatibleKotestVersions(t: Test): Predicate { - return Predicate { jar -> - if (jar.name.contains("kotest-runner")) { - val kotestVersionString = jar.name.split("-")[jar.name.split("-").lastIndex].replace(".jar", "") - val kotestVersion = VersionNumber.parse(kotestVersionString) - if (VersionNumber.UNKNOWN == kotestVersion) { - logger.error("Unable to parse kotest version from file name ${jar.name}") - api.value("${t.identityPath}#unknownKotestVersion", "${jar.name}") - return@Predicate false - } - return@Predicate VersionNumber.parse("5.6.0") <= kotestVersion - } else { - return@Predicate true + private fun isCompatibleVersion(f: File, t: Test): Boolean { + if (f.name.contains("kotest-runner")) { + val kotestVersionString = f.name.split("-")[f.name.split("-").lastIndex].replace(".jar", "") + val kotestVersion = VersionNumber.parse(kotestVersionString) + if (VersionNumber.UNKNOWN == kotestVersion) { + logger.error("Unable to parse kotest version from file name ${f.name}") + api.value("${t.identityPath}#unknownKotestVersion", "${f.name}") + return false } + return VersionNumber.parse("5.6.0") <= kotestVersion + } else { + return true } } }