[antlr-interest] gUnit: Is it possible to test StringTemplate output?

Leon Su leon.antlr at mac.com
Sat Nov 1 15:28:30 PDT 2008


Hi Chris,

Thanks for pointing out this issue. I think it's a bug of testing a  
tree grammar's template output in gUnit-1.0.2.
I just uploaded an intermediate release to the wiki page of gUnit.
Please download the new version and try to see if it works on your  
testsuite.

ps.  you may need to put gunit-1.0.3b.jar before antlr-3.1.1.jar in  
your classpath.

Leon

On Nov 1, 2008, at 3:06 AM, Chris Sekszczynska wrote:

> Hello all,
>
> simple question: Is it possible to test a tree walkers template output
> using
> gUnit? In my tree grammar I put the following into the starting rule:
>
> @init {
>     try {
>          FileReader groupFileR = new FileReader("path/to/group.stg");
>          StringTemplateGroup templates = new
> StringTemplateGroup(groupFileR);
>          groupFileR.close();
>          this.setTemplateLib(templates);
>      } /... some catch blocks
> }
>
> Of cause, I also added the imports. My testsuite looks as follows:
>
> 	gunit TreeWalker walks Parser;
>
> 	program walks program:
> 	"if(true){}" OK
>
> This TC fails. When I expect some value, like
>
> 	program walks program:
> 	"if(true){}" -> <<
>          if True:
>              pass
>>>
>
> I got the following output:
>
> 	test1 (program walks program, line9) -
> 	expected: if(true)
> 	actual: java.lang.NullPointerException
>
> Why does this NullPointerException occurs? I debugged into the
> StringTemplate code but found nothing useful. I think it's produced
> when performing the "node to template" transformation.
>
> When I use the usual way to run the parser and walker, the input
> "if(true){}" produces the expected "if True:\n pass". So I think the
> issue is not caused by my grammars.
>
> Wiki page http://www.antlr.org/wiki/display/ANTLR3/gUnit+-+Grammar 
> +Unit+Testing
> points out that testing template output is possible (see section "Test
> StringTemplate output").
>
> Thanks in advance.
>
> Kind regards,
> Chris
>
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr- 
> interest/your-email-address
>



More information about the antlr-interest mailing list