New test.
[mono.git] / mcs / class / System / Test / Microsoft.VisualBasic / VBCodeProviderTest.cs
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
11 //
12
13 using System;
14 using System.CodeDom;
15 using System.CodeDom.Compiler;
16 using System.Collections.Specialized;
17 using System.Globalization;
18 using System.Reflection;
19 using System.Diagnostics;
20 using System.IO;
21 using System.Text;
22 using Microsoft.VisualBasic;
23 using NUnit.Framework;
24
25 namespace MonoTests.Microsoft.VisualBasic
26 {
27         enum OsType
28         {
29                 Windows,
30                 Unix,
31                 Mac
32         }
33
34         [TestFixture]
35         // mbas no longer exists
36         [Category ("NotWorking")]
37         public class VBCodeProviderTest
38         {
39                 private string _tempDir;
40                 private CodeDomProvider _codeProvider;
41                 private static OsType OS;
42                 private static char DSC = Path.DirectorySeparatorChar;
43
44                 private static readonly string _sourceTest1 = "Public Class Test1" +
45                         Environment.NewLine + "End Class";
46                 private static readonly string _sourceTest2 = "Public Class Test2" +
47                         Environment.NewLine + "End Class";
48
49                 [SetUp]
50                 public void GetReady ()
51                 {
52                         if ('/' == DSC) {
53                                 OS = OsType.Unix;
54                         } else if ('\\' == DSC) {
55                                 OS = OsType.Windows;
56                         } else {
57                                 OS = OsType.Mac;
58                         }
59
60                         _codeProvider = new VBCodeProvider ();
61                         _tempDir = CreateTempDirectory ();
62                 }
63
64                 [TearDown]
65                 public void TearDown ()
66                 {
67                         RemoveDirectory (_tempDir);
68                 }
69
70                 [Test]
71                 public void FileExtension ()
72                 {
73                         Assert.AreEqual ("vb", _codeProvider.FileExtension, "#JW10");
74                 }
75
76                 [Test]
77                 public void LanguageOptionsTest ()
78                 {
79                         Assert.AreEqual (LanguageOptions.CaseInsensitive, _codeProvider.LanguageOptions, "#JW20");
80                 }
81
82                 [Test]
83                 public void GeneratorSupports ()
84                 {
85                         ICodeGenerator codeGenerator = _codeProvider.CreateGenerator ();
86                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.DeclareEnums), "#1");
87                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.ArraysOfArrays), "#2");
88                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.AssemblyAttributes), "#3");
89                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.ChainedConstructorArguments), "#4");
90                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.ComplexExpressions), "#5");
91                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.DeclareDelegates), "#6");
92                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.DeclareEnums), "#7");
93                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.DeclareEvents), "#8");
94                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.DeclareInterfaces), "#9");
95                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.DeclareValueTypes), "#10");
96                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.EntryPointMethod), "#11");
97                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.GotoStatements), "#12");
98                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.MultidimensionalArrays), "#13");
99                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.MultipleInterfaceMembers), "#14");
100                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.NestedTypes), "#15");
101                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.ParameterAttributes), "#16");
102                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.PublicStaticMembers), "#17");
103                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.ReferenceParameters), "#18");
104                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.ReturnTypeAttributes), "#19");
105                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.StaticConstructors), "#20");
106                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.TryCatchStatements), "#21");
107                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.Win32Resources), "#22");
108 #if NET_2_0
109                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.DeclareIndexerProperties), "#23");
110                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.GenericTypeDeclaration), "#24");
111                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.GenericTypeReference), "#25");
112                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.PartialTypes), "#26");
113                         Assert.IsTrue (codeGenerator.Supports (GeneratorSupport.Resources), "#27");
114 #endif
115                 }
116
117                 [Test]
118 #if NET_2_0
119                 // there's not yet an mbas for the 2.0 profile
120                 [Category ("NotWorking")]
121 #endif
122                 public void CreateCompiler ()
123                 {
124                         // Prepare the compilation
125                         ICodeCompiler codeCompiler = _codeProvider.CreateCompiler ();
126                         Assert.IsNotNull (codeCompiler, "#JW30 - CreateCompiler");
127
128                         CompilerParameters options = new CompilerParameters ();
129                         options.GenerateExecutable = true;
130                         options.IncludeDebugInformation = true;
131                         options.TreatWarningsAsErrors = true;
132
133                         // process compilation
134                         CompilerResults compilerResults = codeCompiler.CompileAssemblyFromSource (options,
135                                 "public class TestModule" + Environment.NewLine + "public shared sub Main()"
136                                 + Environment.NewLine + "System.Console.Write(\"Hello world!\")"
137                                 + Environment.NewLine + "End Sub" + Environment.NewLine + "End Class");
138
139                         // Analyse the compilation success/messages
140                         StringCollection MyOutput = compilerResults.Output;
141                         string MyOutStr = "";
142                         foreach (string MyStr in MyOutput) {
143                                 MyOutStr += MyStr + Environment.NewLine + Environment.NewLine;
144                         }
145
146                         if (compilerResults.Errors.Count != 0) {
147                                 Assert.Fail ("#JW31 - Hello world compilation: " + MyOutStr);
148                         }
149
150                         try {
151                                 Assembly MyAss = compilerResults.CompiledAssembly;
152                         } catch (Exception ex) {
153                                 Assert.Fail ("#JW32 - compilerResults.CompiledAssembly hasn't been an expected object" +
154                                                 Environment.NewLine + ex.Message + Environment.NewLine + ex.StackTrace);
155                         }
156
157                         // Execute the test app
158                         ProcessStartInfo NewProcInfo = new ProcessStartInfo ();
159                         if (Windows) {
160                                 NewProcInfo.FileName = compilerResults.CompiledAssembly.Location;
161                         } else {
162                                 NewProcInfo.FileName = "mono";
163                                 NewProcInfo.Arguments = compilerResults.CompiledAssembly.Location;
164                         }
165                         NewProcInfo.RedirectStandardOutput = true;
166                         NewProcInfo.UseShellExecute = false;
167                         NewProcInfo.CreateNoWindow = true;
168                         string TestAppOutput = "";
169                         try {
170                                 Process MyProc = Process.Start (NewProcInfo);
171                                 MyProc.WaitForExit ();
172                                 TestAppOutput = MyProc.StandardOutput.ReadToEnd ();
173                                 MyProc.Close ();
174                                 MyProc.Dispose ();
175                         } catch (Exception ex) {
176                                 Assert.Fail ("#JW34 - " + ex.Message + Environment.NewLine + ex.StackTrace);
177                         }
178                         Assert.AreEqual ("Hello world!", TestAppOutput, "#JW33 - Application output");
179
180                         // Clean up
181                         try {
182                                 File.Delete (NewProcInfo.FileName);
183                         } catch { }
184                 }
185
186                 [Test]
187                 public void CreateGenerator ()
188                 {
189                         ICodeGenerator MyVBCodeGen;
190                         MyVBCodeGen = _codeProvider.CreateGenerator ();
191                         Assert.IsNotNull (MyVBCodeGen, "#JW40 - CreateGenerator");
192                         Assert.IsTrue (MyVBCodeGen.Supports (GeneratorSupport.DeclareEnums), "#JW41");
193                 }
194
195                 [Test]
196 #if NET_2_0
197                 // there's not yet an mbas for the 2.0 profile
198                 [Category ("NotWorking")]
199 #endif
200                 public void CompileFromFile_InMemory ()
201                 {
202                         // create vb source file
203                         string sourceFile = Path.Combine (_tempDir, "file." + _codeProvider.FileExtension);
204                         using (FileStream f = new FileStream (sourceFile, FileMode.Create)) {
205                                 using (StreamWriter s = new StreamWriter (f)) {
206                                         s.Write (_sourceTest1);
207                                         s.Close ();
208                                 }
209                                 f.Close ();
210                         }
211
212                         CompilerParameters options = new CompilerParameters ();
213                         options.GenerateExecutable = false;
214                         options.GenerateInMemory = true;
215                         options.TempFiles = new TempFileCollection (_tempDir);
216 #if NET_2_0
217                         options.EmbeddedResources.Add (sourceFile);
218 #endif
219
220                         ICodeCompiler compiler = _codeProvider.CreateCompiler ();
221                         CompilerResults results = compiler.CompileAssemblyFromFile (options,
222                                 sourceFile);
223
224                         // verify compilation was successful
225                         AssertCompileResults (results, true);
226
227                         Assembly compiledAssembly = results.CompiledAssembly;
228
229                         Assert.IsNotNull (compiledAssembly, "#1");
230                         Assert.AreEqual (string.Empty, compiledAssembly.Location, "#2");
231                         Assert.IsNull (results.PathToAssembly, "#3");
232                         Assert.IsNotNull (compiledAssembly.GetType ("Test1"), "#4");
233
234                         // verify we don't cleanup files in temp directory too agressively
235                         string[] tempFiles = Directory.GetFiles (_tempDir);
236                         Assert.AreEqual (1, tempFiles.Length, "#5");
237                         Assert.AreEqual (sourceFile, tempFiles[0], "#6");
238
239 #if NET_2_0
240                         string[] resources = compiledAssembly.GetManifestResourceNames();
241                         Assert.IsNotNull (resources, "#7");
242                         Assert.AreEqual (1, resources.Length, "#8");
243                         Assert.AreEqual ("file.vb", resources[0], "#9");
244                         Assert.IsNull (compiledAssembly.GetFile ("file.vb"), "#10");
245                         Assert.IsNotNull (compiledAssembly.GetManifestResourceStream  ("file.vb"), "#11");
246 #endif
247                 }
248
249                 [Test]
250 #if NET_2_0
251                 // there's not yet an mbas for the 2.0 profile
252                 [Category ("NotWorking")]
253 #endif
254                 public void CompileFromFileBatch_InMemory ()
255                 {
256                         // create vb source file
257                         string sourceFile1 = Path.Combine (_tempDir, "file1." + _codeProvider.FileExtension);
258                         using (FileStream f = new FileStream (sourceFile1, FileMode.Create)) {
259                                 using (StreamWriter s = new StreamWriter (f)) {
260                                         s.Write (_sourceTest1);
261                                         s.Close ();
262                                 }
263                                 f.Close ();
264                         }
265
266                         string sourceFile2 = Path.Combine (_tempDir, "file2." + _codeProvider.FileExtension);
267                         using (FileStream f = new FileStream (sourceFile2, FileMode.Create)) {
268                                 using (StreamWriter s = new StreamWriter (f)) {
269                                         s.Write (_sourceTest2);
270                                         s.Close ();
271                                 }
272                                 f.Close ();
273                         }
274
275                         CompilerParameters options = new CompilerParameters ();
276                         options.GenerateExecutable = false;
277                         options.GenerateInMemory = true;
278                         options.TempFiles = new TempFileCollection (_tempDir);
279 #if NET_2_0
280                         options.EmbeddedResources.Add (sourceFile1);
281                         options.LinkedResources.Add (sourceFile2);
282 #endif
283
284                         ICodeCompiler compiler = _codeProvider.CreateCompiler ();
285                         CompilerResults results = compiler.CompileAssemblyFromFileBatch (options,
286                                 new string[] { sourceFile1, sourceFile2 });
287
288                         // verify compilation was successful
289                         AssertCompileResults (results, true);
290
291                         Assembly compiledAssembly = results.CompiledAssembly;
292
293                         Assert.IsNotNull (compiledAssembly, "#1");
294                         Assert.AreEqual (string.Empty, compiledAssembly.Location, "#2");
295                         Assert.IsNull (results.PathToAssembly, "#3");
296
297                         Assert.IsNotNull (compiledAssembly.GetType ("Test1"), "#4");
298                         Assert.IsNotNull (compiledAssembly.GetType ("Test2"), "#5");
299
300                         // verify we don't cleanup files in temp directory too agressively
301                         string[] tempFiles = Directory.GetFiles (_tempDir);
302                         Assert.AreEqual (2, tempFiles.Length, "#6");
303                         Assert.IsTrue (File.Exists (sourceFile1), "#7");
304                         Assert.IsTrue (File.Exists (sourceFile2), "#8");
305
306 #if NET_2_0
307                         string[] resources = compiledAssembly.GetManifestResourceNames();
308                         Assert.IsNotNull (resources, "#9");
309                         Assert.AreEqual (2, resources.Length, "#10");
310
311                         Assert.AreEqual ("file1.vb", resources[0], "#A1");
312                         Assert.IsNull (compiledAssembly.GetFile ("file1.vb"), "#A2");
313                         Assert.IsNotNull (compiledAssembly.GetManifestResourceStream  ("file1.vb"), "#A3");
314                         ManifestResourceInfo info = compiledAssembly.GetManifestResourceInfo ("file1.vb");
315                         Assert.IsNotNull (info, "#A4");
316                         Assert.IsNull (info.FileName, "#A5");
317                         Assert.IsNull (info.ReferencedAssembly, "#A6");
318                         Assert.AreEqual ((ResourceLocation.Embedded | ResourceLocation.ContainedInManifestFile), info.ResourceLocation, "#A7");
319
320                         Assert.AreEqual ("file2.vb", resources[1], "#B1");
321                         try {
322                                 compiledAssembly.GetFile ("file2.vb");
323                                 Assert.Fail ("#B2");
324                         } catch (FileNotFoundException) {
325                         }
326                         try {
327                                 compiledAssembly.GetManifestResourceStream  ("file2.vb");
328                                 Assert.Fail ("#B3");
329                         } catch (FileNotFoundException) {
330                         }
331                         info = compiledAssembly.GetManifestResourceInfo ("file2.vb");
332                         Assert.IsNotNull (info, "#B4");
333                         Assert.IsNotNull (info.FileName, "#B5");
334                         Assert.AreEqual ("file2.vb", info.FileName, "#N6");
335                         Assert.IsNull (info.ReferencedAssembly, "#B7");
336                         Assert.AreEqual ((ResourceLocation) 0, info.ResourceLocation, "#B8");
337 #endif
338                 }
339
340                 [Test]
341 #if NET_2_0
342                 // there's not yet an mbas for the 2.0 profile
343                 [Category ("NotWorking")]
344 #endif
345                 public void CompileFromSource_InMemory ()
346                 {
347                         // create a file in temp directory to ensure that compiler is not removing
348                         // too much (temporary) files
349                         string tempFile = Path.Combine (_tempDir, "file." + _codeProvider.FileExtension);
350                         using (FileStream fs = File.Create (tempFile)) {
351                                 fs.Close ();
352                         }
353
354                         CompilerParameters options = new CompilerParameters ();
355                         options.GenerateExecutable = false;
356                         options.GenerateInMemory = true;
357                         options.TempFiles = new TempFileCollection (_tempDir);
358
359                         ICodeCompiler compiler = _codeProvider.CreateCompiler ();
360                         CompilerResults results = compiler.CompileAssemblyFromSource (options,
361                                 _sourceTest1);
362
363                         // verify compilation was successful
364                         AssertCompileResults (results, true);
365
366                         Assert.AreEqual (string.Empty, results.CompiledAssembly.Location, "#1");
367                         Assert.IsNull (results.PathToAssembly, "#2");
368                         Assert.IsNotNull (results.CompiledAssembly.GetType ("Test1"), "#3");
369
370                         // verify we don't cleanup files in temp directory too agressively
371                         string[] tempFiles = Directory.GetFiles (_tempDir);
372                         Assert.AreEqual (1, tempFiles.Length, "#4");
373                         Assert.AreEqual (tempFile, tempFiles[0], "#5");
374                 }
375
376                 [Test]
377 #if NET_2_0
378                 // there's not yet an mbas for the 2.0 profile
379                 [Category ("NotWorking")]
380 #endif
381                 public void CompileFromSourceBatch_InMemory ()
382                 {
383                         // create a file in temp directory to ensure that compiler is not removing
384                         // too much (temporary) files
385                         string tempFile = Path.Combine (_tempDir, "file." + _codeProvider.FileExtension);
386                         using (FileStream fs = File.Create (tempFile)) {
387                                 fs.Close ();
388                         }
389
390                         CompilerParameters options = new CompilerParameters ();
391                         options.GenerateExecutable = false;
392                         options.GenerateInMemory = true;
393                         options.TempFiles = new TempFileCollection (_tempDir);
394
395                         ICodeCompiler compiler = _codeProvider.CreateCompiler ();
396                         CompilerResults results = compiler.CompileAssemblyFromSourceBatch (options,
397                                 new string[] { _sourceTest1, _sourceTest2 });
398
399                         // verify compilation was successful
400                         AssertCompileResults (results, true);
401
402                         Assert.AreEqual (string.Empty, results.CompiledAssembly.Location, "#1");
403                         Assert.IsNull (results.PathToAssembly, "#2");
404
405                         Assert.IsNotNull (results.CompiledAssembly.GetType ("Test1"), "#3");
406                         Assert.IsNotNull (results.CompiledAssembly.GetType ("Test2"), "#4");
407
408                         // verify we don't cleanup files in temp directory too agressively
409                         string[] tempFiles = Directory.GetFiles (_tempDir);
410                         Assert.AreEqual (1, tempFiles.Length, "#5");
411                         Assert.AreEqual (tempFile, tempFiles[0], "#6");
412                 }
413
414                 [Test]
415 #if NET_2_0
416                 // there's not yet an mbas for the 2.0 profile
417                 [Category ("NotWorking")]
418 #endif
419                 public void CompileFromDom_NotInMemory ()
420                 {
421                         // create a file in temp directory to ensure that compiler is not removing
422                         // too much (temporary) files
423                         string tempFile = Path.Combine (_tempDir, "file." + _codeProvider.FileExtension);
424                         using (FileStream fs = File.Create (tempFile)) {
425                                 fs.Close ();
426                         }
427
428                         // compile and verify result in separate appdomain to avoid file locks
429                         AppDomain testDomain = CreateTestDomain ();
430                         CrossDomainTester compileTester = CreateCrossDomainTester (testDomain);
431
432                         string outputAssembly = null;
433
434                         try {
435                                 outputAssembly = compileTester.CompileAssemblyFromDom (_tempDir);
436                         } finally {
437                                 AppDomain.Unload (testDomain);
438                         }
439
440                         // there should be two files in temp dir: temp file and output assembly
441                         string[] tempFiles = Directory.GetFiles (_tempDir);
442                         Assert.AreEqual (2, tempFiles.Length, "#1");
443                         Assert.IsTrue (File.Exists (outputAssembly), "#2");
444                         Assert.IsTrue (File.Exists (tempFile), "#3");
445                 }
446
447                 [Test]
448 #if NET_2_0
449                 // there's not yet an mbas for the 2.0 profile
450                 [Category ("NotWorking")]
451 #endif
452                 public void CompileFromDomBatch_NotInMemory ()
453                 {
454                         // create a file in temp directory to ensure that compiler is not removing
455                         // too much (temporary) files
456                         string tempFile = Path.Combine (_tempDir, "file." + _codeProvider.FileExtension);
457                         using (FileStream fs = File.Create (tempFile)) {
458                                 fs.Close ();
459                         }
460
461                         // compile and verify result in separate appdomain to avoid file locks
462                         AppDomain testDomain = CreateTestDomain ();
463                         CrossDomainTester compileTester = CreateCrossDomainTester (testDomain);
464
465                         string outputAssembly = null;
466
467                         try {
468                                 outputAssembly = compileTester.CompileAssemblyFromDomBatch (_tempDir);
469                         } finally {
470                                 AppDomain.Unload (testDomain);
471                         }
472
473                         // there should be two files in temp dir: temp file and output assembly
474                         string[] tempFiles = Directory.GetFiles (_tempDir);
475                         Assert.AreEqual (2, tempFiles.Length, "#1");
476                         Assert.IsTrue (File.Exists (outputAssembly), "#2");
477                         Assert.IsTrue (File.Exists (tempFile), "#3");
478                 }
479
480                 [Test]
481 #if NET_2_0
482                 // there's not yet an mbas for the 2.0 profile
483                 [Category ("NotWorking")]
484 #endif
485                 public void CompileFromDom_InMemory ()
486                 {
487                         // create a file in temp directory to ensure that compiler is not removing
488                         // too much (temporary) files
489                         string tempFile = Path.Combine (_tempDir, "file." + _codeProvider.FileExtension);
490                         using (FileStream fs = File.Create (tempFile)) {
491                                 fs.Close ();
492                         }
493
494                         CompilerParameters options = new CompilerParameters ();
495                         options.GenerateExecutable = false;
496                         options.GenerateInMemory = true;
497                         options.TempFiles = new TempFileCollection (_tempDir);
498
499                         ICodeCompiler compiler = _codeProvider.CreateCompiler ();
500                         CompilerResults results = compiler.CompileAssemblyFromDom (options, new CodeCompileUnit ());
501
502                         // verify compilation was successful
503                         AssertCompileResults (results, true);
504
505                         Assert.AreEqual (string.Empty, results.CompiledAssembly.Location, "#1");
506                         Assert.IsNull (results.PathToAssembly, "#2");
507
508                         // verify we don't cleanup files in temp directory too agressively
509                         string[] tempFiles = Directory.GetFiles (_tempDir);
510                         Assert.AreEqual (1, tempFiles.Length, "#3");
511                         Assert.AreEqual (tempFile, tempFiles[0], "#4");
512                 }
513
514                 [Test]
515 #if NET_2_0
516                 // there's not yet an mbas for the 2.0 profile
517                 [Category ("NotWorking")]
518 #endif
519                 public void CompileFromDomBatch_InMemory ()
520                 {
521                         // create a file in temp directory to ensure that compiler is not removing
522                         // too much (temporary) files
523                         string tempFile = Path.Combine (_tempDir, "file." + _codeProvider.FileExtension);
524                         using (FileStream fs = File.Create (tempFile)) {
525                                 fs.Close ();
526                         }
527
528                         CompilerParameters options = new CompilerParameters ();
529                         options.GenerateExecutable = false;
530                         options.GenerateInMemory = true;
531                         options.TempFiles = new TempFileCollection (_tempDir);
532
533                         ICodeCompiler compiler = _codeProvider.CreateCompiler ();
534                         CompilerResults results = compiler.CompileAssemblyFromDomBatch (options,
535                                 new CodeCompileUnit[] { new CodeCompileUnit (), new CodeCompileUnit () });
536
537                         // verify compilation was successful
538                         AssertCompileResults (results, true);
539
540                         Assert.AreEqual (string.Empty, results.CompiledAssembly.Location, "#1");
541                         Assert.IsNull (results.PathToAssembly, "#2");
542
543                         // verify we don't cleanup files in temp directory too agressively
544                         string[] tempFiles = Directory.GetFiles (_tempDir);
545                         Assert.AreEqual (1, tempFiles.Length, "#3");
546                         Assert.AreEqual (tempFile, tempFiles[0], "#4");
547                 }
548
549                 //TODO: [Test]
550                 public void CreateParser ()
551                 {
552                         //System.CodeDom.Compiler.ICodeParser CreateParser()
553                 }
554
555                 //TODO: [Test]
556                 public void CreateObjRef ()
557                 {
558                         //System.Runtime.Remoting.ObjRef CreateObjRef(System.Type requestedType)
559                 }
560
561                 bool Windows
562                 {
563                         get {
564                                 return OS == OsType.Windows;
565                         }
566                 }
567
568                 bool Unix
569                 {
570                         get {
571                                 return OS == OsType.Unix;
572                         }
573                 }
574
575                 bool Mac
576                 {
577                         get {
578                                 return OS == OsType.Mac;
579                         }
580                 }
581
582                 private static string CreateTempDirectory ()
583                 {
584                         // create a uniquely named zero-byte file
585                         string tempFile = Path.GetTempFileName ();
586                         // remove the temporary file
587                         File.Delete (tempFile);
588                         // create a directory named after the unique temporary file
589                         Directory.CreateDirectory (tempFile);
590                         // return the path to the temporary directory
591                         return tempFile;
592                 }
593
594                 private static void RemoveDirectory (string path)
595                 {
596                         try {
597                                 if (Directory.Exists (path)) {
598                                         string[] directoryNames = Directory.GetDirectories (path);
599                                         foreach (string directoryName in directoryNames) {
600                                                 RemoveDirectory (directoryName);
601                                         }
602                                         string[] fileNames = Directory.GetFiles (path);
603                                         foreach (string fileName in fileNames) {
604                                                 File.Delete (fileName);
605                                         }
606                                         Directory.Delete (path, true);
607                                 }
608                         } catch (Exception ex) {
609                                 throw new AssertionException ("Unable to cleanup '" + path + "'.", ex);
610                         }
611                 }
612
613                 private static void AssertCompileResults (CompilerResults results, bool allowWarnings)
614                 {
615                         foreach (CompilerError compilerError in results.Errors) {
616                                 if (allowWarnings && compilerError.IsWarning) {
617                                         continue;
618                                 }
619
620                                 Assert.Fail (compilerError.ToString ());
621                         }
622                 }
623
624                 private static AppDomain CreateTestDomain ()
625                 {
626                         return AppDomain.CreateDomain ("CompileFromDom", AppDomain.CurrentDomain.Evidence,
627                                 AppDomain.CurrentDomain.SetupInformation);
628                 }
629
630                 private static CrossDomainTester CreateCrossDomainTester (AppDomain domain)
631                 {
632                         Type testerType = typeof (CrossDomainTester);
633
634                         return (CrossDomainTester) domain.CreateInstanceAndUnwrap (
635                                 testerType.Assembly.FullName, testerType.FullName, false,
636                                 BindingFlags.Public | BindingFlags.Instance, null, new object[0],
637                                 CultureInfo.InvariantCulture, new object[0], domain.Evidence);
638                 }
639
640                 private class CrossDomainTester : MarshalByRefObject
641                 {
642                         public string CompileAssemblyFromDom (string tempDir)
643                         {
644                                 CompilerParameters options = new CompilerParameters ();
645                                 options.GenerateExecutable = false;
646                                 options.GenerateInMemory = false;
647                                 options.TempFiles = new TempFileCollection (tempDir);
648
649                                 VBCodeProvider codeProvider = new VBCodeProvider ();
650                                 ICodeCompiler compiler = codeProvider.CreateCompiler ();
651                                 CompilerResults results = compiler.CompileAssemblyFromDom (options, new CodeCompileUnit ());
652
653                                 // verify compilation was successful
654                                 AssertCompileResults (results, true);
655
656                                 Assert.IsTrue (results.CompiledAssembly.Location.Length != 0,
657                                         "Location should not be empty string");
658                                 Assert.IsNotNull (results.PathToAssembly, "PathToAssembly should not be null");
659
660                                 return results.PathToAssembly;
661                         }
662
663                         public string CompileAssemblyFromDomBatch (string tempDir)
664                         {
665                                 CompilerParameters options = new CompilerParameters ();
666                                 options.GenerateExecutable = false;
667                                 options.GenerateInMemory = false;
668                                 options.TempFiles = new TempFileCollection (tempDir);
669
670                                 VBCodeProvider codeProvider = new VBCodeProvider ();
671                                 ICodeCompiler compiler = codeProvider.CreateCompiler ();
672                                 CompilerResults results = compiler.CompileAssemblyFromDomBatch (options, new CodeCompileUnit[] { new CodeCompileUnit (), new CodeCompileUnit () });
673
674                                 // verify compilation was successful
675                                 AssertCompileResults (results, true);
676
677                                 Assert.IsTrue (results.CompiledAssembly.Location.Length != 0,
678                                         "Location should not be empty string");
679                                 Assert.IsNotNull (results.PathToAssembly, "PathToAssembly should not be null");
680
681                                 return results.PathToAssembly;
682                         }
683                 }
684         }
685 }