[Haskell-cafe] test coverage of Parsec parsers

Aaron VonderHaar gruen0aermel at gmail.com
Sat Nov 14 04:14:06 UTC 2015


Hi, I'm adding HUnit tests to a parser that uses Parsec, and I wanted
to see test coverage of my parser.  I've successfully used hpc to get
a coverage report, but it has a significant deficiency:  An expression
in my parser will show as covered if the expression is ever evaluated,
but I'd really like to see branch coverage of the parser monads.

For example, if I have a single test that parses the string "*" with
the following parser:

plusOrStar =
    do
        result <- (string "+" <|> string "*")
        _ <- (many $ string " ")
        return result

then hpc will report that all the code is covered, but I'd like to be
able to see the fact that (string "+") only ever failed, and that
(string "*") only ever succeeded.

Are there any existing tools for getting that sort of coverage report
for parsers or monads?  Is there an approach other than hpc that I
should be considering to get confidence in my test suite?  If not, I
understand that hpc works by doing source-code transformation--does it
seem like a reasonable endeavor to try to customize it to do what I am
interested in?

Thanks,
--Aaron V.


More information about the Haskell-Cafe mailing list