From c236cffefeef98fa938a788bdb16741c4d9bc779 Mon Sep 17 00:00:00 2001 From: "Sergey.Shanshin" Date: Wed, 1 May 2024 15:47:22 +0200 Subject: [PATCH] Excluded from report companion objects with only constants Fixes #583 --- gradle/libs.versions.toml | 2 +- .../kover/features/jvm/impl/Wildcards.kt | 5 +++- .../functional/cases/ConstantObjectTests.kt | 23 +++++++++++++++++++ .../counters/src/main/kotlin/Objects.kt | 19 +++++++++++++++ .../kover/gradle/plugin/dsl/KoverVersions.kt | 2 +- 5 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/cases/ConstantObjectTests.kt diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index d8decaa9..6317df87 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -1,6 +1,6 @@ [versions] -intellij-coverage = "1.0.748" +intellij-coverage = "1.0.752" junit = "5.9.0" kotlinx-bcv = "0.13.2" kotlinx-dokka = "1.8.10" diff --git a/kover-features-jvm/src/main/java/kotlinx/kover/features/jvm/impl/Wildcards.kt b/kover-features-jvm/src/main/java/kotlinx/kover/features/jvm/impl/Wildcards.kt index 9f326d2e..d38266de 100644 --- a/kover-features-jvm/src/main/java/kotlinx/kover/features/jvm/impl/Wildcards.kt +++ b/kover-features-jvm/src/main/java/kotlinx/kover/features/jvm/impl/Wildcards.kt @@ -12,7 +12,10 @@ internal fun ClassFilters.convert(): Filters { return Filters( convert(includeClasses), convert(excludeClasses), - convert(excludeAnnotation) + convert(excludeAnnotation), + emptyList(), + emptyList(), + emptyList() ) } diff --git a/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/cases/ConstantObjectTests.kt b/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/cases/ConstantObjectTests.kt new file mode 100644 index 00000000..00b9fb7a --- /dev/null +++ b/kover-gradle-plugin/src/functionalTest/kotlin/kotlinx/kover/gradle/plugin/test/functional/cases/ConstantObjectTests.kt @@ -0,0 +1,23 @@ +/* + * Copyright 2017-2024 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license. + */ + +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.starter.TemplateTest + +internal class ConstantObjectTests { + + /** + * All objects that contain only constants should be excluded from the report. + */ + @TemplateTest("counters", ["koverXmlReport"]) + fun CheckerContext.testBasicCounterCases() { + xmlReport { + classCounter("org.jetbrains.ConstantHolder").assertAbsent() + classCounter("org.jetbrains.InterfaceWithCompanion${"$"}Companion").assertAbsent() + classCounter("org.jetbrains.InterfaceWithNamedCompanion${"$"}Named").assertAbsent() + } + } +} \ No newline at end of file diff --git a/kover-gradle-plugin/src/functionalTest/templates/builds/counters/src/main/kotlin/Objects.kt b/kover-gradle-plugin/src/functionalTest/templates/builds/counters/src/main/kotlin/Objects.kt index cda07e75..3cd2843a 100644 --- a/kover-gradle-plugin/src/functionalTest/templates/builds/counters/src/main/kotlin/Objects.kt +++ b/kover-gradle-plugin/src/functionalTest/templates/builds/counters/src/main/kotlin/Objects.kt @@ -56,3 +56,22 @@ object UsedObjectFun { println("Hello") } } + +object ConstantHolder { + const val STRING_CONST = "STRING_CONST" + const val INT_CONST = 42 +} + +interface InterfaceWithCompanion { + companion object { + const val STRING_CONST = "STRING_CONST" + const val INT_CONST = 42 + } +} + +interface InterfaceWithNamedCompanion { + companion object Named { + const val STRING_CONST = "STRING_CONST" + const val INT_CONST = 42 + } +} diff --git a/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/dsl/KoverVersions.kt b/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/dsl/KoverVersions.kt index 9bce6473..8a6b7a70 100644 --- a/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/dsl/KoverVersions.kt +++ b/kover-gradle-plugin/src/main/kotlin/kotlinx/kover/gradle/plugin/dsl/KoverVersions.kt @@ -17,7 +17,7 @@ public object KoverVersions { /** * Kover coverage tool version. */ - public const val KOVER_TOOL_VERSION = "1.0.748" + public const val KOVER_TOOL_VERSION = "1.0.752" /** * JaCoCo coverage tool version used by default.