Kotlin / kotlinx-kover

Apache License 2.0
1.37k stars 53 forks source link

[XML] Codecov.io does not see files with package mismatch #260

Open IgnatBeresnev opened 2 years ago

IgnatBeresnev commented 2 years ago

If you have a Kotlin file with some classes/functions under a certain package, for example

src/main/kotlin/org/jetbrains/kover/reproducer/PackageMismatchFile.kt

but inside the file you have a different package declared, for example

package org.jetbrains.kover.reproducer.some.inner.pckg // some.inner.pckg has been added

class PackageMismatchClass {}

codecov.io will not see (and thus not calculate coverage for) this file. You can observe it in this report.

If you physically move the file to the "correct" package, it will work as expected.

The problem might be relevant for other tools that use Jacoco format since this behaviour is not possible in Java (package must match location), and tools that analyze Jacoco coverage reports might rely on that.


I haven't noticed any difference in generated XML reports between Jacoco and IntelliJ engines, both generate the following paths:

    <package name="org/jetbrains/kover/reproducer/some/inner/pckg">
        <class name="org/jetbrains/kover/reproducer/some/inner/pckg/PackageMismatchClass"
               sourcefilename="PackageMismatchFile.kt">
            ...
        </class>
        <sourcefile name="PackageMismatchFile.kt">
            ...
        </sourcefile>
        ...
    </package>

Runnable reproducer can be found in this repo, there are instructions on how to run it and upload the report.

This was found while investigating https://github.com/Kotlin/kotlinx-kover/issues/16

twyatt commented 1 year ago

For more context, related JaCoCo issue: https://github.com/jacoco/jacoco/issues/939