[antlr-interest] gUnit and Error Recovery

Leon Su leon.antlr at mac.com
Thu Aug 7 11:33:30 PDT 2008


Hi Louis,

I just quickly tested the grammar fragment you provided:
remove (cls)* from pkg, and add WS:( ' ' | '\t' | '\r' | '\n' )+  
{$channel = HIDDEN;};

tested by gUnit1.0.2+ANTLR3.1b2 and gUnit-1.0.1+ANTLR3.0.1
and both got the failed 2nd test as we expected ( and received the  
error msg from ANTLR: line 0:-1 missing RBRACKET at '<EOF>' )

If you're using gunit-1.0.1 currently, don't forget to download the  
updated gunit-1.0.1.jar Version2 on the wiki page.
Please let me know if you any problem.

Leon

On Aug 7, 2008, at 10:25 AM, Louis Rose wrote:

> 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