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
34 changes: 34 additions & 0 deletions kover-gradle-plugin/examples/jvm/copy-variant/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
plugins {
kotlin("jvm") version "1.7.10"
id("org.jetbrains.kotlinx.kover") version "0.8.1"
}

dependencies {
implementation(project(":first"))
implementation(project(":second"))
testImplementation(kotlin("test"))
}

kover {
merge {
subprojects()

createVariant("aggregated") {
add("jvm")
}
}

currentProject {
copyVariant("first", "aggregated")
copyVariant("second", "aggregated")
}

reports {
variant("first") {
filters.includes.projects.add(":first")
}
variant("second") {
filters.includes.projects.add(":second")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
kotlin("jvm")
}

dependencies {
testImplementation(kotlin("test"))
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package kotlinx.kover.examples.merged.subproject.utils

class SubprojectUtils {
fun minus(a: Int, b: Int): Int {
if (b < 0) return 0
return a - b
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package kotlinx.kover.examples.merged

class SubprojectFirstClass {
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,18 @@
package kotlinx.kover.examples.merged.subproject

import kotlin.math.*

class SubprojectSecondClass {
fun formatDouble(d: Double): String {
if (d.roundToInt().toDouble() == d) {
return "INTEGER=${d.roundToInt()}"
} else {
return "FRACTIONAL=$d"
}
}

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

import kotlin.test.Test

class TestClasses {
@Test
fun testThisProject() {
SubprojectFirstClass().printClass()
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
plugins {
kotlin("jvm")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package kotlinx.kover.examples.merged

class ClassFromSecondProject {
fun foo() {
println("Hello")
}
}
16 changes: 16 additions & 0 deletions kover-gradle-plugin/examples/jvm/copy-variant/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pluginManagement {
repositories {
gradlePluginPortal()
mavenCentral()
}
}
rootProject.name = "copy-variant"

include(":first")
include(":second")

dependencyResolutionManagement {
repositories {
mavenCentral()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package kotlinx.kover.examples.merged

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,8 @@
package kotlinx.kover.examples.merged.utils

class MergedUtils {
fun sum(a: Int, b: Int): Int {
if (a < 0 && b < 0) return 0
return a + b
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package kotlinx.kover.examples.merged

import kotlinx.kover.examples.merged.subproject.*
import kotlin.test.Test

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

@Test
fun testExcludedProject() {
ClassFromSecondProject().foo()
}

@Test
fun testSubproject() {
SubprojectFirstClass().formatInt(42)
SubprojectSecondClass().formatDouble(4.2)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ internal class ExamplesBuildTests {
// build only
}

@ExamplesTest("jvm/copy-variant", ["koverXmlReportFirst", "koverXmlReportSecond"])
fun CheckerContext.jvmCopyVariant() {
xmlReport("first") {
// only classes from `first` project are present
classCounter("kotlinx.kover.examples.merged.SubprojectFirstClass").assertCovered()
classCounter("kotlinx.kover.examples.merged.ClassFromSecondProject").assertAbsent()
}

xmlReport("second") {
// only classes from `second` project are present
classCounter("kotlinx.kover.examples.merged.SubprojectFirstClass").assertAbsent()
classCounter("kotlinx.kover.examples.merged.ClassFromSecondProject").assertCovered()
}
}

@ExamplesTest("android/minimal_groovy")
fun CheckerContext.androidGroovy() {
// build only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,6 @@ internal fun KoverContext.finalizing(origins: AllVariantOrigins) {
jvmVariant?.let { variantArtifacts[JVM_VARIANT_NAME] = it }
androidVariants.forEach { variantArtifacts[it.variantName] = it }

val availableVariants = variantArtifacts.keys + projectExtension.currentProject.customVariants.keys
projectExtension.reports.byName.forEach { (requestedVariant, _) ->
if (requestedVariant !in availableVariants) {
throw KoverIllegalConfigException("It is not possible to configure the '$requestedVariant' variant because it does not exist")
}
}

val totalVariant =
TotalVariantArtifacts(project, toolProvider, koverBucketConfiguration, variantConfig(TOTAL_VARIANT_NAME), projectExtension)
variantArtifacts.values.forEach { totalVariant.mergeWith(it) }
Expand Down