Skip to content

Commit

Permalink
Added a filter of source sets
Browse files Browse the repository at this point in the history
Resolves #376

PR #395
  • Loading branch information
shanshin committed Jun 1, 2023
1 parent d59373e commit fb94c52
Show file tree
Hide file tree
Showing 20 changed files with 297 additions and 228 deletions.
7 changes: 6 additions & 1 deletion api/kover-gradle-plugin.api
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ public abstract interface class kotlinx/kover/gradle/plugin/dsl/KoverProjectExte
public abstract fun disable ()V
public abstract fun excludeInstrumentation (Lorg/gradle/api/Action;)V
public abstract fun excludeJavaCode ()V
public abstract fun excludeSourceSets (Lorg/gradle/api/Action;)V
public abstract fun excludeTests (Lorg/gradle/api/Action;)V
public fun filters (Lkotlin/jvm/functions/Function0;)V
public fun getEngine ()Ljava/lang/Void;
Expand Down Expand Up @@ -232,7 +233,6 @@ public abstract interface class kotlinx/kover/gradle/plugin/dsl/KoverReportsConf

public abstract interface class kotlinx/kover/gradle/plugin/dsl/KoverTestsExclusions {
public fun getExcludeTasks ()Ljava/util/List;
public abstract fun mppTargetName ([Ljava/lang/String;)V
public abstract fun tasks (Ljava/lang/Iterable;)V
public abstract fun tasks ([Ljava/lang/String;)V
}
Expand Down Expand Up @@ -306,3 +306,8 @@ public final class kotlinx/kover/gradle/plugin/dsl/MetricType : java/lang/Enum {
public static fun values ()[Lkotlinx/kover/gradle/plugin/dsl/MetricType;
}

public abstract interface class kotlinx/kover/gradle/plugin/dsl/SourceSetsExclusions {
public abstract fun names (Ljava/lang/Iterable;)V
public abstract fun names ([Ljava/lang/String;)V
}

18 changes: 18 additions & 0 deletions docs/gradle-plugin/configuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- [Configuring Android reports](#configuring-android-reports)
- [Reports filtering](#reports-filtering)
- [Class name with wildcards](#class-name-with-wildcards)
- [Configuring measurements](#configuring-measurements)
- [Verification](#verification)
- [Merging reports](#merging-reports)

Expand Down Expand Up @@ -386,6 +387,23 @@ Examples:
* (bad) `my/package/ClassName.kt`
* (bad) `src/my.**.ClassName`

## Configuring measurements
The configuration of measurements can affect not only the content of the report in a particular project, but also the instrumentation of the code and reports in all projects that depend on the configurable.

### Exclusion of JVM source sets

It is possible to exclude from all reports the code declared in certain source sets.

As a side effect, the generation of Kover reports ceases to depend on the compilation tasks of these source sets.

```kotlin
kover {
excludeSourceSets {
names("test1", "extra")
}
}
```

## Verification
When checking a certain verification rule, the entire code is divided into units of code for which it determines whether it was covered (executed) or skipped (not executed).
For example, an entire line from source code or a specific JVM instruction from compiled byte-code can be executed or not.
Expand Down
2 changes: 0 additions & 2 deletions docs/gradle-plugin/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,6 @@ This means that even if a class is specified in both the inclusion and exclusion

[Wildcards](configuring#class-name-with-wildcards) `*` and `?` are allowed in class names.

## Kover configuration


## Kover Tasks
### Kover default tasks
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package kotlinx.kover.gradle.plugin.test.functional.cases

import kotlinx.kover.gradle.plugin.test.functional.framework.checker.CheckerContext
import kotlinx.kover.gradle.plugin.test.functional.framework.checker.defaultXmlReport
import kotlinx.kover.gradle.plugin.test.functional.framework.starter.TemplateTest

internal class CompilationFiltersTests {
@TemplateTest("sourcesets", ["koverXmlReport"])
fun CheckerContext.testJvmSourceSetFilter() {
xml(defaultXmlReport()) {
classCounter("kotlinx.kover.examples.sourcesets.ExtraClass").assertAbsent()
}
}

@TemplateTest("sourcesets-mpp", ["koverXmlReport"])
fun CheckerContext.testMppSourceSetFilter() {
xml(defaultXmlReport()) {
classCounter("kotlinx.kover.examples.sourcesets.ExtraClass").assertAbsent()
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ internal class KoverWriter(private val writer: FormattedWriter) : KoverProjectEx
writer.call("excludeTests", config) { KoverTestsExclusionsWriter(it) }
}

internal fun excludeCompilations(config: Action<KoverCompilationsExclusions>) {
writer.call("excludeCompilations", config) { KoverCompilationsExclusionsWriter(it) }
override fun excludeSourceSets(config: Action<SourceSetsExclusions>) {
writer.call("excludeCompilations", config) { SourceSetsExclusionsWriter(it) }
}

override fun excludeInstrumentation(config: Action<KoverInstrumentationExclusions>) {
Expand All @@ -47,48 +47,17 @@ private class KoverTestsExclusionsWriter(private val writer: FormattedWriter) :
override fun tasks(names: Iterable<String>) {
writer.callStr("tasks", names)
}

override fun mppTargetName(vararg name: String) {
writer.callStr("mppTargetName", name.asIterable())
}
}

private class KoverCompilationsExclusionsWriter(private val writer: FormattedWriter) : KoverCompilationsExclusions {
private class SourceSetsExclusionsWriter(private val writer: FormattedWriter) : SourceSetsExclusions {

override fun jvm(config: Action<KoverJvmSourceSet>) {
writer.call("jvm", config) { KoverJvmSourceSetWriter(it) }
override fun names(vararg name: String) {
names(name.toList())
}

override fun mpp(config: Action<KoverMppSourceSet>) {
writer.call("mpp", config) { KoverMppSourceSetWriter(it) }
override fun names(names: Iterable<String>) {
writer.callStr("names", names)
}

}

private class KoverJvmSourceSetWriter(private val writer: FormattedWriter): KoverJvmSourceSet {
override fun sourceSetName(vararg name: String) {
sourceSetName(name.asIterable())
}

override fun sourceSetName(names: Iterable<String>) {
writer.callStr("sourceSetName", names)
}

}

private class KoverMppSourceSetWriter(private val writer: FormattedWriter): KoverMppSourceSet {
override fun targetName(vararg name: String) {
writer.callStr("targetName", name.asIterable())
}

override fun compilation(targetName: String, compilationName: String) {
writer.callStr("compilation", listOf(targetName, compilationName))
}

override fun compilation(compilationName: String) {
writer.callStr("compilation", listOf(compilationName))
}

}

private class KoverInstrumentationExclusionsWriter(private val writer: FormattedWriter) :
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
plugins {
kotlin("multiplatform") version "1.7.10"
id("org.jetbrains.kotlinx.kover") version "0.7.0"
}

repositories {
mavenCentral()
}

kover {
excludeSourceSets {
names("extra")
}
}

sourceSets.create("extra")

kotlin {
jvm {
withJava()
}

sourceSets {
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
}
}
rootProject.name = "example-source-sets-mpp"

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package kotlinx.kover.examples.sourcesets

class ExtraClass {
fun function() {
println("Example")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package kotlinx.kover.examples.sourcesets

class ExampleClass {
fun formatInt(i: Int): String {
if (i == 0) return "ZERO"
return if (i > 0) {
"POSITIVE=$i"
} else {
"NEGATIVE=${-i}"
}
}

fun printClass() {
val name = this::class.qualifiedName
println(name)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package kotlinx.kover.examples.sourcesets

import kotlin.test.Test

class TestClasses {
@Test
fun test() {
ExampleClass().formatInt(50)
}
}
20 changes: 20 additions & 0 deletions src/functionalTest/templates/builds/sourcesets/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
plugins {
kotlin("jvm") version "1.7.10"
id("org.jetbrains.kotlinx.kover") version "0.7.0"
}

repositories {
mavenCentral()
}

sourceSets.create("extra")

kover {
excludeSourceSets {
names("extra")
}
}

dependencies {
testImplementation(kotlin("test"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
}
}
rootProject.name = "example-source-sets"

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package kotlinx.kover.examples.sourcesets

class ExtraClass {
fun function() {
println("Example")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package kotlinx.kover.examples.sourcesets

class ExampleClass {
fun formatInt(i: Int): String {
if (i == 0) return "ZERO"
return if (i > 0) {
"POSITIVE=$i"
} else {
"NEGATIVE=${-i}"
}
}

fun printClass() {
val name = this::class.qualifiedName
println(name)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package kotlinx.kover.examples.sourcesets

import kotlin.test.Test

class TestClasses {
@Test
fun test() {
ExampleClass().formatInt(50)
}
}
Loading

0 comments on commit fb94c52

Please sign in to comment.