[Haskell-cafe] Code coverage: mark certain function calls as covered

Özgür Akgün ozgurakgun at gmail.com
Wed Nov 13 10:04:03 UTC 2019

This may sound like a bizarre request, but I feel I can't be the only one.

I have a function called "bug". This is essentially a special case of
"error", but I am disciplined and I only use this function to mark parts of
my code I believe are unreachable.

So something like:

data Term = X ... | Y ... | Z ...

-- the argument can only be X or Y in this part of the program
f :: Term -> ...
f (X ...) = ...
f (Y ...) = ...
f Z{} = bug "This should never happen (in f)"

You might hate this style of programming, and frankly I am not a fan
either. But sometimes we have to write partial functions and I am at least
trying to mark the cases explicitly in these cases.

So this is my question: if I did a good job and if the Z case above is
indeed unreachable, the code coverage report will always flag it as
uncovered and in the overall report this will make it harder for me to see
the parts of my code which aren't covered and should be.

I'd like a way of marking (= generating a tick for?) every call to this
function bug as covered.

Please let me know if there is a better place to ask this question. I
checked and hpc <http://hackage.haskell.org/package/hpc>'s issue tracker is
shared with GHC's and I wasn't sure if they'd appreciate a question there.

Özgür Akgün
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20191113/483f6db0/attachment.html>

More information about the Haskell-Cafe mailing list