Stream: helpdesk (published)

Topic: telling code coverage to skip naked throw


view this post on Zulip Clark C. Evans (Apr 05 2021 at 17:44):

I have a branch that I never expect to encounter, and I'm wondering how to mark the throw in this branch as being OK so that doesn't red flag during code coverage.

if ....
else
     throw("I should never get here")
end

view this post on Zulip Expanding Man (Apr 05 2021 at 17:57):

In my experience code coverage tools are fairly inflexible, and even, arguably kind of bullshit. For example, you can change the above to one line condition && error("I should never get here") and most code coverage tools will count that as covered, whereas in the above form it will think it missed a line. That is, code coverage doesn't count branches or anything like that, it's a very superficial and unsophisticated analysis.

view this post on Zulip Expanding Man (Apr 05 2021 at 17:58):

I'm certainly no expert in code coverage, but everything I've seen suggests to me that code coverage is a "rough estimate not to be taken too seriously"

view this post on Zulip Kirill Simonov (Apr 05 2021 at 18:06):

coverage.py supports # pragma: no cover syntax, but I don't know if it works for Julia


Last updated: Dec 28 2024 at 04:38 UTC