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

Public kotlin extension function results in 0% coverage after aggregation #697

Closed
woodii opened this issue Oct 30, 2024 · 4 comments
Closed
Assignees
Labels
Bug Bug issue type S: untriaged Status: issue reported but unprocessed

Comments

@woodii
Copy link

woodii commented Oct 30, 2024

Dear kover team (:

Describe the bug
We have kotlin extension functions inside our codebase which are located just inside a kotlin file, but not inside another class or object. When generating a kover report inside a single gradle feature module the coverage is correct and the function is included.
When using the aggregated project report this single extension function is excluded unless we put it inside of another class or object.

Sample wich results in 0% coverage:

@StringRes
fun Tag.getActivationButtonText(): Int {
    return when (this) {
        Tag.NOT_AVAILABLE -> R.string.badge_not_available
        Tag.COMING_SOON -> R.string.badge_coming_soon
        Tag.LAST_CHANCE,
        Tag.UNKNOWN -> R.string.activate_voucher
    }
}

Workaround 1:

@StringRes
fun Tag.getActivationButtonText() = TagExt.getActivationButtonText(this)

object TagExt {
    @StringRes
    fun getActivationButtonText(tag: Tag): Int {
        return when (tag) {
            Tag.NOT_AVAILABLE -> R.string.badge_not_available
            Tag.COMING_SOON -> R.string.badge_coming_soon
            Tag.LAST_CHANCE,
            Tag.UNKNOWN -> R.string.activate_voucher
        }
    }
}

Workaround 2:

object TagExt {

    @StringRes
    fun Tag.getActivationButtonText(): Int {
        return when (this) {
            Tag.NOT_AVAILABLE -> R.string.badge_not_available
            Tag.COMING_SOON -> R.string.badge_coming_soon
            Tag.LAST_CHANCE,
            Tag.UNKNOWN -> R.string.voucherdetails_activate_voucher
        }
    }
}

The file is just missing inside the generated XML/Html Reports

Expected behavior
The aggregated report is complete and standalone extension functions are included.

Reproducer
please check problem description above

Reports
Unfortunately I cant provide you with full reports as it is a private repository but will try to answer you all upcoming question to resolve this issue.

Environment

  • Kover Gradle Plugin version: 0.7.5 (also tested with 0.8.3)
  • Gradle version: 8.6
  • Kotlin project type: Kotlin/Android
@woodii woodii added Bug Bug issue type S: untriaged Status: issue reported but unprocessed labels Oct 30, 2024
@shanshin
Copy link
Collaborator

Hi,
could you clarify, by "Sample wich results in 0% coverage:" you mean that function is in HTML/XML report but its coverage is 0?

@woodii
Copy link
Author

woodii commented Oct 31, 2024

Hi shanshin,

sorry the line was indeed a bit misleading. The function is included in module reports generated by ./gradlew features:featureA:koverXmlReportDebug with correct coverage

but in aggregated reports via ./gradlew koverXmlReportBuildVariant the function is completely missing.

@shanshin
Copy link
Collaborator

shanshin commented Nov 4, 2024

Unfortunately, without a producer, it's hard to say what the problem might be, in the configuration or in a bug.
However, keep in mind that when you move an extension function from a class to the file level, it will be located in another class.
E.g. if the fun SomeClass.action() function is located in the foo/bar/Biz file, then this function will be in the foo.bar.BizKt class in the report (foo.bar.BizKt.action function)

@woodii
Copy link
Author

woodii commented Nov 8, 2024

Hi shanshin,
thank you for pointing me into the right direction! While preparing a sample project to reproduce this issue I stumbled upon a silly configuration on our side. This configuration together with a not so ideal naming convention resulted in this behaviour.

First we generally put public extension functions in files suffixed with .ext.kt -> this resulted in Names in the kover report like Tag_ext.kt

Secondly we tried to exclude all generated code from our coverage reports by excluding all files with *_* in their name.

Because the kover configuration only is used for the merged report the module report included the file while the aggregated didn't. So we will probably change our naming-convention for extension functions and overhaul our kover config aswell ;)

Sorry for bothering you, many thanks for your assistance on this issue and for developing this great tool.

@woodii woodii closed this as completed Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug issue type S: untriaged Status: issue reported but unprocessed
Projects
None yet
Development

No branches or pull requests

2 participants