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

Ignore specific lines, for example `require`

Open soywiz opened this issue 3 years ago • 6 comments

Require method calls that are a safeguard for implementations never will be able to be fully executed if the implementation works fine.

Screenshot 2022-10-04 at 17 55 08

So I would like to mark somehow specific lines to be ignored for the coverage. Is it possible right now?

soywiz avatar Oct 04 '22 15:10 soywiz

Hi, at the moment there is no way to exclude a specific line from the report.

Using an annotation filter, you can exclude lambdas, but this will not work in the case of inline functions.

shanshin avatar Oct 04 '22 17:10 shanshin

Thanks @shanshin ! So maybe this could be a feature request. Not sure if a comment or something in the line above the partial line could be easily be consumed by the plugin having the source.

And thanks you guys for all the hard work! With 0.6.1, I was able to finally get it working and upload the reports to codecov!

soywiz avatar Oct 04 '22 17:10 soywiz

Not sure if a comment or something in the line above the partial line could be easily be consumed by the plugin having the source.

Ignoring the line by comment (or compile-only annotations) is a planned feature, but at this stage its implementation is difficult.

shanshin avatar Oct 04 '22 17:10 shanshin

Nevertheless, the overall recommendation is to test every meaningful code path and exclude only really obscure lines (the classic example of which is Java's catch (check exception) when it's statically known that the try` block never throws it)

qwwdfsad avatar Oct 05 '22 08:10 qwwdfsad

Yeah, thats the case here. That require for example tests the correctness of the private state. Public constructors and methofs dont allow to violate that contract, so it is not possible to test that branch without mocking or reflectively change stuff. And since those are in the commonTest branch it wont be reasonably possible. As you said I don't want to test those kind of branches for the reasons you put, but would want to skip them if possible to approach to the 100% coverage without those affecting to it. Not a super huge deal for me, since I have lot of untested code yet, but will be appreciated if this feature is supported at some point in the future.

soywiz avatar Oct 05 '22 09:10 soywiz