diff --git a/build.gradle.kts b/build.gradle.kts index c70df01c..1e18b4e0 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,3 +1,4 @@ +import kotlinx.kover.gradle.plugin.dsl.MetricType import kotlinx.validation.build.mavenCentralMetadata import kotlinx.validation.build.mavenRepositoryPublishing import kotlinx.validation.build.signPublicationIfKeyPresent @@ -14,6 +15,7 @@ plugins { `maven-publish` `jvm-test-suite` id("org.jetbrains.kotlinx.binary-compatibility-validator") + alias(libs.plugins.kover) } group = "org.jetbrains.kotlinx" @@ -107,6 +109,7 @@ tasks.compileTestKotlin { tasks.withType().configureEach { systemProperty("overwrite.output", System.getProperty("overwrite.output", "false")) systemProperty("testCasesClassesDirs", sourceSets.test.get().output.classesDirs.asPath) + systemProperty("kover.enabled", project.findProperty("kover.enabled")?.toString().toBoolean()) jvmArgs("-ea") } @@ -195,3 +198,25 @@ testing { tasks.withType().configureEach { onlyIf("only sign if signatory is present") { signatory?.keyId != null } } + +kover { + koverReport { + filters { + excludes { + packages("kotlinx.validation.test") + } + } + verify { + rule { + minBound(80, MetricType.BRANCH) + minBound(90, MetricType.LINE) + } + } + } + // Unfortunately, we can't test both configuration cache use and the test coverage + // simultaneously, so the coverage collection should be enabled explicitly (and that + // will disable configuration cache). + if (!project.findProperty("kover.enabled")?.toString().toBoolean()) { + disable() + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index a605b9f1..bb028625 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -39,3 +39,7 @@ gradlePlugin-pluginPublishing = { module = "com.gradle.publish:plugin-publish-pl gradlePlugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } gradlePlugin-android = { module = "com.android.tools.build:gradle", version.ref = "androidGradlePlugin" } ## endregion + +[plugins] + +kover = { id = "org.jetbrains.kotlinx.kover", version = "0.7.5" } diff --git a/src/functionalTest/kotlin/kotlinx/validation/api/TestDsl.kt b/src/functionalTest/kotlin/kotlinx/validation/api/TestDsl.kt index 831c1a14..cfa25799 100644 --- a/src/functionalTest/kotlin/kotlinx/validation/api/TestDsl.kt +++ b/src/functionalTest/kotlin/kotlinx/validation/api/TestDsl.kt @@ -12,6 +12,8 @@ import org.intellij.lang.annotations.Language public val API_DIR: String = ApiValidationExtension().apiDumpDirectory +private val koverEnabled: Boolean = System.getProperty("kover.enabled").toBoolean() + internal fun BaseKotlinGradleTest.test( gradleVersion: String = "8.5", injectPluginClasspath: Boolean = true, @@ -38,14 +40,19 @@ internal fun BaseKotlinGradleTest.test( .withPluginClasspath() .withArguments(baseKotlinScope.runner.arguments) .withGradleVersion(gradleVersion) + + if (koverEnabled) { + // In debug mode, tests will be running inside the same JVM. + // That will allow collection coverage info by the Kover. + runner.withDebug(true) + } + if (injectPluginClasspath) { // The hack dating back to https://docs.gradle.org/6.0/userguide/test_kit.html#sub:test-kit-classpath-injection // Currently, some tests won't work without it because some classes are missing on the classpath. runner.addPluginTestRuntimeClasspath() } return runner - // disabled because of: https://github.com/gradle/gradle/issues/6862 - // .withDebug(baseKotlinScope.runner.debug) } /** @@ -165,7 +172,13 @@ internal class AppendableScope(val filePath: String) { } internal class Runner { - val arguments: MutableList = mutableListOf("--configuration-cache") + val arguments: MutableList = mutableListOf().apply { + if (!koverEnabled) { + // Configuration cache is incompatible with javaagents being enabled for Gradle + // See https://github.com/gradle/gradle/issues/25979 + add("--configuration-cache") + } + } } internal fun readFileList(@Language("file-reference") fileName: String): String { diff --git a/src/functionalTest/kotlin/kotlinx/validation/test/MixedMarkersTest.kt b/src/functionalTest/kotlin/kotlinx/validation/test/MixedMarkersTest.kt index 0c89f317..e97e664a 100644 --- a/src/functionalTest/kotlin/kotlinx/validation/test/MixedMarkersTest.kt +++ b/src/functionalTest/kotlin/kotlinx/validation/test/MixedMarkersTest.kt @@ -31,7 +31,7 @@ class MixedMarkersTest : BaseKotlinGradleTest() { } } - runner.withDebug(true).build().apply { + runner.build().apply { assertTaskSuccess(":apiCheck") } } diff --git a/src/functionalTest/kotlin/kotlinx/validation/test/PublicMarkersTest.kt b/src/functionalTest/kotlin/kotlinx/validation/test/PublicMarkersTest.kt index cf4963b8..e03ee69e 100644 --- a/src/functionalTest/kotlin/kotlinx/validation/test/PublicMarkersTest.kt +++ b/src/functionalTest/kotlin/kotlinx/validation/test/PublicMarkersTest.kt @@ -41,7 +41,7 @@ class PublicMarkersTest : BaseKotlinGradleTest() { } } - runner.withDebug(true).build().apply { + runner.build().apply { assertTaskSuccess(":apiCheck") } }