Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] exclusions don't work (as described in the documentation) #370

Closed
RaphaelTarita opened this issue May 11, 2023 · 4 comments · Fixed by #380
Closed

[BUG] exclusions don't work (as described in the documentation) #370

RaphaelTarita opened this issue May 11, 2023 · 4 comments · Fixed by #380
Assignees
Labels
Bug Bug issue type S: waiting for clarification Status: additional information required to proceed

Comments

@RaphaelTarita
Copy link

Describe the bug
I cannot get any kind of excluding filter to work, at least not the way the documentation explains it. I am not aware of any other way of configuring filters, so I don't know if filters just generally don't work or if I'm doing something wrong. Basically, no matter what kind of exclusions I define in the kover configuration, they all get ignored and everything lands in the final HTML report.

Expected behavior
I'm specifically trying to exclude declarations annotated with javax.annotation.processing.Generated, and I'd expect that those declarations would not show up in the HTML report.

Reproducer
I tried this in a new, minimal gradle/kotlin project for reproduction. Here's the build.gradle.kts:

import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
    kotlin("jvm") version "1.8.21"
    id("org.jetbrains.kotlinx.kover") version "0.6.1"
}

group = "com.rtarita"
version = "1.0-SNAPSHOT"

repositories {
    mavenCentral()
}

dependencies {
    testImplementation("io.kotest:kotest-runner-junit5:5.6.1")
    testImplementation("io.kotest:kotest-assertions-core:5.6.1")
}

tasks.test {
    useJUnitPlatform()
}

tasks.withType<KotlinCompile> {
    compilerOptions {
        jvmTarget.set(JvmTarget.JVM_11)
    }
}

kover {
    filters {
        annotations {
            excludes += "javax.annotation.processing.Generated" // also tried with listOf()
        }
    }
}

In this project, I have two classes residing in the package root com.example:

TestClass1.kt:

package com.example

class TestClass1 {
    fun function1() = "Hello, World!"
}

TestClass2.kt:

package com.example

import javax.annotation.processing.Generated

@Generated
class TestClass2 {
    fun function2() = "Bye, World!"
}

Then, in my test sources (also under com.example), I have this Kotest test class.

TestClass1Tests.kt:

package com.example

import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe

class TestClass1Tests : FunSpec({
    test("function1() should return hello world") {
        val testInstance = TestClass1()
        testInstance.function1() shouldBe "Hello, World!"
    }
})

this only tests and covers TestClass1, so without further configuration it would be expected that TestClass2 shows up uncovered in the HTML report. However, since the kover config in the buildscript should exclude all declarations annotated with javax.annotation.processing.Generated, I would expect TestClass2 to not show up in the report, and therefore to have a coverage of 100%.

Reports
Instead, I get a report that looks like this:
image

In particular, the package shows TestClass1 fully covered and TestClass2 not covered:
image

I don't know if my configuration is simply wrong or if I'm missing something, but simply going off from the documentation I had expected this to work. Any help appreciated!

Environment

  • Kover Gradle Plugin version: 0.6.1
  • Gradle version: 8.1.1
  • Kotlin project type: Kotlin/JVM 1.8.21
  • Coverage Engine version: default
  • JVM: Target Version 11, OpenJDK 11.0.2
  • OS: Windows 11
@RaphaelTarita RaphaelTarita added Bug Bug issue type S: untriaged Status: issue reported but unprocessed labels May 11, 2023
@RaphaelTarita
Copy link
Author

Update: I just tested that excluding TestClass2 explicitly by its fully-qualified name (NOT by simple name) works:

kover {
    filters {
        classes {
            excludes += "com.example.TestClass2"
        }
    }
}

This actually removes TestClass2 from the report and displays the expected 100% coverage.

So far, this is the only exclusion mechanism that has worked for me. I still don't know why the exclusion by annotation does not work.

@shanshin
Copy link
Collaborator

shanshin commented May 16, 2023

Please try 0.7.0 version.

@shanshin shanshin added S: waiting for clarification Status: additional information required to proceed and removed S: untriaged Status: issue reported but unprocessed labels May 16, 2023
@RaphaelTarita
Copy link
Author

I now tried the 0.7.0 version and used this config in the buildscript:

koverReport {
    filters {
        excludes {
            annotatedBy("*Generated")
        }
    }
}

I also tried "javax.annotation.processing.Generated" and "@javax.annotation.processing.Generated" as inputs for annotatedBy().

I'm still getting the same results. Declarations annotated with @Generated are not excluded.

@shanshin
Copy link
Collaborator

@RaphaelTarita, this is a lack of documentation.
Since on-the-fly instrumentation works with bytecode, then AnnotationRetention for it should be BINARY or RUNTIME.

SOURCE is used for the javax.annotation.processing.Generated annotation, so it will be ignored by Kover

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug issue type S: waiting for clarification Status: additional information required to proceed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants