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 public void TestAdditionalLibPaths ()
166 MCExtended mc = new MCExtended ();
167 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
168 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
170 mc.AdditionalLibPaths = new string [2] { "A", "B" };
174 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
175 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
179 public void TestAddModules ()
181 MCExtended mc = new MCExtended ();
182 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
183 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
185 mc.AddModules = new string [2] { "A", "B" };
189 Assert.AreEqual ("/addmodule:A,B", c1.ToString (), "A1");
190 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
194 public void TestCodePage1 ()
196 MCExtended mc = new MCExtended ();
197 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
198 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
204 Assert.AreEqual ("/codepage:1111", c1.ToString (), "A1");
205 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
209 public void TestCodePage2 ()
211 MCExtended mc = new MCExtended ();
212 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
213 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
218 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
219 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
223 public void TestDebugType ()
225 MCExtended mc = new MCExtended ();
226 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
227 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
233 Assert.AreEqual ("/debug:A", c1.ToString (), "A1");
234 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
238 public void TestDefineConstants ()
240 MCExtended mc = new MCExtended ();
241 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
242 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
244 mc.DefineConstants = "A;B";
248 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
249 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
253 public void TestDelaySign1 ()
255 MCExtended mc = new MCExtended ();
256 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
257 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
263 Assert.AreEqual ("/delaysign+", c1.ToString (), "A1");
264 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
268 public void TestDelaySign2 ()
270 MCExtended mc = new MCExtended ();
271 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
272 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
274 mc.DelaySign = false;
278 Assert.AreEqual ("/delaysign-", c1.ToString (), "A1");
279 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
283 public void TestEmitDebugInformation1 ()
285 MCExtended mc = new MCExtended ();
286 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
287 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
289 mc.EmitDebugInformation = true;
293 Assert.AreEqual ("/debug+", c1.ToString (), "A1");
294 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
298 public void TestEmitDebugInformation2 ()
300 MCExtended mc = new MCExtended ();
301 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
302 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
304 mc.EmitDebugInformation = false;
308 Assert.AreEqual ("/debug-", c1.ToString (), "A1");
309 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
313 [Category ("NotWorking")]
314 public void TestFileAlignment1 ()
316 MCExtended mc = new MCExtended ();
317 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
318 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
320 mc.FileAlignment = 100;
324 Assert.AreEqual ("/filealign:100", c1.ToString (), "A1");
325 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
329 public void TestFileAlignment2 ()
331 MCExtended mc = new MCExtended ();
332 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
333 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
338 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
339 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
343 public void TestKeyContainer ()
345 MCExtended mc = new MCExtended ();
346 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
347 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
349 mc.KeyContainer = "A";
353 Assert.AreEqual ("/keycontainer:A", c1.ToString (), "A1");
354 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
358 public void TestKeyFile ()
360 MCExtended mc = new MCExtended ();
361 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
362 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
368 Assert.AreEqual ("/keyfile:A", c1.ToString (), "A1");
369 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
373 public void TestLinkResources ()
375 MCExtended mc = new MCExtended ();
376 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
377 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
379 mc.LinkResources = new ITaskItem [2] { new TaskItem ("A"), new TaskItem ("B") };
383 Assert.AreEqual ("/linkresource:A /linkresource:B", c1.ToString (), "A1");
384 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
388 public void TestMainEntryPoint ()
390 MCExtended mc = new MCExtended ();
391 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
392 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
394 mc.MainEntryPoint = "A";
398 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
399 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
403 public void TestNoConfig1 ()
405 MCExtended mc = new MCExtended ();
406 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
407 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
413 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
414 Assert.AreEqual ("/noconfig", c2.ToString (), "A2");
418 public void TestNoConfig2 ()
420 MCExtended mc = new MCExtended ();
421 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
422 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
428 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
429 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
433 public void TestNoLogo1 ()
435 MCExtended mc = new MCExtended ();
436 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
437 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
443 Assert.AreEqual ("/nologo", c1.ToString (), "A1");
444 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
448 public void TestNoLogo2 ()
450 MCExtended mc = new MCExtended ();
451 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
452 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
458 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
459 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
463 public void TestOptimize1 ()
465 MCExtended mc = new MCExtended ();
466 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
467 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
473 Assert.AreEqual ("/optimize+", c1.ToString (), "A1");
474 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
478 public void TestOptimize2 ()
480 MCExtended mc = new MCExtended ();
481 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
482 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
488 Assert.AreEqual ("/optimize-", c1.ToString (), "A1");
489 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
493 public void TestOutputAssembly ()
495 MCExtended mc = new MCExtended ();
496 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
497 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
499 mc.OutputAssembly = new TaskItem ("A");
503 Assert.AreEqual ("/out:A", c1.ToString (), "A1");
504 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
508 public void TestReferences ()
510 MCExtended mc = new MCExtended ();
511 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
512 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
514 mc.References = new ITaskItem [2] { new TaskItem ("A"), new TaskItem ("B") };
518 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
519 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
523 public void TestResources ()
525 MCExtended mc = new MCExtended ();
526 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
527 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
529 mc.Resources = new ITaskItem [2] { new TaskItem ("A"), new TaskItem ("B") };
533 Assert.AreEqual ("/resource:A /resource:B", c1.ToString (), "A1");
534 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
538 public void TestResponseFiles ()
540 MCExtended mc = new MCExtended ();
541 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
542 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
544 mc.ResponseFiles = new ITaskItem [2] { new TaskItem ("A"), new TaskItem ("B") };
548 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
549 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
553 public void TestSources ()
555 MCExtended mc = new MCExtended ();
556 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
557 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
559 mc.Sources = new ITaskItem [2] { new TaskItem ("A"), new TaskItem ("B") };
563 Assert.AreEqual ("/out:A.exe A B", c1.ToString (), "A1");
564 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
568 public void TestTargetType ()
570 MCExtended mc = new MCExtended ();
571 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
572 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
578 Assert.AreEqual ("/target:a", c1.ToString (), "A1");
579 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
583 public void TestTreatWarningsAsErrors1 ()
585 MCExtended mc = new MCExtended ();
586 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
587 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
589 mc.TreatWarningsAsErrors = true;
593 Assert.AreEqual ("/warnaserror+", c1.ToString (), "A1");
594 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
598 public void TestTreatWarningsAsErrors2 ()
600 MCExtended mc = new MCExtended ();
601 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
602 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
604 mc.TreatWarningsAsErrors = false;
608 Assert.AreEqual ("/warnaserror-", c1.ToString (), "A1");
609 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
613 [Category ("NotWorking")]
614 public void TestUtf8Output1 ()
616 MCExtended mc = new MCExtended ();
617 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
618 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
620 mc.Utf8Output = true;
624 Assert.AreEqual ("/utf8output", c1.ToString (), "A1");
625 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
629 public void TestUtf8Output2 ()
631 MCExtended mc = new MCExtended ();
632 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
633 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
635 mc.Utf8Output = false;
639 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
640 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
644 public void TestWin32Icon ()
646 MCExtended mc = new MCExtended ();
647 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
648 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
654 Assert.AreEqual ("/win32icon:A", c1.ToString (), "A1");
655 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
659 public void TestWin32Resource ()
661 MCExtended mc = new MCExtended ();
662 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
663 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
665 mc.Win32Resource = "A;B";
669 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
670 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
674 public void TestCheckAllReferencesExistOnDisk1 ()
676 MCExtended mc = new MCExtended ();
677 mc.BuildEngine = new TestEngine ();
679 mc.References = new ITaskItem [0];
680 Assert.IsTrue (mc.CheckAllReferencesExistOnDisk (), "A1");
682 mc.References = null;
683 Assert.IsTrue (mc.CheckAllReferencesExistOnDisk (), "A2");
685 mc.References = new ITaskItem [1] { new TaskItem (@"Test\resources\test.cs") };
686 Assert.IsTrue (mc.CheckAllReferencesExistOnDisk (), "A3");
688 mc.References = new ITaskItem [2] { new TaskItem (@"Test\resources\test.cs"), new TaskItem ("X") };
689 Assert.IsFalse (mc.CheckAllReferencesExistOnDisk (), "A4");