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

[XML] Method with empty body marked as not covered, even though it is #259

Closed
IgnatBeresnev opened this issue Oct 20, 2022 · 4 comments
Closed
Assignees
Labels
Bug Bug issue type Kover Coverage Tool S: ready for release Status: merged in the main branch

Comments

@IgnatBeresnev
Copy link
Member

IgnatBeresnev commented Oct 20, 2022

This issue might affect more cases than simply an empty body, but I haven't checked anything else.

Reproducer:

// main
class TestFile {

    fun foo() {
        println("should be covered")
    }

    fun bar() { }
}

// test
class TestFileTest {
    
    @Test
    fun shouldCheckFoo() {
        TestFile().foo()
    }

    @Test
    fun shouldCheckBar() {
        TestFile().bar()
    }
}

Results in the following HTML report:
2022-10-20_11-19-07

But if you upload the XML report to codecov.io (results here), you'll see the following:
2022-10-20_11-22-59

I don't think it's a bug of codecov, but rather of kover's xml report data. Codecov seems to calculate coverage based on source file coverage, and if we look at the xml report, we'll see the following:

        // IntelliJ results
        <sourcefile name="KotlinFile.kt">
            <line nr="3" mi="0" ci="2" mb="0" cb="0"/>
            <line nr="6" mi="0" ci="4" mb="0" cb="0"/>
  ---->     <line nr="9" mi="0" ci="0" mb="0" cb="0"/>
            <counter type="INSTRUCTION" missed="0" covered="6"/>
            <counter type="BRANCH" missed="0" covered="0"/>
            <counter type="LINE" missed="0" covered="3"/>
        </sourcefile>

Where line 9 (bar() declaration) is neither covered (ci) nor missed (mi). Moreover, it affects the LINE counter, which is 1 less than it should be (should be 4 covered instructions).

However, if you change the engine to Jacoco and generate reports for the same case, you'll see that everything is correct and that line 9 is covered (ci=1).

       // Jacoco results
        <sourcefile name="KotlinFile.kt">
            <line nr="3" mi="0" ci="3" mb="0" cb="0"/>
            <line nr="6" mi="0" ci="4" mb="0" cb="0"/>
            <line nr="7" mi="0" ci="1" mb="0" cb="0"/>
  ---->     <line nr="9" mi="0" ci="1" mb="0" cb="0"/>
            <counter type="INSTRUCTION" missed="0" covered="9"/>
            <counter type="LINE" missed="0" covered="4"/>
            <counter type="COMPLEXITY" missed="0" covered="3"/>
            <counter type="METHOD" missed="0" covered="3"/>
            <counter type="CLASS" missed="0" covered="1"/>
        </sourcefile>

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 #16 as it affects calculated coverage.

@shanshin shanshin added the S: untriaged Status: issue reported but unprocessed label Oct 20, 2022
@shanshin shanshin self-assigned this Oct 27, 2022
@zuevmaxim
Copy link

The issue is caused by agent ignoring empty lines if it is not the only line in a method. The agent also should count instructions in the same way

@shanshin shanshin added S: in progress Status: implementing or design in process and removed S: untriaged Status: issue reported but unprocessed labels Nov 21, 2022
@zuevmaxim
Copy link

Fixed in agent version 1.0.688

@shanshin shanshin added S: ready for release Status: merged in the main branch and removed S: in progress Status: implementing or design in process labels Nov 22, 2022
@shanshin
Copy link
Collaborator

shanshin commented Nov 22, 2022

To use custom engine you need to configure it in all projects where Kover is used

for Kotlin Gradle script

kover {
    engine.set(kotlinx.kover.api.IntellijEngine("1.0.688"))
}

for Groovy

kover {
    engine = new kotlinx.kover.api.IntellijEngine("1.0.688")
}

@shanshin
Copy link
Collaborator

Fixed in 0.7.0-Alpha

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Bug issue type Kover Coverage Tool S: ready for release Status: merged in the main branch
Projects
None yet
Development

No branches or pull requests

3 participants