public static StringTemplate LoadTemplate(string name) { StringTemplateGroup templateGroup = new StringTemplateGroup ("MG", templatePath, typeof(DefaultTemplateLexer)); return templateGroup.GetInstanceOf (name); }
/** * Instantiates an instance of the CxxTestDriverGenerator for the * specified project and test suite collection. * * @param project the ICProject associated with this generator * @param path the path of the source file to be generated * @param suites the collection of test suites to be generated * * @throws IOException if an I/O error occurs during generation */ public TestRunnerGenerator(string path, TestSuiteCollection suites, Dictionary<string, bool> testsToRun) { this.suites = suites; this.runnerPath = path; // Create a proxy object to manage the tests to run. Any tests // not in this map are assumed to be true (so that if tests // have been added, but not refreshed in the tool window, they // will be run until they are explicitly disabled). this.testsToRunProxy = new TestsToRunProxy(testsToRun); // Load the template from the embedded assembly resources. Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream( RunnerTemplateResourcePath); StringTemplateGroup templateGroup = new StringTemplateGroup( new StreamReader(stream), typeof(AngleBracketTemplateLexer)); templateGroup.RegisterAttributeRenderer(typeof(string), new TestRunnerStringRenderer(path)); template = templateGroup.GetInstanceOf("runAllTestsFile"); // Initialize the options that will be passed into the template. options = new Hashtable(); options["platformIsMSVC"] = true; options["trapSignals"] = true; options["traceStack"] = true; options["noStaticInit"] = true; options["root"] = true; options["part"] = false; options["abortOnFail"] = true; options["longLongType"] = null; options["mainProvided"] = suites.MainFunctionExists; options["runner"] = "XmlStdioPrinter"; options["xmlOutput"] = true; options["testResultsFilename"] = Constants.TestResultsFilename; options["testsToRun"] = testsToRunProxy; writer = File.CreateText(path); }
public void GenerateFile(string outputFilePath, string templateString, string templateName, string rootName, object root) { if (_mostRecentSourceFile < File.GetLastWriteTimeUtc(outputFilePath)) return; StringTemplateGroup group; using (StringReader reader = new StringReader(templateString)) { group = new StringTemplateGroup(reader, typeof(AngleBracketTemplateLexer)); } StringTemplate template = group.GetInstanceOf(templateName); template.SetAttribute(rootName, root); using (StreamWriter writer = new StreamWriter(outputFilePath, false)) { template.Write(new AutoIndentWriter(writer)); } }
private void WriteHeaderFileContent(TextWriter writer, string suitePath) { Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream( NewTestSuiteTemplateResourcePath); StringTemplateGroup templateGroup = new StringTemplateGroup( new StreamReader(stream), typeof(AngleBracketTemplateLexer)); templateGroup.RegisterAttributeRenderer(typeof(string), new NewTestSuiteStringRenderer(suitePath)); StringTemplate template = templateGroup.GetInstanceOf("newSuiteFile"); // Initialize the options that will be passed into the template. Hashtable options = new Hashtable(); options["suiteName"] = suiteName; options["superclass"] = superclass; options["headerUnderTest"] = headerUnderTest.CanonicalName; options["createSetUp"] = createSetUp; options["createTearDown"] = createTearDown; template.SetAttribute("options", options); template.SetAttribute("testCases", new List<string>(stubNames)); template.Write(new AutoIndentWriter(writer)); }