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
Assertion statements with static conditions do not have coverage #232
Comments
Hi Simon, Thank you for reporting this interesting finding. I checked OpenClover's source code and indeed, the assert statement is not being instrumented:
This means it does not measure statement coverage for asserts. However, what is being instrumented is assert's expression, this means it measures branch coverage for expressions. With one exception though. It does not instrument constant expressions, because in constants there's no true and false branch to be executed:
This is exactly what we can see in the instrumented code of Demo.java:
|
Another question is why the assert as a statement is not being instrumented. I checked OpenClover's code history and this "instrumentable = false" exists since the first commit in the repository - so since the original Clover version open-sourced by Atlassian. I suspect that there might be some specific grammar context in which the assert keyword might appear, preventing it from being instrumented. A similar example is the "catch" block. OpenClover does not insert the recorder call before "catch" keyword, because it would make no sense. It inserts it inside the catch
Similarly, OpenClover does not insert the recorder call before "super()" in the constructor, because super must be the first statement executed.
I will try to investigate in which conditions asserts cannot be instrumented as a statement... |
Thank you so much for your swift reply and for taking a look already. Interesting to see that it is actually the branch coverage that is responsible for the difference between "static" and "dynamic" There was a bit of extra confusion since Clover has an extra "coverage context" for assert statements. So I was very certain that Thanks for taking a deeper look. |
You can exclude include/assert statements using coverage context during report generation. But this shall include/exclude only the branch coverage for them. |
Assertion statements with static conditions (i.e.
assert true
) are not detected byclover
when they are executed. CC @zimmskiReproducer
java -cp <path-to-jars>/clover-4.5.1.jar com.atlassian.clover.CloverInstr -i demo/coveragedb -d demo/instructed demo/Demo.java
javac -cp <path-to-jars>/clover-4.5.1.jar -g:source,lines,vars demo/instructed/Demo.java
java -cp <path-to-jars>/clover-4.5.1.jar:./demo/instructed -ea Demo
java -cp <path-to-jars>/clover-4.5.1.jar com.atlassian.clover.reporters.xml.XMLReporter -i demo/coveragedb -o demo/coverage.xml -l
Inspecting the generated
xml
report, only theassert
statement for the "object" case has coverage:Version
openclover
4.5.1
The text was updated successfully, but these errors were encountered: