2 // ManagedCompilerTest.cs
5 // Marek Sieradzki (marek.sieradzki@gmail.com)
7 // (C) 2006 Marek Sieradzki
9 // Permission is hereby granted, free of charge, to any person obtaining
10 // a copy of this software and associated documentation files (the
11 // "Software"), to deal in the Software without restriction, including
12 // without limitation the rights to use, copy, modify, merge, publish,
13 // distribute, sublicense, and/or sell copies of the Software, and to
14 // permit persons to whom the Software is furnished to do so, subject to
15 // the following conditions:
17 // The above copyright notice and this permission notice shall be
18 // included in all copies or substantial portions of the Software.
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 using System.Collections;
30 using Microsoft.Build.BuildEngine;
31 using Microsoft.Build.Framework;
32 using Microsoft.Build.Tasks;
33 using Microsoft.Build.Utilities;
34 using NUnit.Framework;
36 namespace MonoTests.Microsoft.Build.Tasks {
38 class MCExtended : ManagedCompiler {
44 public void ARFC (CommandLineBuilderExtension commandLine)
46 base.AddResponseFileCommands (commandLine);
49 public void ACLC (CommandLineBuilderExtension commandLine)
51 base.AddCommandLineCommands (commandLine);
54 public new bool CheckAllReferencesExistOnDisk ()
56 return base.CheckAllReferencesExistOnDisk ();
60 protected override string ToolName {
61 get { return "something"; }
64 protected override string GenerateFullPathToTool ()
71 public class ManagedCompilerTest {
74 public void TestAssignment ()
76 MCExtended mc = new MCExtended ();
78 mc.AdditionalLibPaths = new string [1] { "1" };
79 mc.AddModules = new string [1] { "2" };
82 mc.DefineConstants = "5";
84 mc.EmitDebugInformation = true;
86 mc.KeyContainer = "7";
88 mc.LinkResources = new ITaskItem [1] { new TaskItem ("9") };
89 mc.MainEntryPoint = "10";
93 mc.OutputAssembly = new TaskItem ("11");
94 mc.References = new ITaskItem [1] { new TaskItem ("12") };
95 mc.Resources = new ITaskItem [1] { new TaskItem ("13") };
96 mc.ResponseFiles = new ITaskItem [1] { new TaskItem ("14") };
97 mc.Sources = new ITaskItem [1] { new TaskItem ("15") };
99 mc.TreatWarningsAsErrors = true;
100 mc.Utf8Output = true;
102 mc.Win32Resource = "18";
104 Assert.AreEqual ("1", mc.AdditionalLibPaths [0], "A1");
105 Assert.AreEqual ("2", mc.AddModules [0], "A2");
106 Assert.AreEqual (3, mc.CodePage, "A3");
107 Assert.AreEqual ("4", mc.DebugType, "A4");
108 Assert.AreEqual ("5", mc.DefineConstants, "A5");
109 Assert.AreEqual (true, mc.DelaySign, "A6");
110 Assert.AreEqual (true, mc.EmitDebugInformation, "A7");
111 Assert.AreEqual (6, mc.FileAlignment, "A8");
112 Assert.AreEqual ("7", mc.KeyContainer, "A9");
113 Assert.AreEqual ("8", mc.KeyFile, "A10");
114 Assert.AreEqual ("9", mc.LinkResources [0].ItemSpec, "A11");
115 Assert.AreEqual ("10", mc.MainEntryPoint, "A12");
116 Assert.AreEqual (true, mc.NoConfig, "A13");
117 Assert.AreEqual (true, mc.NoLogo, "A14");
118 Assert.AreEqual (true, mc.Optimize, "A15");
119 Assert.AreEqual ("11", mc.OutputAssembly.ItemSpec, "A16");
120 Assert.AreEqual ("12", mc.References [0].ItemSpec, "A17");
121 Assert.AreEqual ("13", mc.Resources [0].ItemSpec, "A18");
122 Assert.AreEqual ("14", mc.ResponseFiles [0].ItemSpec, "A19");
123 Assert.AreEqual ("15", mc.Sources [0].ItemSpec, "A20");
124 Assert.AreEqual ("16", mc.TargetType, "A21");
125 Assert.AreEqual (true, mc.TreatWarningsAsErrors, "A22");
126 Assert.AreEqual (true, mc.Utf8Output, "A23");
127 Assert.AreEqual ("17", mc.Win32Icon, "A24");
128 Assert.AreEqual ("18", mc.Win32Resource, "A25");
132 public void TestDefaultValues ()
134 MCExtended mc = new MCExtended ();
136 Assert.IsNull (mc.AdditionalLibPaths, "A1");
137 Assert.IsNull (mc.AddModules, "A2");
138 Assert.AreEqual (0, mc.CodePage, "A3");
139 Assert.IsNull (mc.DebugType, "A4");
140 Assert.IsNull (mc.DefineConstants, "A5");
141 Assert.IsFalse (mc.DelaySign, "A6");
142 Assert.IsFalse (mc.EmitDebugInformation, "A7");
143 Assert.AreEqual (0, mc.FileAlignment, "A8");
144 Assert.IsNull (mc.KeyContainer, "A9");
145 Assert.IsNull (mc.KeyFile, "A10");
146 Assert.IsNull (mc.LinkResources, "A11");
147 Assert.IsNull (mc.MainEntryPoint, "A12");
148 Assert.IsFalse (mc.NoConfig, "A13");
149 Assert.IsFalse (mc.NoLogo, "A14");
150 Assert.IsFalse (mc.Optimize, "A15");
151 Assert.IsNull (mc.OutputAssembly, "A16");
152 Assert.IsNull (mc.References, "A17");
153 Assert.IsNull (mc.Resources, "A18");
154 Assert.IsNull (mc.ResponseFiles, "A19");
155 Assert.IsNull (mc.Sources, "A20");
156 Assert.IsNull (mc.TargetType, "A21");
157 Assert.IsFalse (mc.TreatWarningsAsErrors, "A22");
158 Assert.IsFalse (mc.Utf8Output, "A23");
159 Assert.IsNull (mc.Win32Icon, "A24");
160 Assert.IsNull (mc.Win32Resource, "A25");
164 [Category ("NotWorking")]
165 public void TestAdditionalLibPaths ()
167 MCExtended mc = new MCExtended ();
168 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
169 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
171 mc.AdditionalLibPaths = new string [2] { "A", "B" };
175 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
176 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
180 public void TestAddModules ()
182 MCExtended mc = new MCExtended ();
183 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
184 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
186 mc.AddModules = new string [2] { "A", "B" };
190 Assert.AreEqual ("/addmodule:A,B", c1.ToString (), "A1");
191 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
195 public void TestCodePage1 ()
197 MCExtended mc = new MCExtended ();
198 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
199 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
205 Assert.AreEqual ("/codepage:1111", c1.ToString (), "A1");
206 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
210 public void TestCodePage2 ()
212 MCExtended mc = new MCExtended ();
213 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
214 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
219 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
220 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
224 public void TestDebugType ()
226 MCExtended mc = new MCExtended ();
227 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
228 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
234 Assert.AreEqual ("/debug:A", c1.ToString (), "A1");
235 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
239 [Category ("NotWorking")]
240 public void TestDefineConstants ()
242 MCExtended mc = new MCExtended ();
243 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
244 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
246 mc.DefineConstants = "A;B";
250 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
251 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
255 public void TestDelaySign1 ()
257 MCExtended mc = new MCExtended ();
258 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
259 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
265 Assert.AreEqual ("/delaysign+", c1.ToString (), "A1");
266 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
270 public void TestDelaySign2 ()
272 MCExtended mc = new MCExtended ();
273 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
274 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
276 mc.DelaySign = false;
280 Assert.AreEqual ("/delaysign-", c1.ToString (), "A1");
281 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
285 public void TestEmitDebugInformation1 ()
287 MCExtended mc = new MCExtended ();
288 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
289 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
291 mc.EmitDebugInformation = true;
295 Assert.AreEqual ("/debug+", c1.ToString (), "A1");
296 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
300 public void TestEmitDebugInformation2 ()
302 MCExtended mc = new MCExtended ();
303 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
304 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
306 mc.EmitDebugInformation = false;
310 Assert.AreEqual ("/debug-", c1.ToString (), "A1");
311 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
315 [Category ("NotWorking")]
316 public void TestFileAlignment1 ()
318 MCExtended mc = new MCExtended ();
319 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
320 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
322 mc.FileAlignment = 100;
326 Assert.AreEqual ("/filealign:100", c1.ToString (), "A1");
327 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
331 public void TestFileAlignment2 ()
333 MCExtended mc = new MCExtended ();
334 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
335 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
340 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
341 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
345 public void TestKeyContainer ()
347 MCExtended mc = new MCExtended ();
348 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
349 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
351 mc.KeyContainer = "A";
355 Assert.AreEqual ("/keycontainer:A", c1.ToString (), "A1");
356 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
360 public void TestKeyFile ()
362 MCExtended mc = new MCExtended ();
363 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
364 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
370 Assert.AreEqual ("/keyfile:A", c1.ToString (), "A1");
371 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
375 public void TestLinkResources ()
377 MCExtended mc = new MCExtended ();
378 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
379 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
381 mc.LinkResources = new ITaskItem [2] { new TaskItem ("A"), new TaskItem ("B") };
385 Assert.AreEqual ("/linkresource:A /linkresource:B", c1.ToString (), "A1");
386 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
390 [Category ("NotWorking")]
391 public void TestMainEntryPoint ()
393 MCExtended mc = new MCExtended ();
394 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
395 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
397 mc.MainEntryPoint = "A";
401 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
402 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
406 public void TestNoConfig1 ()
408 MCExtended mc = new MCExtended ();
409 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
410 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
416 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
417 Assert.AreEqual ("/noconfig", c2.ToString (), "A2");
421 public void TestNoConfig2 ()
423 MCExtended mc = new MCExtended ();
424 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
425 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
431 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
432 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
436 public void TestNoLogo1 ()
438 MCExtended mc = new MCExtended ();
439 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
440 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
446 Assert.AreEqual ("/nologo", c1.ToString (), "A1");
447 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
451 public void TestNoLogo2 ()
453 MCExtended mc = new MCExtended ();
454 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
455 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
461 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
462 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
466 public void TestOptimize1 ()
468 MCExtended mc = new MCExtended ();
469 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
470 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
476 Assert.AreEqual ("/optimize+", c1.ToString (), "A1");
477 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
481 public void TestOptimize2 ()
483 MCExtended mc = new MCExtended ();
484 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
485 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
491 Assert.AreEqual ("/optimize-", c1.ToString (), "A1");
492 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
496 public void TestOutputAssembly ()
498 MCExtended mc = new MCExtended ();
499 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
500 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
502 mc.OutputAssembly = new TaskItem ("A");
506 Assert.AreEqual ("/out:A", c1.ToString (), "A1");
507 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
511 [Category ("NotWorking")]
512 public void TestReferences ()
514 MCExtended mc = new MCExtended ();
515 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
516 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
518 mc.References = new ITaskItem [2] { new TaskItem ("A"), new TaskItem ("B") };
522 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
523 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
527 public void TestResources ()
529 MCExtended mc = new MCExtended ();
530 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
531 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
533 mc.Resources = new ITaskItem [2] { new TaskItem ("A"), new TaskItem ("B") };
537 Assert.AreEqual ("/resource:A /resource:B", c1.ToString (), "A1");
538 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
542 [Category ("NotWorking")]
543 public void TestResponseFiles ()
545 MCExtended mc = new MCExtended ();
546 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
547 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
549 mc.ResponseFiles = new ITaskItem [2] { new TaskItem ("A"), new TaskItem ("B") };
553 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
554 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
558 public void TestSources ()
560 MCExtended mc = new MCExtended ();
561 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
562 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
564 mc.Sources = new ITaskItem [2] { new TaskItem ("A"), new TaskItem ("B") };
568 Assert.AreEqual ("/out:A.exe A B", c1.ToString (), "A1");
569 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
573 public void TestTargetType ()
575 MCExtended mc = new MCExtended ();
576 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
577 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
583 Assert.AreEqual ("/target:a", c1.ToString (), "A1");
584 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
588 public void TestTreatWarningsAsErrors1 ()
590 MCExtended mc = new MCExtended ();
591 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
592 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
594 mc.TreatWarningsAsErrors = true;
598 Assert.AreEqual ("/warnaserror+", c1.ToString (), "A1");
599 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
603 public void TestTreatWarningsAsErrors2 ()
605 MCExtended mc = new MCExtended ();
606 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
607 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
609 mc.TreatWarningsAsErrors = false;
613 Assert.AreEqual ("/warnaserror-", c1.ToString (), "A1");
614 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
618 [Category ("NotWorking")]
619 public void TestUtf8Output1 ()
621 MCExtended mc = new MCExtended ();
622 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
623 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
625 mc.Utf8Output = true;
629 Assert.AreEqual ("/utf8output", c1.ToString (), "A1");
630 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
634 public void TestUtf8Output2 ()
636 MCExtended mc = new MCExtended ();
637 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
638 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
640 mc.Utf8Output = false;
644 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
645 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
649 public void TestWin32Icon ()
651 MCExtended mc = new MCExtended ();
652 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
653 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
659 Assert.AreEqual ("/win32icon:A", c1.ToString (), "A1");
660 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
664 [Category ("NotWorking")]
665 public void TestWin32Resource ()
667 MCExtended mc = new MCExtended ();
668 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
669 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
671 mc.Win32Resource = "A;B";
675 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
676 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
680 public void TestCheckAllReferencesExistOnDisk1 ()
682 MCExtended mc = new MCExtended ();
683 mc.BuildEngine = new TestEngine ();
685 mc.References = new ITaskItem [0];
686 Assert.IsTrue (mc.CheckAllReferencesExistOnDisk (), "A1");
688 mc.References = null;
689 Assert.IsTrue (mc.CheckAllReferencesExistOnDisk (), "A2");
691 mc.References = new ITaskItem [1] { new TaskItem (@"Test\resources\test.cs") };
692 Assert.IsTrue (mc.CheckAllReferencesExistOnDisk (), "A3");
694 mc.References = new ITaskItem [2] { new TaskItem (@"Test\resources\test.cs"), new TaskItem ("X") };
695 Assert.IsFalse (mc.CheckAllReferencesExistOnDisk (), "A4");