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.
30 using System.Collections;
31 using Microsoft.Build.BuildEngine;
32 using Microsoft.Build.Framework;
33 using Microsoft.Build.Tasks;
34 using Microsoft.Build.Utilities;
35 using NUnit.Framework;
37 namespace MonoTests.Microsoft.Build.Tasks {
39 class MCExtended : ManagedCompiler {
45 public void ARFC (CommandLineBuilderExtension commandLine)
47 base.AddResponseFileCommands (commandLine);
50 public void ACLC (CommandLineBuilderExtension commandLine)
52 base.AddCommandLineCommands (commandLine);
55 public new bool CheckAllReferencesExistOnDisk ()
57 return base.CheckAllReferencesExistOnDisk ();
61 protected override string ToolName {
62 get { return "something"; }
65 protected override string GenerateFullPathToTool ()
72 public class ManagedCompilerTest {
75 public void TestAssignment ()
77 MCExtended mc = new MCExtended ();
79 mc.AdditionalLibPaths = new string [1] { "1" };
80 mc.AddModules = new string [1] { "2" };
83 mc.DefineConstants = "5";
85 mc.EmitDebugInformation = true;
87 mc.KeyContainer = "7";
89 mc.LinkResources = new ITaskItem [1] { new TaskItem ("9") };
90 mc.MainEntryPoint = "10";
94 mc.OutputAssembly = new TaskItem ("11");
95 mc.References = new ITaskItem [1] { new TaskItem ("12") };
96 mc.Resources = new ITaskItem [1] { new TaskItem ("13") };
97 mc.ResponseFiles = new ITaskItem [1] { new TaskItem ("14") };
98 mc.Sources = new ITaskItem [1] { new TaskItem ("15") };
100 mc.TreatWarningsAsErrors = true;
101 mc.Utf8Output = true;
103 mc.Win32Resource = "18";
105 Assert.AreEqual ("1", mc.AdditionalLibPaths [0], "A1");
106 Assert.AreEqual ("2", mc.AddModules [0], "A2");
107 Assert.AreEqual (3, mc.CodePage, "A3");
108 Assert.AreEqual ("4", mc.DebugType, "A4");
109 Assert.AreEqual ("5", mc.DefineConstants, "A5");
110 Assert.AreEqual (true, mc.DelaySign, "A6");
111 Assert.AreEqual (true, mc.EmitDebugInformation, "A7");
112 Assert.AreEqual (6, mc.FileAlignment, "A8");
113 Assert.AreEqual ("7", mc.KeyContainer, "A9");
114 Assert.AreEqual ("8", mc.KeyFile, "A10");
115 Assert.AreEqual ("9", mc.LinkResources [0].ItemSpec, "A11");
116 Assert.AreEqual ("10", mc.MainEntryPoint, "A12");
117 Assert.AreEqual (true, mc.NoConfig, "A13");
118 Assert.AreEqual (true, mc.NoLogo, "A14");
119 Assert.AreEqual (true, mc.Optimize, "A15");
120 Assert.AreEqual ("11", mc.OutputAssembly.ItemSpec, "A16");
121 Assert.AreEqual ("12", mc.References [0].ItemSpec, "A17");
122 Assert.AreEqual ("13", mc.Resources [0].ItemSpec, "A18");
123 Assert.AreEqual ("14", mc.ResponseFiles [0].ItemSpec, "A19");
124 Assert.AreEqual ("15", mc.Sources [0].ItemSpec, "A20");
125 Assert.AreEqual ("16", mc.TargetType, "A21");
126 Assert.AreEqual (true, mc.TreatWarningsAsErrors, "A22");
127 Assert.AreEqual (true, mc.Utf8Output, "A23");
128 Assert.AreEqual ("17", mc.Win32Icon, "A24");
129 Assert.AreEqual ("18", mc.Win32Resource, "A25");
133 public void TestDefaultValues ()
135 MCExtended mc = new MCExtended ();
137 Assert.IsNull (mc.AdditionalLibPaths, "A1");
138 Assert.IsNull (mc.AddModules, "A2");
139 Assert.AreEqual (0, mc.CodePage, "A3");
140 Assert.IsNull (mc.DebugType, "A4");
141 Assert.IsNull (mc.DefineConstants, "A5");
142 Assert.IsFalse (mc.DelaySign, "A6");
143 Assert.IsFalse (mc.EmitDebugInformation, "A7");
144 Assert.AreEqual (0, mc.FileAlignment, "A8");
145 Assert.IsNull (mc.KeyContainer, "A9");
146 Assert.IsNull (mc.KeyFile, "A10");
147 Assert.IsNull (mc.LinkResources, "A11");
148 Assert.IsNull (mc.MainEntryPoint, "A12");
149 Assert.IsFalse (mc.NoConfig, "A13");
150 Assert.IsFalse (mc.NoLogo, "A14");
151 Assert.IsFalse (mc.Optimize, "A15");
152 Assert.IsNull (mc.OutputAssembly, "A16");
153 Assert.IsNull (mc.References, "A17");
154 Assert.IsNull (mc.Resources, "A18");
155 Assert.IsNull (mc.ResponseFiles, "A19");
156 Assert.IsNull (mc.Sources, "A20");
157 Assert.IsNull (mc.TargetType, "A21");
158 Assert.IsFalse (mc.TreatWarningsAsErrors, "A22");
159 Assert.IsFalse (mc.Utf8Output, "A23");
160 Assert.IsNull (mc.Win32Icon, "A24");
161 Assert.IsNull (mc.Win32Resource, "A25");
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 public void TestDefineConstants ()
241 MCExtended mc = new MCExtended ();
242 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
243 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
245 mc.DefineConstants = "A;B";
249 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
250 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
254 public void TestDelaySign1 ()
256 MCExtended mc = new MCExtended ();
257 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
258 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
264 Assert.AreEqual ("/delaysign+", c1.ToString (), "A1");
265 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
269 public void TestDelaySign2 ()
271 MCExtended mc = new MCExtended ();
272 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
273 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
275 mc.DelaySign = false;
279 Assert.AreEqual ("/delaysign-", c1.ToString (), "A1");
280 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
284 public void TestEmitDebugInformation1 ()
286 MCExtended mc = new MCExtended ();
287 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
288 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
290 mc.EmitDebugInformation = true;
294 Assert.AreEqual ("/debug+", c1.ToString (), "A1");
295 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
299 public void TestEmitDebugInformation2 ()
301 MCExtended mc = new MCExtended ();
302 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
303 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
305 mc.EmitDebugInformation = false;
309 Assert.AreEqual ("/debug-", c1.ToString (), "A1");
310 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
314 [Category ("NotWorking")]
315 public void TestFileAlignment1 ()
317 MCExtended mc = new MCExtended ();
318 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
319 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
321 mc.FileAlignment = 100;
325 Assert.AreEqual ("/filealign:100", c1.ToString (), "A1");
326 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
330 public void TestFileAlignment2 ()
332 MCExtended mc = new MCExtended ();
333 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
334 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
339 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
340 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
344 public void TestKeyContainer ()
346 MCExtended mc = new MCExtended ();
347 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
348 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
350 mc.KeyContainer = "A";
354 Assert.AreEqual ("/keycontainer:A", c1.ToString (), "A1");
355 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
359 public void TestKeyFile ()
361 MCExtended mc = new MCExtended ();
362 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
363 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
369 Assert.AreEqual ("/keyfile:A", c1.ToString (), "A1");
370 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
374 public void TestLinkResources ()
376 MCExtended mc = new MCExtended ();
377 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
378 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
380 mc.LinkResources = new ITaskItem [2] { new TaskItem ("A"), new TaskItem ("B") };
384 Assert.AreEqual ("/linkresource:A /linkresource:B", c1.ToString (), "A1");
385 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
389 public void TestMainEntryPoint ()
391 MCExtended mc = new MCExtended ();
392 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
393 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
395 mc.MainEntryPoint = "A";
399 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
400 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
404 public void TestNoConfig1 ()
406 MCExtended mc = new MCExtended ();
407 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
408 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
414 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
415 Assert.AreEqual ("/noconfig", c2.ToString (), "A2");
419 public void TestNoConfig2 ()
421 MCExtended mc = new MCExtended ();
422 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
423 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
429 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
430 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
434 public void TestNoLogo1 ()
436 MCExtended mc = new MCExtended ();
437 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
438 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
444 Assert.AreEqual ("/nologo", c1.ToString (), "A1");
445 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
449 public void TestNoLogo2 ()
451 MCExtended mc = new MCExtended ();
452 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
453 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
459 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
460 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
464 public void TestOptimize1 ()
466 MCExtended mc = new MCExtended ();
467 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
468 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
474 Assert.AreEqual ("/optimize+", c1.ToString (), "A1");
475 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
479 public void TestOptimize2 ()
481 MCExtended mc = new MCExtended ();
482 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
483 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
489 Assert.AreEqual ("/optimize-", c1.ToString (), "A1");
490 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
494 public void TestOutputAssembly ()
496 MCExtended mc = new MCExtended ();
497 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
498 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
500 mc.OutputAssembly = new TaskItem ("A");
504 Assert.AreEqual ("/out:A", c1.ToString (), "A1");
505 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
509 public void TestReferences ()
511 MCExtended mc = new MCExtended ();
512 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
513 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
515 mc.References = new ITaskItem [2] { new TaskItem ("A"), new TaskItem ("B") };
519 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
520 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
524 public void TestResources ()
526 MCExtended mc = new MCExtended ();
527 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
528 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
530 mc.Resources = new ITaskItem [2] { new TaskItem ("A"), new TaskItem ("B") };
534 Assert.AreEqual ("/resource:A /resource:B", c1.ToString (), "A1");
535 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
539 public void TestResponseFiles ()
541 MCExtended mc = new MCExtended ();
542 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
543 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
545 mc.ResponseFiles = new ITaskItem [2] { new TaskItem ("A"), new TaskItem ("B") };
549 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
550 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
554 public void TestSources ()
556 MCExtended mc = new MCExtended ();
557 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
558 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
560 mc.Sources = new ITaskItem [2] { new TaskItem ("A"), new TaskItem ("B") };
564 Assert.AreEqual ("/out:A.exe A B", c1.ToString (), "A1");
565 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
569 public void TestTargetType ()
571 MCExtended mc = new MCExtended ();
572 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
573 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
579 Assert.AreEqual ("/target:a", c1.ToString (), "A1");
580 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
584 public void TestTreatWarningsAsErrors1 ()
586 MCExtended mc = new MCExtended ();
587 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
588 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
590 mc.TreatWarningsAsErrors = true;
594 Assert.AreEqual ("/warnaserror+", c1.ToString (), "A1");
595 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
599 public void TestTreatWarningsAsErrors2 ()
601 MCExtended mc = new MCExtended ();
602 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
603 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
605 mc.TreatWarningsAsErrors = false;
609 Assert.AreEqual ("/warnaserror-", c1.ToString (), "A1");
610 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
614 [Category ("NotWorking")]
615 public void TestUtf8Output1 ()
617 MCExtended mc = new MCExtended ();
618 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
619 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
621 mc.Utf8Output = true;
625 Assert.AreEqual ("/utf8output", c1.ToString (), "A1");
626 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
630 public void TestUtf8Output2 ()
632 MCExtended mc = new MCExtended ();
633 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
634 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
636 mc.Utf8Output = false;
640 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
641 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
645 public void TestWin32Icon ()
647 MCExtended mc = new MCExtended ();
648 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
649 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
655 Assert.AreEqual ("/win32icon:A", c1.ToString (), "A1");
656 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
660 public void TestWin32Resource ()
662 MCExtended mc = new MCExtended ();
663 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
664 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
666 mc.Win32Resource = "A;B";
670 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
671 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
675 public void TestCheckAllReferencesExistOnDisk1 ()
677 MCExtended mc = new MCExtended ();
678 mc.BuildEngine = new TestEngine ();
680 mc.References = new ITaskItem [0];
681 Assert.IsTrue (mc.CheckAllReferencesExistOnDisk (), "A1");
683 mc.References = null;
684 Assert.IsTrue (mc.CheckAllReferencesExistOnDisk (), "A2");
686 string path = Path.Combine (Path.Combine ("Test", "resources"), "test.cs");
687 mc.References = new ITaskItem [1] { new TaskItem (path) };
688 Assert.IsTrue (mc.CheckAllReferencesExistOnDisk (), "A3");
690 mc.References = new ITaskItem [2] { new TaskItem (path), new TaskItem ("X") };
691 Assert.IsFalse (mc.CheckAllReferencesExistOnDisk (), "A4");