Code coverage: mark certain function calls as covered

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

El 13 nov 2019, a las 05:04, Özgür Akgün
escribió: This may sound like a bizarre request, but I feel I can't be the only one.
I can give a +1 that this would be useful. Here's an annoying case I've run into that doesn't even require partial functions: fiveDiv :: Int -> Either String Int fiveDiv 0 = Left "Can't div by 0" fiveDiv n = Right $ 5 `div` n and the test cases are: fiveDiv 8 === Right 0 and isLeft (fiveDiv 0) Now the string itself ("Can't div by 0") is marked as an uncovered expression. This trivial case could easily be covered but: a) I've run into this frequently enough in more annoying cases, and b) it feels more idiomatic to write a test that doesn't care about the contents of the string (and the test doesn't need to change if the string changes) Tom
participants (2)
-
amindfv@gmail.com
-
Özgür Akgün