Kotlin / kotlinx-kover

Apache License 2.0
1.37k stars 53 forks source link

Add Kover task to execute action after coverage evaluation #605

Open shanshin opened 6 months ago

shanshin commented 6 months ago

What is your use-case and why do you need this feature? In some cases, it is necessary to perform additional actions after measuring the coverage: for example, perform conditional verification, write values to the log, write the coverage values to the file in any form.

Kover cannot provide for all use cases. However, we can provide a factory with which users can create tasks that perform coverage processing

Describe the solution you'd like

kover {
    reports {
        total {
            evaluations.create("myLog") {
               // use build caching
                isCacheable = false

                // action to execute
                action {
                    logger.info("Total coverage: ${lines.coveredPercentage}%")
                }

                // a way to get a task to specify future dependencies
                taskProvider
            }
        }
    }
}

and later executed via koverMyLogAction

Use cases: https://github.com/Kotlin/kotlinx-kover/issues/545 and https://github.com/Kotlin/kotlinx-kover/issues/419

mgroth0 commented 1 month ago

I was just looking for something like this. Similar to https://github.com/Kotlin/kotlinx-kover/issues/545, I need slightly more advanced verification logic:

pseudocode

if (numberOfBranches > 50 && branchesCoveredPercent < 1) {
    failVerfication()
}

Just like https://github.com/Kotlin/kotlinx-kover/issues/545, I have some very small modules failing verifications because in shared build logic I make it so all modules have to cover at bare minimum 1 percent of branches. I've had cases where a module has less than 10 branches and this is not ideal for me to fail verification in this case.