[stringtemplate-interest] StringTemplateGroup.setRefreshInterval(0) dosen't flush super templates

Gary Clark GaryC at jeld-wen.com
Fri Sep 14 22:23:08 PDT 2007


I'm working with Java StringTemplate 3.1b1 and found a problem with super templates.  The following test case shows the problem.  I'm not sure how this could be added to the StringTemplate test suite because this test writes two files to the local disk and modifies one during the test to expose the bug.

/* -- Begin test code -- */
import static org.junit.Assert.assertEquals;

import java.io.File;
import java.io.PrintWriter;

import org.antlr.stringtemplate.PathGroupLoader;
import org.antlr.stringtemplate.StringTemplate;
import org.antlr.stringtemplate.StringTemplateErrorListener;
import org.antlr.stringtemplate.StringTemplateGroup;
import org.junit.Test;

public class TmplTest implements StringTemplateErrorListener{
	@Test
	public void testGroups() throws Exception {
		// Write the test template
		PrintWriter f = new PrintWriter(new File("strtemp/err.stg"));
		f.print("group err : err-super;\ntest2()::=<<a>>\n");
		f.close();

		// Write the first version of the super template
		f = new PrintWriter(new File("strtemp/err-super.stg"));
		f.print("group err-super;\ntest()::=<<a>>");
		f.close();

		// Setup the group loader and the group
		PathGroupLoader loader = new PathGroupLoader("strtemp", this);
		StringTemplateGroup.registerGroupLoader(loader);
		StringTemplateGroup group = StringTemplateGroup.loadGroup("err");
		group.setRefreshInterval(0);
		
		// Run with the first version of the supertemplate
		
		StringTemplate st = group.getInstanceOf("test");
		assertEquals("a", st.toString());

		// Write the second version of the super template
		f = new PrintWriter(new File("strtemp/err-super.stg"));
		f.print("group err-super;\ntest()::=<<b>>");
		f.close();

		// Run with the second version of the super template
		group = StringTemplateGroup.loadGroup("err");
		group.setRefreshInterval(0);
		
		st = group.getInstanceOf("test");
		assertEquals("b", st.toString());
	}

	public void error(String arg0, Throwable arg1) {
		System.out.println("ST ERROR " + arg0 + " : " + arg1.getMessage());
	}

	public void warning(String arg0) {
		System.out.println("ST WARNING " + arg0);
	}
}
/* -- Begin test code -- */

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org:8080/pipermail/stringtemplate-interest/attachments/20070914/a04f33ba/attachment.html 


More information about the stringtemplate-interest mailing list