protected void RunParserTestCase(string testfile) { _compiler.Parameters.Input.Add(GetCompilerInput(testfile)); Boo.Lang.Compiler.CompilerContext context = _compiler.Run(); if (context.Errors.Count > 0) { Assert.Fail(context.Errors.ToString(true)); } Assert.AreEqual(1, context.CompileUnit.Modules.Count, "expected a module as output"); string expected = GetDocumentation(context.CompileUnit.Modules[0]); string output = _compiler.Parameters.OutputWriter.ToString(); Assert.AreEqual(expected.Trim(), output.ToString().Trim().Replace("\r\n", "\n"), testfile); }
void AssertCultureDependentMessage(string message, CultureInfo culture) { var savedCulture = Thread.CurrentThread.CurrentUICulture; Thread.CurrentThread.CurrentUICulture = culture; try { var compiler = new Boo.Lang.Compiler.BooCompiler(); var options = compiler.Parameters; options.Input.Add(new Boo.Lang.Compiler.IO.StringInput("testcase", TestCase)); options.Pipeline = new Boo.Lang.Compiler.Pipelines.Parse(); var errors = compiler.Run().Errors; Assert.IsTrue(errors.Count >= 1); Assert.AreEqual(message, errors[0].Message); } finally { Thread.CurrentThread.CurrentUICulture = savedCulture; } }
protected void RunParserTestCase(string testfile) { _compiler.Parameters.Input.Add(new FileInput(GetTestCasePath(testfile))); Boo.Lang.Compiler.CompilerContext context = _compiler.Run(); if (context.Errors.Count > 0) { Assert.Fail(context.Errors.ToString(true)); } Assert.AreEqual(1, context.CompileUnit.Modules.Count, "expected a module as output"); string expected = context.CompileUnit.Modules[0].Documentation; if (null == expected) { Assert.Fail(string.Format("Test case '{0}' does not have a docstring!", testfile)); } string output = _compiler.Parameters.OutputWriter.ToString(); Assert.AreEqual(expected.Trim(), output.ToString().Trim().Replace("\r\n", "\n"), testfile); }
private static CompilerResults CompileBoo(string[] sourceFiles, string[] referencedAssemblies) { // Prepare parameters var cp = new Boo.Lang.Compiler.CompilerParameters(); cp.Pipeline = new CompileToMemory(); cp.Ducky = true; cp.Debug = true; cp.OutputType = Boo.Lang.Compiler.CompilerOutputType.Library; cp.DefaultMethodVisibility = Boo.Lang.Compiler.Ast.TypeMemberModifiers.Public; // References cp.References.Add(typeof(System.Windows.Forms.Form).Assembly); cp.References.Add(typeof(System.Drawing.Color).Assembly); cp.References.Add(typeof(System.Xml.XmlDocument).Assembly); // .NET 3.5 if (Net35) { if (coreAssembly == null) { coreAssembly = Assembly.LoadWithPartialName("System.Core"); } cp.References.Add(coreAssembly); } // Add input files foreach (string file in sourceFiles) { string ext = Path.GetExtension(file); if (String.Compare(ext, ".boo", StringComparison.InvariantCultureIgnoreCase) == 0) { cp.Input.Add(new Boo.Lang.Compiler.IO.FileInput(file)); } else if (ext.ToLowerInvariant() == ".resx") { cp.Resources.Add(new Boo.Lang.Compiler.Resources.EmbeddedFileResource(file)); } } if (cp.Input.Count == 0) { // Nothing to compile return null; } // Create compiler Boo.Lang.Compiler.BooCompiler booc = new Boo.Lang.Compiler.BooCompiler(cp); var ctx = booc.Run(); // Convert result CompilerResults result = new CompilerResults(null); result.CompiledAssembly = ctx.GeneratedAssembly; result.Output.Add(booc.GetType().AssemblyQualifiedName); result.Output.Add(""); foreach (Boo.Lang.Compiler.CompilerWarning w in ctx.Warnings) { result.Output.Add(w.ToString()); } foreach (Boo.Lang.Compiler.CompilerError e in ctx.Errors) { result.Output.Add(e.ToString()); result.Errors.Add(new CompilerError(e.LexicalInfo.FileName, e.LexicalInfo.Line, e.LexicalInfo.Column, e.Code, e.Message)); } return result; }
private static CompilerResults CompileBoo(string[] sourceFiles, string[] referencedAssemblies) { // Prepare parameters var cp = new Boo.Lang.Compiler.CompilerParameters(); cp.Pipeline = new CompileToMemory(); cp.Ducky = true; cp.Debug = true; cp.OutputType = Boo.Lang.Compiler.CompilerOutputType.Library; cp.DefaultMethodVisibility = Boo.Lang.Compiler.Ast.TypeMemberModifiers.Public; // References cp.References.Add(typeof(System.Windows.Forms.Form).Assembly); cp.References.Add(typeof(System.Drawing.Color).Assembly); cp.References.Add(typeof(System.Xml.XmlDocument).Assembly); // .NET 3.5 if (Net35) { if (coreAssembly == null) { coreAssembly = Assembly.LoadWithPartialName("System.Core"); } cp.References.Add(coreAssembly); } // Add input files foreach (string file in sourceFiles) { string ext = Path.GetExtension(file); if (String.Compare(ext, ".boo", StringComparison.InvariantCultureIgnoreCase) == 0) { cp.Input.Add(new Boo.Lang.Compiler.IO.FileInput(file)); } else if (ext.ToLowerInvariant() == ".resx") { cp.Resources.Add(new Boo.Lang.Compiler.Resources.EmbeddedFileResource(file)); } } if (cp.Input.Count == 0) { // Nothing to compile return(null); } // Create compiler Boo.Lang.Compiler.BooCompiler booc = new Boo.Lang.Compiler.BooCompiler(cp); var ctx = booc.Run(); // Convert result CompilerResults result = new CompilerResults(null); result.CompiledAssembly = ctx.GeneratedAssembly; result.Output.Add(booc.GetType().AssemblyQualifiedName); result.Output.Add(""); foreach (Boo.Lang.Compiler.CompilerWarning w in ctx.Warnings) { result.Output.Add(w.ToString()); } foreach (Boo.Lang.Compiler.CompilerError e in ctx.Errors) { result.Output.Add(e.ToString()); result.Errors.Add(new CompilerError(e.LexicalInfo.FileName, e.LexicalInfo.Line, e.LexicalInfo.Column, e.Code, e.Message)); } return(result); }