**** Merged from MCS ****
[mono-project.git] / mcs / class / System / Test / Microsoft.VisualBasic / VBCodeProviderTest.cs
blobe30c6ff6e57319b87691ca2832f034ed0583912c
1 //
2 // Microsoft.VisualBasic.VBCodeProvider.cs
3 //
4 // Author:
5 // Jochen Wezel (jwezel@compumaster.de) //
6 //
7 // (C) 2003 Jochen Wezel (CompuMaster GmbH)
8 //
9 // Last modifications:
10 // 2003-12-10 JW: publishing of this file
13 using NUnit.Framework;
14 using System;
15 using Microsoft.VisualBasic;
16 using System.CodeDom.Compiler;
17 using System.ComponentModel;
18 using System.Collections.Specialized;
19 using System.Reflection;
20 using System.Diagnostics;
21 using System.IO;
23 namespace MonoTests.System.Microsoft.VisualBasic
26 enum OsType {
27 Windows,
28 Unix,
29 Mac
32 [TestFixture]
33 public class VBCodeProviderTest : Assertion {
35 CodeDomProvider MyVBCodeProvider;
36 static OsType OS;
37 static char DSC = Path.DirectorySeparatorChar;
39 [SetUp]
40 public void GetReady() {
41 if ('/' == DSC) {
42 OS = OsType.Unix;
43 } else if ('\\' == DSC) {
44 OS = OsType.Windows;
45 } else {
46 OS = OsType.Mac;
49 MyVBCodeProvider = new VBCodeProvider();
52 [Test]
53 public void FileExtension ()
55 AssertEquals ("#JW10", "vb", MyVBCodeProvider.FileExtension);
58 [Test]
59 public void LanguageOptionsTest ()
61 AssertEquals ("#JW20", LanguageOptions.CaseInsensitive, MyVBCodeProvider.LanguageOptions);
64 [Test]
65 public void CreateCompiler()
67 // Prepare the compilation
68 //Console.WriteLine("#J30.pre1 - CreateCompiler");
69 ICodeCompiler MyVBCodeCompiler;
70 MyVBCodeCompiler = MyVBCodeProvider.CreateCompiler();
71 AssertNotNull ("#JW30 - CreateCompiler", MyVBCodeCompiler);
72 CompilerResults MyVBCodeCompilerResults;
73 //Console.WriteLine("#J30.post1 - CreateCompiler");
75 CompilerParameters options = new CompilerParameters();
76 options.GenerateExecutable = true;
77 options.IncludeDebugInformation = true;
78 options.TreatWarningsAsErrors = true;
80 // Process compilation
81 MyVBCodeCompilerResults = MyVBCodeCompiler.CompileAssemblyFromSource(options,
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);
84 // Analyse the compilation success/messages
85 StringCollection MyOutput;
86 MyOutput = MyVBCodeCompilerResults.Output;
87 string MyOutStr = "";
88 foreach (string MyStr in MyOutput)
90 MyOutStr += MyStr + Environment.NewLine + Environment.NewLine;
93 AssertEquals ("#JW31 - Hello world compilation: " + MyOutStr, 0, MyVBCodeCompilerResults.Errors.Count);
95 try
97 Assembly MyAss = MyVBCodeCompilerResults.CompiledAssembly;
99 catch (Exception ex)
101 Assert ("#JW32 - MyVBCodeCompilerResults.CompiledAssembly hasn't been an expected object" +
102 Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace, false);
105 // Execute the test app
106 ProcessStartInfo NewProcInfo = new ProcessStartInfo();
107 if (Windows) {
108 NewProcInfo.FileName = MyVBCodeCompilerResults.CompiledAssembly.Location;
110 else {
111 NewProcInfo.FileName = "mono";
112 NewProcInfo.Arguments = MyVBCodeCompilerResults.CompiledAssembly.Location;
114 NewProcInfo.RedirectStandardOutput = true;
115 NewProcInfo.UseShellExecute = false;
116 NewProcInfo.CreateNoWindow = true;
117 string TestAppOutput = "";
120 Process MyProc = Process.Start(NewProcInfo);
121 MyProc.WaitForExit();
122 TestAppOutput = MyProc.StandardOutput.ReadToEnd();
123 MyProc.Close();
124 MyProc.Dispose();
126 catch (Exception ex)
128 Fail("#JW34 - " + ex.Message + Environment.NewLine + ex.StackTrace);
130 AssertEquals("#JW33 - Application output", "Hello world!", TestAppOutput);
132 // Clean up
135 File.Delete (NewProcInfo.FileName);
137 catch {}
140 [Test]
141 public void CreateGenerator()
143 ICodeGenerator MyVBCodeGen;
144 MyVBCodeGen = MyVBCodeProvider.CreateGenerator();
145 Assert ("#JW40 - CreateGenerator", (MyVBCodeGen != null));
146 AssertEquals ("#JW41", true, MyVBCodeGen.Supports (GeneratorSupport.DeclareEnums));
150 //TODO: [Test]
151 public void CreateParser()
153 //System.CodeDom.Compiler.ICodeParser CreateParser()
156 //TODO: [Test]
157 public void CreateObjRef()
159 //System.Runtime.Remoting.ObjRef CreateObjRef(System.Type requestedType)
162 bool Windows
164 get {
165 return OS == OsType.Windows;
169 bool Unix
171 get {
172 return OS == OsType.Unix;
176 bool Mac
178 get {
179 return OS == OsType.Mac;