Skip to content

Commit f8d3b5e

Browse files
authored
Added test on copyVariant function
PR #632
1 parent 3bee2a8 commit f8d3b5e

File tree

14 files changed

+183
-7
lines changed

14 files changed

+183
-7
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
plugins {
2+
kotlin("jvm") version "1.7.10"
3+
id("org.jetbrains.kotlinx.kover") version "0.8.1"
4+
}
5+
6+
dependencies {
7+
implementation(project(":first"))
8+
implementation(project(":second"))
9+
testImplementation(kotlin("test"))
10+
}
11+
12+
kover {
13+
merge {
14+
subprojects()
15+
16+
createVariant("aggregated") {
17+
add("jvm")
18+
}
19+
}
20+
21+
currentProject {
22+
copyVariant("first", "aggregated")
23+
copyVariant("second", "aggregated")
24+
}
25+
26+
reports {
27+
variant("first") {
28+
filters.includes.projects.add(":first")
29+
}
30+
variant("second") {
31+
filters.includes.projects.add(":second")
32+
}
33+
}
34+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
plugins {
2+
kotlin("jvm")
3+
}
4+
5+
dependencies {
6+
testImplementation(kotlin("test"))
7+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package kotlinx.kover.examples.merged.subproject.utils
2+
3+
class SubprojectUtils {
4+
fun minus(a: Int, b: Int): Int {
5+
if (b < 0) return 0
6+
return a - b
7+
}
8+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package kotlinx.kover.examples.merged
2+
3+
class SubprojectFirstClass {
4+
fun formatInt(i: Int): String {
5+
if (i == 0) return "ZERO"
6+
return if (i > 0) {
7+
"POSITIVE=$i"
8+
} else {
9+
"NEGATIVE=${-i}"
10+
}
11+
}
12+
13+
fun printClass() {
14+
val name = this::class.qualifiedName
15+
println(name)
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package kotlinx.kover.examples.merged.subproject
2+
3+
import kotlin.math.*
4+
5+
class SubprojectSecondClass {
6+
fun formatDouble(d: Double): String {
7+
if (d.roundToInt().toDouble() == d) {
8+
return "INTEGER=${d.roundToInt()}"
9+
} else {
10+
return "FRACTIONAL=$d"
11+
}
12+
}
13+
14+
fun printClass() {
15+
val name = this::class.qualifiedName
16+
println(name)
17+
}
18+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package kotlinx.kover.examples.merged
2+
3+
import kotlin.test.Test
4+
5+
class TestClasses {
6+
@Test
7+
fun testThisProject() {
8+
SubprojectFirstClass().printClass()
9+
}
10+
11+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
plugins {
2+
kotlin("jvm")
3+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package kotlinx.kover.examples.merged
2+
3+
class ClassFromSecondProject {
4+
fun foo() {
5+
println("Hello")
6+
}
7+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
pluginManagement {
2+
repositories {
3+
gradlePluginPortal()
4+
mavenCentral()
5+
}
6+
}
7+
rootProject.name = "copy-variant"
8+
9+
include(":first")
10+
include(":second")
11+
12+
dependencyResolutionManagement {
13+
repositories {
14+
mavenCentral()
15+
}
16+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package kotlinx.kover.examples.merged
2+
3+
class ExampleClass {
4+
fun formatInt(i: Int): String {
5+
if (i == 0) return "ZERO"
6+
return if (i > 0) {
7+
"POSITIVE=$i"
8+
} else {
9+
"NEGATIVE=${-i}"
10+
}
11+
}
12+
13+
fun printClass() {
14+
val name = this::class.qualifiedName
15+
println(name)
16+
}
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package kotlinx.kover.examples.merged.utils
2+
3+
class MergedUtils {
4+
fun sum(a: Int, b: Int): Int {
5+
if (a < 0 && b < 0) return 0
6+
return a + b
7+
}
8+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package kotlinx.kover.examples.merged
2+
3+
import kotlinx.kover.examples.merged.subproject.*
4+
import kotlin.test.Test
5+
6+
class TestClasses {
7+
@Test
8+
fun testThisProject() {
9+
ExampleClass().formatInt(50)
10+
}
11+
12+
@Test
13+
fun testExcludedProject() {
14+
ClassFromSecondProject().foo()
15+
}
16+
17+
@Test
18+
fun testSubproject() {
19+
SubprojectFirstClass().formatInt(42)
20+
SubprojectSecondClass().formatDouble(4.2)
21+
}
22+
}

kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/cases/ExamplesBuildTests.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,21 @@ internal class ExamplesBuildTests {
2424
// build only
2525
}
2626

27+
@ExamplesTest("jvm/copy-variant", ["koverXmlReportFirst", "koverXmlReportSecond"])
28+
fun CheckerContext.jvmCopyVariant() {
29+
xmlReport("first") {
30+
// only classes from `first` project are present
31+
classCounter("kotlinx.kover.examples.merged.SubprojectFirstClass").assertCovered()
32+
classCounter("kotlinx.kover.examples.merged.ClassFromSecondProject").assertAbsent()
33+
}
34+
35+
xmlReport("second") {
36+
// only classes from `second` project are present
37+
classCounter("kotlinx.kover.examples.merged.SubprojectFirstClass").assertAbsent()
38+
classCounter("kotlinx.kover.examples.merged.ClassFromSecondProject").assertCovered()
39+
}
40+
}
41+
2742
@ExamplesTest("android/minimal_groovy")
2843
fun CheckerContext.androidGroovy() {
2944
// build only

kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/appliers/FinalizeKover.kt

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,6 @@ internal fun KoverContext.finalizing(origins: AllVariantOrigins) {
5858
jvmVariant?.let { variantArtifacts[JVM_VARIANT_NAME] = it }
5959
androidVariants.forEach { variantArtifacts[it.variantName] = it }
6060

61-
val availableVariants = variantArtifacts.keys + projectExtension.currentProject.customVariants.keys
62-
projectExtension.reports.byName.forEach { (requestedVariant, _) ->
63-
if (requestedVariant !in availableVariants) {
64-
throw KoverIllegalConfigException("It is not possible to configure the '$requestedVariant' variant because it does not exist")
65-
}
66-
}
67-
6861
val totalVariant =
6962
TotalVariantArtifacts(project, toolProvider, koverBucketConfiguration, variantConfig(TOTAL_VARIANT_NAME), projectExtension)
7063
variantArtifacts.values.forEach { totalVariant.mergeWith(it) }

0 commit comments

Comments
 (0)