2 // Microsoft.VisualBasic.VBCodeProvider.cs
\r
5 // Jochen Wezel (jwezel@compumaster.de) //
\r
7 // (C) 2003 Jochen Wezel (CompuMaster GmbH)
\r
9 // Last modifications:
\r
10 // 2003-12-10 JW: publishing of this file
\r
13 using NUnit.Framework;
\r
15 using Microsoft.VisualBasic;
\r
16 using System.CodeDom.Compiler;
\r
17 using System.ComponentModel;
\r
18 using System.Collections.Specialized;
\r
19 using System.Reflection;
\r
20 using System.Diagnostics;
\r
23 namespace MonoTests.System.Microsoft.VisualBasic
\r
26 public class VBCodeProviderTest : Assertion {
\r
28 CodeDomProvider MyVBCodeProvider;
\r
31 public void GetReady() {
\r
32 MyVBCodeProvider = new VBCodeProvider();
\r
36 public void FileExtension ()
\r
38 AssertEquals ("#JW10", "vb", MyVBCodeProvider.FileExtension);
\r
42 public void LanguageOptionsTest ()
\r
44 AssertEquals ("#JW20", LanguageOptions.CaseInsensitive, MyVBCodeProvider.LanguageOptions);
\r
48 public void CreateCompiler()
\r
50 // Prepare the compilation
\r
51 //Console.WriteLine("#J30.pre1 - CreateCompiler");
\r
52 ICodeCompiler MyVBCodeCompiler;
\r
53 MyVBCodeCompiler = MyVBCodeProvider.CreateCompiler();
\r
54 AssertNotNull ("#JW30 - CreateCompiler", MyVBCodeCompiler);
\r
55 CompilerResults MyVBCodeCompilerResults;
\r
56 //Console.WriteLine("#J30.post1 - CreateCompiler");
\r
58 CompilerParameters options = new CompilerParameters();
\r
59 options.GenerateExecutable = true;
\r
60 options.IncludeDebugInformation = true;
\r
61 options.TreatWarningsAsErrors = true;
\r
63 // Process compilation
\r
64 MyVBCodeCompilerResults = MyVBCodeCompiler.CompileAssemblyFromSource(options,
\r
65 "public class TestModule" + Environment.NewLine + "public shared sub Main()" + Environment.NewLine + "System.Console.Write(\"Hello world!\")" + Environment.NewLine + "End Sub" + Environment.NewLine + "End Class" + Environment.NewLine);
\r
67 // Analyse the compilation success/messages
\r
68 StringCollection MyOutput;
\r
69 MyOutput = MyVBCodeCompilerResults.Output;
\r
70 string MyOutStr = "";
\r
71 foreach (string MyStr in MyOutput)
\r
73 MyOutStr += MyStr + Environment.NewLine + Environment.NewLine;
\r
76 AssertEquals ("#JW31 - Hello world compilation: " + MyOutStr, 0, MyVBCodeCompilerResults.Errors.Count);
\r
80 Assembly MyAss = MyVBCodeCompilerResults.CompiledAssembly;
\r
82 catch (Exception ex)
\r
84 Assert ("#JW32 - MyVBCodeCompilerResults.CompiledAssembly hasn't been an expected object" +
\r
85 Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace, false);
\r
88 // Execute the test app
\r
89 ProcessStartInfo NewProcInfo = new ProcessStartInfo();
\r
90 NewProcInfo.FileName = MyVBCodeCompilerResults.CompiledAssembly.Location;
\r
91 NewProcInfo.RedirectStandardOutput = true;
\r
92 NewProcInfo.UseShellExecute = false;
\r
93 NewProcInfo.CreateNoWindow = true;
\r
94 string TestAppOutput = "";
\r
97 Process MyProc = Process.Start(NewProcInfo);
\r
98 MyProc.WaitForExit();
\r
99 TestAppOutput = MyProc.StandardOutput.ReadToEnd();
\r
103 catch (Exception ex)
\r
105 Assert("#JW34 - " + ex.Message + Environment.NewLine + ex.StackTrace, false);
\r
107 AssertEquals("#JW33 - Application output", "Hello world!", TestAppOutput);
\r
112 File.Delete (NewProcInfo.FileName);
\r
118 public void CreateGenerator()
\r
120 ICodeGenerator MyVBCodeGen;
\r
121 MyVBCodeGen = MyVBCodeProvider.CreateGenerator();
\r
122 Assert ("#JW40 - CreateGenerator", (MyVBCodeGen != null));
\r
123 AssertEquals ("#JW41", true, MyVBCodeGen.Supports (GeneratorSupport.DeclareEnums));
\r
128 public void CreateParser()
\r
130 //System.CodeDom.Compiler.ICodeParser CreateParser()
\r
134 public void CreateObjRef()
\r
136 //System.Runtime.Remoting.ObjRef CreateObjRef(System.Type requestedType)
\r