Skip to content

Commit 30339f3

Browse files
qwwdfsadpablobaxter
authored andcommitted
Integrate Kover (Kotlin#3141)
1 parent b4cf872 commit 30339f3

File tree

7 files changed

+91
-4
lines changed

7 files changed

+91
-4
lines changed

build.gradle

+4-2
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ buildscript {
5858
classpath "com.moowork.gradle:gradle-node-plugin:$gradle_node_version"
5959
classpath "org.jetbrains.kotlinx:binary-compatibility-validator:$binary_compatibility_validator_version"
6060
classpath "ru.vyarus:gradle-animalsniffer-plugin:1.5.3" // Android API check
61+
classpath "org.jetbrains.kotlinx:kover:$kover_version"
6162

6263
// JMH plugins
6364
classpath "com.github.jengelman.gradle.plugins:shadow:5.1.0"
@@ -105,7 +106,8 @@ allprojects {
105106
}
106107

107108
apply plugin: "binary-compatibility-validator"
108-
apply plugin: 'base'
109+
apply plugin: "base"
110+
apply plugin: "kover-conventions"
109111

110112
apiValidation {
111113
ignoredProjects += unpublished + ["kotlinx-coroutines-bom"]
@@ -303,7 +305,7 @@ def publishTasks = getTasksByName("publish", true) + getTasksByName("publishNpm"
303305

304306
task deploy(dependsOn: publishTasks)
305307

306-
apply plugin: 'animalsniffer-convention'
308+
apply plugin: "animalsniffer-conventions"
307309

308310
clean.dependsOn gradle.includedBuilds.collect { it.task(':clean') }
309311

buildSrc/build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,5 @@ dependencies {
6060
exclude(group = "org.jetbrains.kotlin", module = "kotlin-stdlib")
6161
}
6262
implementation("ru.vyarus:gradle-animalsniffer-plugin:1.5.3") // Android API check
63+
implementation("org.jetbrains.kotlinx:kover:${version("kover")}")
6364
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import kotlinx.kover.api.*
2+
import kotlinx.kover.tasks.*
3+
4+
/*
5+
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
6+
*/
7+
apply(plugin = "kover")
8+
9+
val notCovered = sourceless + internal + unpublished
10+
11+
val expectedCoverage = mutableMapOf(
12+
// These have lower coverage in general, it can be eventually fixed
13+
"kotlinx-coroutines-swing" to 70,
14+
"kotlinx-coroutines-android" to 50,
15+
"kotlinx-coroutines-javafx" to 39, // JavaFx is not tested on TC because its graphic subsystem cannot be initialized in headless mode
16+
17+
// TODO figure it out, these probably should be fixed
18+
"kotlinx-coroutines-debug" to 84,
19+
"kotlinx-coroutines-reactive" to 65,
20+
"kotlinx-coroutines-reactor" to 65,
21+
"kotlinx-coroutines-rx2" to 78,
22+
"kotlinx-coroutines-slf4j" to 81
23+
)
24+
25+
extensions.configure<KoverExtension> {
26+
disabledProjects = notCovered
27+
/*
28+
* Is explicitly enabled on TC in a separate build step.
29+
* Examples:
30+
* ./gradlew :p:check -- doesn't verify coverage
31+
* ./gradlew :p:check -Pkover.enabled=true -- verifies coverage
32+
* ./gradlew :p:koverReport -Pkover.enabled=true -- generates report
33+
*/
34+
isDisabled = !(properties["kover.enabled"]?.toString()?.toBoolean() ?: false)
35+
}
36+
37+
subprojects {
38+
val projectName = name
39+
if (projectName in notCovered) return@subprojects
40+
tasks.withType<KoverVerificationTask> {
41+
rule {
42+
bound {
43+
/*
44+
* 85 is our baseline that we aim to raise to 90+.
45+
* Missing coverage is typically due to bugs in the agent
46+
* (e.g. signatures deprecated with an error are counted),
47+
* sometimes it's various diagnostic `toString` or `catch` for OOMs/VerificationErrors,
48+
* but some places are definitely worth visiting.
49+
*/
50+
minValue = expectedCoverage[projectName] ?: 85 // COVERED_LINES_PERCENTAGE
51+
}
52+
}
53+
}
54+
}

gradle.properties

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ rxjava2_version=2.2.8
2222
rxjava3_version=3.0.2
2323
javafx_version=11.0.2
2424
javafx_plugin_version=0.0.8
25-
binary_compatibility_validator_version=0.8.0-RC
25+
binary_compatibility_validator_version=0.8.0
26+
kover_version=0.5.0-RC2
2627
blockhound_version=1.0.2.RELEASE
2728
jna_version=5.9.0
2829

kotlinx-coroutines-core/build.gradle

+23-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ static void configureJvmForLincheck(task) {
256256
task.minHeapSize = '1g'
257257
task.maxHeapSize = '4g' // we may need more space for building an interleaving tree in the model checking mode
258258
task.jvmArgs = ['--add-opens', 'java.base/jdk.internal.misc=ALL-UNNAMED', // required for transformation
259-
'--add-exports', 'java.base/jdk.internal.util=ALL-UNNAMED'] // in the model checking mode
259+
'--add-exports', 'java.base/jdk.internal.util=ALL-UNNAMED'] // in the model checking mode
260260
task.systemProperty 'kotlinx.coroutines.semaphore.segmentSize', '2'
261261
task.systemProperty 'kotlinx.coroutines.semaphore.maxSpinCycles', '1' // better for the model checking mode
262262
}
@@ -265,6 +265,28 @@ static void configureJvmForLincheck(task) {
265265
task moreTest(dependsOn: [jvmStressTest, jvmLincheckTest])
266266
check.dependsOn moreTest
267267

268+
tasks.jvmLincheckTest {
269+
kover {
270+
enabled = false // Always disabled, lincheck doesn't really support coverage
271+
}
272+
}
273+
274+
def commonKoverExcludes =
275+
["kotlinx.coroutines.test.*", // Deprecated package for removal
276+
"kotlinx.coroutines.debug.*", // Tested by debug module
277+
"kotlinx.coroutines.channels.ChannelsKt__DeprecatedKt.*", // Deprecated
278+
"kotlinx.coroutines.scheduling.LimitingDispatcher", // Deprecated
279+
"kotlinx.coroutines.scheduling.ExperimentalCoroutineDispatcher" // Deprecated
280+
]
281+
282+
tasks.koverHtmlReport {
283+
excludes = commonKoverExcludes
284+
}
285+
286+
tasks.koverVerify {
287+
excludes = commonKoverExcludes
288+
}
289+
268290
task testsJar(type: Jar, dependsOn: jvmTestClasses) {
269291
classifier = 'tests'
270292
from compileTestKotlinJvm.destinationDir

ui/kotlinx-coroutines-android/build.gradle.kts

+7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
* Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
33
*/
44

5+
import kotlinx.kover.api.*
6+
57
configurations {
68
create("r8")
79
}
@@ -103,3 +105,8 @@ open class RunR8 : JavaExec() {
103105
}
104106
}
105107

108+
tasks.withType<Test> {
109+
extensions.configure<KoverTaskExtension> {
110+
excludes = excludes + listOf("com.android.*", "android.*") // Exclude robolectric-generated classes
111+
}
112+
}

0 commit comments

Comments
 (0)