[antlr-interest] NQOT: Grammar meta-programming

Gavin Lambert antlr at mirality.co.nz
Sat Dec 8 04:09:44 PST 2007


At 00:35 9/12/2007, Johannes Luber wrote:
 >How would you do unit tests with ANTLR? I'm not sure how I can
 >realize them here.

Like any other class -- you test that given certain input, it 
produces specific output.

In my view the most important thing to unit test is the lexer, 
since that's often the most brittle component and ANTLR doesn't 
give you as much debugging help with it -- combined with at times 
some rather odd decision making, it's even more important.  All 
you need to test there is that given certain strings as input, the 
lexer produces specific token streams.  (You could test only the 
type and order of tokens, but for a comprehensive test it ought to 
verify that each token contains the correct data as well).

Unit testing the parser may be more complicated depending on how 
it's written.  If it's generating an AST or a StringTemplate, then 
again you can just test the generated output against what you're 
expecting.  If it's executing actions directly, then you'll need 
to test the consequences of those actions, whether "live" or by 
mocking it out through an interface.

You might want to have a look at gUnit.  I haven't used it myself 
but you might find it helpful.



More information about the antlr-interest mailing list