2 // Microsoft.VisualBasic.VBCodeProvider.cs
5 // Jochen Wezel (jwezel@compumaster.de) //
7 // (C) 2003 Jochen Wezel (CompuMaster GmbH)
10 // 2003-12-10 JW: publishing of this file
13 using NUnit
.Framework
;
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
;
23 namespace MonoTests
.System
.Microsoft
.VisualBasic
33 public class VBCodeProviderTest
: Assertion
{
35 CodeDomProvider MyVBCodeProvider
;
37 static char DSC
= Path
.DirectorySeparatorChar
;
40 public void GetReady() {
43 } else if ('\\' == DSC
) {
49 MyVBCodeProvider
= new VBCodeProvider();
53 public void FileExtension ()
55 AssertEquals ("#JW10", "vb", MyVBCodeProvider
.FileExtension
);
59 public void LanguageOptionsTest ()
61 AssertEquals ("#JW20", LanguageOptions
.CaseInsensitive
, MyVBCodeProvider
.LanguageOptions
);
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
;
88 foreach (string MyStr
in MyOutput
)
90 MyOutStr
+= MyStr
+ Environment
.NewLine
+ Environment
.NewLine
;
93 AssertEquals ("#JW31 - Hello world compilation: " + MyOutStr
, 0, MyVBCodeCompilerResults
.Errors
.Count
);
97 Assembly MyAss
= MyVBCodeCompilerResults
.CompiledAssembly
;
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();
108 NewProcInfo
.FileName
= MyVBCodeCompilerResults
.CompiledAssembly
.Location
;
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();
128 Fail("#JW34 - " + ex
.Message
+ Environment
.NewLine
+ ex
.StackTrace
);
130 AssertEquals("#JW33 - Application output", "Hello world!", TestAppOutput
);
135 File
.Delete (NewProcInfo
.FileName
);
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
));
151 public void CreateParser()
153 //System.CodeDom.Compiler.ICodeParser CreateParser()
157 public void CreateObjRef()
159 //System.Runtime.Remoting.ObjRef CreateObjRef(System.Type requestedType)
165 return OS
== OsType
.Windows
;
172 return OS
== OsType
.Unix
;
179 return OS
== OsType
.Mac
;