| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184 |
- //
- // Microsoft.VisualBasic.VBCodeProvider.cs
- //
- // Author:
- // Jochen Wezel ([email protected]) //
- //
- // (C) 2003 Jochen Wezel (CompuMaster GmbH)
- //
- // Last modifications:
- // 2003-12-10 JW: publishing of this file
- //
- using NUnit.Framework;
- using System;
- using Microsoft.VisualBasic;
- using System.CodeDom.Compiler;
- using System.ComponentModel;
- using System.Collections.Specialized;
- using System.Reflection;
- using System.Diagnostics;
- using System.IO;
- namespace MonoTests.System.Microsoft.VisualBasic
- {
- enum OsType {
- Windows,
- Unix,
- Mac
- }
- [TestFixture]
- public class VBCodeProviderTest : Assertion {
-
- CodeDomProvider MyVBCodeProvider;
- static OsType OS;
- static char DSC = Path.DirectorySeparatorChar;
- [SetUp]
- public void GetReady() {
- if ('/' == DSC) {
- OS = OsType.Unix;
- } else if ('\\' == DSC) {
- OS = OsType.Windows;
- } else {
- OS = OsType.Mac;
- }
- MyVBCodeProvider = new VBCodeProvider();
- }
- [Test]
- public void FileExtension ()
- {
- AssertEquals ("#JW10", "vb", MyVBCodeProvider.FileExtension);
- }
- [Test]
- public void LanguageOptionsTest ()
- {
- AssertEquals ("#JW20", LanguageOptions.CaseInsensitive, MyVBCodeProvider.LanguageOptions);
- }
- [Test]
- public void CreateCompiler()
- {
- // Prepare the compilation
- //Console.WriteLine("#J30.pre1 - CreateCompiler");
- ICodeCompiler MyVBCodeCompiler;
- MyVBCodeCompiler = MyVBCodeProvider.CreateCompiler();
- AssertNotNull ("#JW30 - CreateCompiler", MyVBCodeCompiler);
- CompilerResults MyVBCodeCompilerResults;
- //Console.WriteLine("#J30.post1 - CreateCompiler");
- CompilerParameters options = new CompilerParameters();
- options.GenerateExecutable = true;
- options.IncludeDebugInformation = true;
- options.TreatWarningsAsErrors = true;
-
- // Process compilation
- MyVBCodeCompilerResults = MyVBCodeCompiler.CompileAssemblyFromSource(options,
- "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);
- // Analyse the compilation success/messages
- StringCollection MyOutput;
- MyOutput = MyVBCodeCompilerResults.Output;
- string MyOutStr = "";
- foreach (string MyStr in MyOutput)
- {
- MyOutStr += MyStr + Environment.NewLine + Environment.NewLine;
- }
- AssertEquals ("#JW31 - Hello world compilation: " + MyOutStr, 0, MyVBCodeCompilerResults.Errors.Count);
- try
- {
- Assembly MyAss = MyVBCodeCompilerResults.CompiledAssembly;
- }
- catch (Exception ex)
- {
- Assert ("#JW32 - MyVBCodeCompilerResults.CompiledAssembly hasn't been an expected object" +
- Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace, false);
- }
- // Execute the test app
- ProcessStartInfo NewProcInfo = new ProcessStartInfo();
- if (Windows) {
- NewProcInfo.FileName = MyVBCodeCompilerResults.CompiledAssembly.Location;
- }
- else {
- NewProcInfo.FileName = "mono";
- NewProcInfo.Arguments = MyVBCodeCompilerResults.CompiledAssembly.Location;
- }
- NewProcInfo.RedirectStandardOutput = true;
- NewProcInfo.UseShellExecute = false;
- NewProcInfo.CreateNoWindow = true;
- string TestAppOutput = "";
- try
- {
- Process MyProc = Process.Start(NewProcInfo);
- MyProc.WaitForExit();
- TestAppOutput = MyProc.StandardOutput.ReadToEnd();
- MyProc.Close();
- MyProc.Dispose();
- }
- catch (Exception ex)
- {
- Fail("#JW34 - " + ex.Message + Environment.NewLine + ex.StackTrace);
- }
- AssertEquals("#JW33 - Application output", "Hello world!", TestAppOutput);
- // Clean up
- try
- {
- File.Delete (NewProcInfo.FileName);
- }
- catch {}
- }
- [Test]
- public void CreateGenerator()
- {
- ICodeGenerator MyVBCodeGen;
- MyVBCodeGen = MyVBCodeProvider.CreateGenerator();
- Assert ("#JW40 - CreateGenerator", (MyVBCodeGen != null));
- AssertEquals ("#JW41", true, MyVBCodeGen.Supports (GeneratorSupport.DeclareEnums));
- }
-
- //TODO: [Test]
- public void CreateParser()
- {
- //System.CodeDom.Compiler.ICodeParser CreateParser()
- }
- //TODO: [Test]
- public void CreateObjRef()
- {
- //System.Runtime.Remoting.ObjRef CreateObjRef(System.Type requestedType)
- }
- bool Windows
- {
- get {
- return OS == OsType.Windows;
- }
- }
- bool Unix
- {
- get {
- return OS == OsType.Unix;
- }
- }
- bool Mac
- {
- get {
- return OS == OsType.Mac;
- }
- }
- }
- }
|