[antlr-interest] gUnit for v4?

Kieran Simpson kierans777 at gmail.com
Wed Apr 18 21:56:20 PDT 2012

On 23/07/64 5:59 AM, Terence Parr wrote:
> Hi,
> I started down the path of building the new version of gUnit for v4, but I'm beginning to question its value for the new version. Because I am pooh-poohing putting actions directly within a grammar, grammar can only yield parse trees. and looks nice to be able to say:
> expr:
> 	"1"		->  (expr 1)
> 	"1+2"	->  (expr (expr 1) + (expr 2))
> but so what? all that did was confirm that the parser generated by ANTLR works correctly. it's not telling you anything you didn't know by looking at the grammar.
> In the old days we used to build ASTs and so we needed to check the structure. That need is no longer here. Also, these rules don't generate output and so we can't check input to output translation.
> What it comes down to is this: we really need functional testing not unit testing for language applications, unless of course each rule returns a string that the translation of the input some phrase or something. But, it's just as easy to write calls to assertEquals() saying that input x should yield input y. If we are doing something other than generating output, such as building up a data structure, then we really do need to manually check that the data structure is solid given some input.
> I'm trying to find a flaw in my logic. Is there something I'm missing about testing grammars? In v4, they will give you exactly what you want, unless there is a bug in ANTLR. But that's my problem not yours.
> If we can't find a major benefit, then we should avoid introducing another moving part to the ANTLR ecosystem.

I find gUnit very helpful in testing parts of my grammar both in 
isolation and different combinations.  I like being able to test token 
definitions against different input.

Where I find functional testing more beneficial is for tree walkers. 
For my grammars that produce ASTs I've found the grammar tests useful in 
preventing regression bugs.

There's also testing in non Java languages to consider.  Having the 
ability to have tests generated/run via JUnit may be easier than having 
to piece together your tests in another language (eg: C) which I 
personally find is more time consuming.

Just a few thoughts.


More information about the antlr-interest mailing list