[Haskell-beginners] HUnit or QuickCheck for test-driven
developing a parser
stephen.tetley at gmail.com
Wed Jan 20 15:09:06 EST 2010
Presumably you would be doing the obvious thing and testing that the
parser fails for ill-formed files and works for well-formed files?
For well formed files - as you have a parser you would likely have
defined an abstract syntax tree, so you could use QuickCheck to
generate random syntax trees, pretty print them, then run the parser
on them to test them. Alternatively you might want a test generator
that builds all abstract syntax trees up to a certain nesting depth
rather than random ones (I think the GAST tool does this in Clean, I
suspect there is a similar Haskell tool).
For ill formed files, I think you would have to create them yourself.
You could write a 'sloppy printer' rather than a pretty printer that
injects syntax errors if you really wanted to do it automatically.
Myself, I would just keep a library of hand written example files,
both ones that should pass and ones that should fail, rather than try
to generate them.
More information about the Beginners