[Haskell-cafe] Code coverage: mark certain function calls as covered
amindfv at gmail.com
amindfv at gmail.com
Wed Nov 13 22:55:13 UTC 2019
> El 13 nov 2019, a las 05:04, Özgür Akgün <ozgurakgun at gmail.com> 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
More information about the Haskell-Cafe
mailing list