Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -107,6 +109,7 @@ tasks.compileTestKotlin {
tasks.withType<Test>().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")
}

Expand Down Expand Up @@ -195,3 +198,25 @@ testing {
tasks.withType<Sign>().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()
}
}
4 changes: 4 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
19 changes: 16 additions & 3 deletions src/functionalTest/kotlin/kotlinx/validation/api/TestDsl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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)
}

/**
Expand Down Expand Up @@ -165,7 +172,13 @@ internal class AppendableScope(val filePath: String) {
}

internal class Runner {
val arguments: MutableList<String> = mutableListOf("--configuration-cache")
val arguments: MutableList<String> = mutableListOf<String>().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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class MixedMarkersTest : BaseKotlinGradleTest() {
}
}

runner.withDebug(true).build().apply {
runner.build().apply {
assertTaskSuccess(":apiCheck")
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class PublicMarkersTest : BaseKotlinGradleTest() {
}
}

runner.withDebug(true).build().apply {
runner.build().apply {
assertTaskSuccess(":apiCheck")
}
}
Expand Down