HUnit or QuickCheck for test-driven developing a parser

Hello there, Let's say I'm writing a parser for a toy programming language, and I want to do it following a test-driven development philosophy. Which would be better testing tool for this task, HUnit or QuickCheck (or perhaps something else)? Cheers, adam.

Hi Adam 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. Best wishes Stephen
participants (2)
-
Adam Cigánek
-
Stephen Tetley