[antlr-interest] gunit and verbose output

Sébastien Kirche sebastien.kirche at gmail.com
Mon Jul 18 16:19:39 PDT 2011


Hi,

as I am progressing in the definition of my powerscript grammar, I
began to build a consistent base of test cases to point the portions
of the grammar that still need some work.

I first used to put the test cases in a String array processed in the
main method of the parser class. Not very practical.
I used also to parse a set of debug_* files where I put the test cases
grouped by theme, with a pause between each test file to look for
error messages. Better, but it lacks the ability to display a resume
of the passed vs. failed tests (though I still use that to produce
automated graphviz diagrams of syntax).

Then I discovered gunit, which looks to be what I am looking for, with
some problems :
1) gunit seems to be annoyed by some debug output messages
(System.ot.print...) that I put in Lexer and Parser actions. I get a
the following in the gunit results (partial output) :

executing testsuite for grammar:PowerScript with 39 tests
-----------------------------------------------------------------------
8 failures found:
test1 (Ident, line7) -
expected: OK
actual: java.lang.StringIndexOutOfBoundsException: String index out of range: -1

test2 (Ident, line9) -
expected: OK
actual: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
[...]

If I comment out a System.out.print in the Ident rule, the tests are passed OK.

2) following Jim Idle advice, I am using a custom
ANTLRNoCaseFileStream to perform a case insensitive matching of the
language keywords, and I am about to implement a such StringStream.
Would it be possible to use that case insensitive stream with gunit ?
For the moment I need to type each keyword in uppercase as they are
defined in the grammar.

3) I have some tests that fails. Sometimes the cause is obvious (in
the test case), sometimes it is not and I cannot get a verbose reason
with gunit. E.g , I get a expected: OK / actual: FAIL. I need to
specifically invoke the rule with the same input to get a clear error
message from the parser. I have made a dynamic rule invoker to help,
but would it be possible to get the error message directly with gunit
?

For those that could help, I join my "dynamic invoker", you just need
to pass the rule name and an input string to invoke the rule from the
parser. Start it by giving the rule name and a test string in the
command line arguments.

Regards,
-- 
Sébastien Kirche
-------------- next part --------------
A non-text attachment was scrubbed...
Name: RunExpression.java
Type: application/octet-stream
Size: 1267 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20110719/13979f86/attachment.obj 


More information about the antlr-interest mailing list