Bachmann1234 / diff_cover

Automatically find diff lines that need test coverage.
Apache License 2.0
712 stars 191 forks source link

Add note, incremental coverage is 0 #263

Open lirui311012 opened 2 years ago

lirui311012 commented 2 years ago

After integrating diff-cover, a line of code appears to be commented out, and the incremental code coverage is 0. How to solve this? I think adding a line of comment code, this line of code will not be compiled, then the denominator of the incremental coverage should be 0, so the coverage should be 100%

Bachmann1234 commented 2 years ago

Does diff cover report any missing lines? In the scenario you described I would not expect diff cover to report any lines as missing ...

Can you show an example?

lirui311012 commented 2 years ago

for example: Unmodified code: src/test.cpp

include

using namespace std;
int main()
{
    int a = 10;
    int b=  20;
    int c = a + b;
    cout << (a + b) << endl;
    return 0;
}

Modified code: src/test.cpp

include

using namespace std;
int main()
{
    int a = 10;
    int b=  20;
    // int c = a + b;
    cout << (a + b) << endl;
    return 0;
}

The comparison can be found, int c = a + b; is blocked but,This line of code should not be calculated into the incremental code, so that is 100% coverage However, in the actual test, this line of blocked code is calculated as incremental code and is not covered by the google test unit test case

Bachmann1234 commented 2 years ago

It sounds like the coverage report is returning something incorrect? Diff cover does not compute coverage itself.

It takes coverage computed by another tool and compares it to the diff.

So if the underlying coverage tool is reporting the wrong thing then you need to look at that tool.