kotlinx-kover icon indicating copy to clipboard operation
kotlinx-kover copied to clipboard

Coverage for inline functions producing flow is not working

Open driessamyn opened this issue 9 months ago • 2 comments

Describe the bug

Consider the following function:

inline fun flowTest(): Flow<Int> {
    return flow {
        for (i in range(1, 10)) {
            emit(i)
        }
    }
}

and the following test:

@Test
fun `flow test`() {
    runBlocking {
        flowTest().collect(::println)
    }
}

Full coverage is expected, confirmed by the println output from the test. However, Kover reports coverage as missing for this.

Errors

Image

Kover reports missing coverage

Expected behavior

Full coverage to be reported.

Reproducer

See code snippits above. This is a reproduction of an issue in this code: https://sonarcloud.io/component_measures?metric=new_coverage&selected=driessamyn_kapper%3Acoroutines%2Fsrc%2Fmain%2Fkotlin%2Fnet%2Fsamyn%2Fkapper%2Fcoroutines%2FKapperKotlinFlowQueryFun.kt&view=list&pullRequest=85&id=driessamyn_kapper

Environment

  • Kover Gradle Plugin version: 0.9.1
  • Gradle version: Gradle 8.12
  • Kotlin project type: Kotlin/JVM
  • Coverage Toolset Kover

driessamyn avatar Feb 25 '25 21:02 driessamyn

Confirmed that using the Jacoco coverage library also misses this coverage

Image

driessamyn avatar Feb 26 '25 08:02 driessamyn

Confirmed that using the Jacoco coverage library also misses this coverage

Recent versions of JaCoCo do not support inline functions. A future release contains the necessary changes.

shanshin avatar Feb 26 '25 12:02 shanshin

Closed due to the end of IntelliJ Agent development (#720) and the introduction of a new strategy for measuring of Kotlin code coverage (#746).

It is recommended to use JaCoCo, for this purpose it is enough to specify

kover {
    useJacoco("0.8.13")
}

in each project.

shanshin avatar May 30 '25 13:05 shanshin