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
33 public class VBCodeProviderTest : Assertion {
\r
35 CodeDomProvider MyVBCodeProvider;
\r
37 static char DSC = Path.DirectorySeparatorChar;
\r
40 public void GetReady() {
\r
43 } else if ('\\' == DSC) {
\r
44 OS = OsType.Windows;
\r
49 MyVBCodeProvider = new VBCodeProvider();
\r
53 public void FileExtension ()
\r
55 AssertEquals ("#JW10", "vb", MyVBCodeProvider.FileExtension);
\r
59 public void LanguageOptionsTest ()
\r
61 AssertEquals ("#JW20", LanguageOptions.CaseInsensitive, MyVBCodeProvider.LanguageOptions);
\r
65 public void CreateCompiler()
\r
67 // Prepare the compilation
\r
68 //Console.WriteLine("#J30.pre1 - CreateCompiler");
\r
69 ICodeCompiler MyVBCodeCompiler;
\r
70 MyVBCodeCompiler = MyVBCodeProvider.CreateCompiler();
\r
71 AssertNotNull ("#JW30 - CreateCompiler", MyVBCodeCompiler);
\r
72 CompilerResults MyVBCodeCompilerResults;
\r
73 //Console.WriteLine("#J30.post1 - CreateCompiler");
\r
75 CompilerParameters options = new CompilerParameters();
\r
76 options.GenerateExecutable = true;
\r
77 options.IncludeDebugInformation = true;
\r
78 options.TreatWarningsAsErrors = true;
\r
80 // Process compilation
\r
81 MyVBCodeCompilerResults = MyVBCodeCompiler.CompileAssemblyFromSource(options,
\r
82 "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
84 // Analyse the compilation success/messages
\r
85 StringCollection MyOutput;
\r
86 MyOutput = MyVBCodeCompilerResults.Output;
\r
87 string MyOutStr = "";
\r
88 foreach (string MyStr in MyOutput)
\r
90 MyOutStr += MyStr + Environment.NewLine + Environment.NewLine;
\r
93 if (MyVBCodeCompilerResults.Errors.Count != 0) {
94 System.Console.WriteLine (MyVBCodeCompilerResults);
95 Assert ("#JW31 - Hello world compilation: " + MyOutStr, false);
\r
100 Assembly MyAss = MyVBCodeCompilerResults.CompiledAssembly;
\r
102 catch (Exception ex)
\r
104 Assert ("#JW32 - MyVBCodeCompilerResults.CompiledAssembly hasn't been an expected object" +
\r
105 Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace, false);
\r
108 // Execute the test app
\r
109 ProcessStartInfo NewProcInfo = new ProcessStartInfo();
\r
111 NewProcInfo.FileName = MyVBCodeCompilerResults.CompiledAssembly.Location;
\r
114 NewProcInfo.FileName = "mono";
\r
115 NewProcInfo.Arguments = MyVBCodeCompilerResults.CompiledAssembly.Location;
\r
117 NewProcInfo.RedirectStandardOutput = true;
\r
118 NewProcInfo.UseShellExecute = false;
\r
119 NewProcInfo.CreateNoWindow = true;
\r
120 string TestAppOutput = "";
\r
123 Process MyProc = Process.Start(NewProcInfo);
\r
124 MyProc.WaitForExit();
\r
125 TestAppOutput = MyProc.StandardOutput.ReadToEnd();
\r
129 catch (Exception ex)
\r
131 Fail("#JW34 - " + ex.Message + Environment.NewLine + ex.StackTrace);
\r
133 AssertEquals("#JW33 - Application output", "Hello world!", TestAppOutput);
\r
138 File.Delete (NewProcInfo.FileName);
\r
144 public void CreateGenerator()
\r
146 ICodeGenerator MyVBCodeGen;
\r
147 MyVBCodeGen = MyVBCodeProvider.CreateGenerator();
\r
148 Assert ("#JW40 - CreateGenerator", (MyVBCodeGen != null));
\r
149 AssertEquals ("#JW41", true, MyVBCodeGen.Supports (GeneratorSupport.DeclareEnums));
\r
154 public void CreateParser()
\r
156 //System.CodeDom.Compiler.ICodeParser CreateParser()
\r
160 public void CreateObjRef()
\r
162 //System.Runtime.Remoting.ObjRef CreateObjRef(System.Type requestedType)
\r
168 return OS == OsType.Windows;
\r
175 return OS == OsType.Unix;
\r
182 return OS == OsType.Mac;
\r