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

Chris Sekszczynska Development at ChrisSek.de
Sat Nov 1 03:06:20 PDT 2008


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


More information about the antlr-interest mailing list