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

Reified T - Invalid Code Coverage #638

Open
gibarrola-mdt opened this issue Jun 19, 2024 · 2 comments
Open

Reified T - Invalid Code Coverage #638

gibarrola-mdt opened this issue Jun 19, 2024 · 2 comments
Assignees
Labels
Bug Bug issue type S: confirmed Status: bug is reproduced or present

Comments

@gibarrola-mdt
Copy link

Kover 0.8.1 and previous versions are incorrectly calculating the branch % for some reified extensions. Below is a snippet on how to reproduce the observed error:

Internal Function:

internal inline fun <reified T> sizeOf() : Int where T : Number =
    when(T::class)
    {
       Byte::class -> Byte.SIZE_BYTES
       Short::class -> Short.SIZE_BYTES
       Int::class -> Int.SIZE_BYTES
       Long::class -> Long.SIZE_BYTES
       Float::class -> Float.SIZE_BYTES
       Double::class -> Double.SIZE_BYTES
       else -> throw Exception("Unsupported type")
    }

Unit Test - results in partial "Branch, %" coverage although the "Instruction, %" is 100%:

@Test
fun sizeOfTest() {
    assertEquals(1, sizeOf<Byte>())
    assertEquals(2, sizeOf<Short>())
    assertEquals(4, sizeOf<Int>())
    assertEquals(8, sizeOf<Long>())
    assertEquals(4, sizeOf<Float>())
    assertEquals(8, sizeOf<Double>())
    
    assertFailsWith<Exception> {
       sizeOf<InvalidNumberClass>()
    }
}

private class InvalidNumberClass(private val number: Number): Number() {
    override fun toByte() = number.toByte()
    override fun toShort() = number.toShort()
    override fun toInt() = number.toInt()
    override fun toLong() = number.toLong()
    override fun toFloat() = number.toFloat()
    override fun toDouble(): Double = number.toDouble()
}

image

Environment

  • Kover Gradle Plugin version: 0.8.1
  • Gradle version: 8.2
  • Kotlin project type: Kotlin/Multiplatform
@gibarrola-mdt gibarrola-mdt added Bug Bug issue type S: untriaged Status: issue reported but unprocessed labels Jun 19, 2024
@shanshin
Copy link
Collaborator

@zuevmaxim, locally reproduced

Image

@shanshin shanshin added S: confirmed Status: bug is reproduced or present and removed S: untriaged Status: issue reported but unprocessed labels Jun 24, 2024
@zuevmaxim
Copy link

@shanshin For the last inlined call, the compiler replaced previously used IFEQ with IFNE instruction, so the coverage agent tracks the first branch as covered twice, and the second one as not covered at all.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug issue type S: confirmed Status: bug is reproduced or present
Projects
None yet
Development

No branches or pull requests

3 participants