[antlr-interest] gUnit and Error Recovery

Louis Rose louis at cs.york.ac.uk
Thu Aug 7 10:25:42 PDT 2008


Hi all,

I'm currently considering migrating a large number of unit tests to 
gUnit. I have a query about the way gUnit works with ANTLR's error 
recovery capabilities.

Here's a fragment from an ANTLR grammar that I wish to test:

pkg: NAME^ LBRACKET! (cls)* RBRACKET!;

LBRACKET     : '{';
RBRACKET     : '}';
NAME         : ID_START_LETTER (ID_LETTER)*;

fragment
ID_START_LETTER
     :    '_'
     |    'a'..'z'
     |    'A'..'Z'
     |    '@'
     ;

fragment
ID_LETTER
     :    ID_START_LETTER
     |    '0'..'9'
     |    '-'
     ;


I have the following gUnit tests:

pkg:
     "Families {}" -> "Families"
     "Families {"    FAIL

I would expect the second test to verify that a terminating right 
bracket is required. (i.e. parsing would fail). In fact, the parser 
successfully recognises the input from the second test:

1 failures found:
test2 (pkg, line6) -
expected: FAIL
actual: OK

Tests run: 2, Failures: 1


Is this working as intended? How can I test that all uses of pkg should 
be terminated with a closing bracket?

Many thanks,
Louis Rose.



More information about the antlr-interest mailing list