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.Framework;
31 using Microsoft.Build.Utilities;
32 using Microsoft.Build.Tasks;
33 using NUnit.Framework;
35 namespace MonoTests.Microsoft.Build.Tasks {
37 class CscExtended : Csc {
43 public void ARFC (CommandLineBuilderExtension commandLine)
45 base.AddResponseFileCommands (commandLine);
48 public void ACLC (CommandLineBuilderExtension commandLine)
50 base.AddCommandLineCommands (commandLine);
55 public class CscTest {
57 public void TestAssignment ()
61 csc.AllowUnsafeBlocks = true;
62 csc.BaseAddress = "1";
63 csc.CheckForOverflowUnderflow = true;
64 csc.DisabledWarnings = "2";
65 csc.DocumentationFile = "3";
66 csc.ErrorReport = "4";
67 csc.GenerateFullPaths = true;
68 csc.LangVersion = "5";
69 csc.ModuleAssemblyName = "6";
70 csc.NoStandardLib = true;
73 csc.UseHostCompilerIfAvailable = true;
75 csc.WarningsAsErrors = "10";
76 csc.WarningsNotAsErrors = "11";
78 Assert.AreEqual (true, csc.AllowUnsafeBlocks, "A1");
79 Assert.AreEqual ("1", csc.BaseAddress, "A2");
80 Assert.AreEqual (true, csc.CheckForOverflowUnderflow, "A3");
81 Assert.AreEqual ("2", csc.DisabledWarnings, "A4");
82 Assert.AreEqual ("3", csc.DocumentationFile, "A5");
83 Assert.AreEqual ("4", csc.ErrorReport, "A6");
84 Assert.AreEqual (true, csc.GenerateFullPaths, "A7");
85 Assert.AreEqual ("5", csc.LangVersion, "A8");
86 Assert.AreEqual ("6", csc.ModuleAssemblyName, "A9");
87 Assert.AreEqual ("7", csc.PdbFile, "A10");
88 Assert.AreEqual ("8", csc.Platform, "A11");
89 Assert.AreEqual (true, csc.UseHostCompilerIfAvailable, "A12");
90 Assert.AreEqual (9, csc.WarningLevel, "A13");
91 Assert.AreEqual ("10", csc.WarningsAsErrors, "A14");
92 Assert.AreEqual ("11", csc.WarningsNotAsErrors, "A15");
96 public void TestDefaultValues ()
100 Assert.IsFalse (csc.AllowUnsafeBlocks, "A1");
101 Assert.IsNull (csc.BaseAddress, "A2");
102 Assert.IsFalse (csc.CheckForOverflowUnderflow, "A3");
103 Assert.IsNull (csc.DisabledWarnings, "A4");
104 Assert.IsNull (csc.DocumentationFile, "A5");
105 Assert.IsNull (csc.ErrorReport, "A6");
106 Assert.IsFalse (csc.GenerateFullPaths, "A7");
107 Assert.IsNull (csc.LangVersion, "A8");
108 Assert.IsNull (csc.ModuleAssemblyName, "A9");
109 Assert.IsNull (csc.PdbFile, "A10");
110 Assert.IsNull (csc.Platform, "A11");
111 Assert.IsFalse (csc.UseHostCompilerIfAvailable, "A12");
112 Assert.AreEqual (4, csc.WarningLevel, "A13");
113 Assert.IsNull (csc.WarningsAsErrors, "A14");
114 Assert.IsNull (csc.WarningsNotAsErrors, "A15");
117 #region CscSpecificVariables
120 public void TestAllowUnsafeBlocks1 ()
122 CscExtended csc = new CscExtended ();
123 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
125 csc.AllowUnsafeBlocks = true;
128 Assert.AreEqual ("/unsafe+", clbe.ToString (), "A1");
132 public void TestAllowUnsafeBlocks2 ()
134 CscExtended csc = new CscExtended ();
135 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
137 csc.AllowUnsafeBlocks = false;
140 Assert.AreEqual ("/unsafe-", clbe.ToString (), "A1");
144 [Category ("NotWorking")]
145 public void TestBaseAddress ()
147 CscExtended csc = new CscExtended ();
148 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
150 csc.BaseAddress = "A";
153 Assert.AreEqual ("/baseaddress:A", clbe.ToString (), "A1");
157 public void TestCheckForOverflowUnderflow1 ()
159 CscExtended csc = new CscExtended ();
160 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
162 csc.CheckForOverflowUnderflow = true;
165 Assert.AreEqual ("/checked+", clbe.ToString (), "A1");
169 public void TestCheckForOverflowUnderflow2 ()
171 CscExtended csc = new CscExtended ();
172 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
174 csc.CheckForOverflowUnderflow = false;
177 Assert.AreEqual ("/checked-", clbe.ToString (), "A1");
181 public void TestDisabledWarnings ()
183 CscExtended csc = new CscExtended ();
184 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
186 csc.DisabledWarnings = "A";
189 Assert.AreEqual ("/nowarn:A", clbe.ToString (), "A1");
193 public void TestDisabledWarningsComma ()
195 CscExtended csc = new CscExtended ();
196 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
198 csc.DisabledWarnings = "A, B";
201 Assert.AreEqual ("/nowarn:A;B", clbe.ToString (), "A1");
205 public void TestDocumentationFile ()
207 CscExtended csc = new CscExtended ();
208 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
210 csc.DocumentationFile = "A";
213 Assert.AreEqual ("/doc:A", clbe.ToString (), "A1");
217 [Category ("NotWorking")]
218 public void TestErrorReport ()
220 CscExtended csc = new CscExtended ();
221 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
223 csc.ErrorReport = "A";
226 Assert.AreEqual ("/errorreport:A", clbe.ToString (), "A1");
230 public void TestGenerateFullPaths1 ()
232 CscExtended csc = new CscExtended ();
233 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
235 csc.GenerateFullPaths = true;
238 Assert.AreEqual ("/fullpaths", clbe.ToString (), "A1");
242 public void TestGenerateFullPaths2 ()
244 CscExtended csc = new CscExtended ();
245 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
247 csc.GenerateFullPaths = false;
250 Assert.AreEqual ("", clbe.ToString (), "A1");
254 public void TestLangVersion ()
256 CscExtended csc = new CscExtended ();
257 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
259 csc.LangVersion = "A'B";
262 Assert.AreEqual ("/langversion:\"A'B\"", clbe.ToString (), "A1");
266 [Category ("NotWorking")]
267 public void TestModuleAssemblyName ()
269 CscExtended csc = new CscExtended ();
270 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
272 csc.ModuleAssemblyName = "A'B";
275 Assert.AreEqual ("/moduleassemblyname:\"A'B\"", clbe.ToString (), "A1");
279 [Category ("NotWorking")]
280 public void TestPdbFile ()
282 CscExtended csc = new CscExtended ();
283 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
288 Assert.AreEqual ("/pdb:A", clbe.ToString (), "A1");
292 [Category ("NotWorking")]
293 public void TestPlatform ()
295 CscExtended csc = new CscExtended ();
296 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
301 Assert.AreEqual ("/platform:A", clbe.ToString (), "A1");
305 public void TestWarning ()
307 CscExtended csc = new CscExtended ();
308 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
310 csc.WarningLevel = 4;
313 Assert.AreEqual ("/warn:4", clbe.ToString (), "A1");
317 public void TestWarningAsErrors ()
319 CscExtended csc = new CscExtended ();
320 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
322 csc.WarningsAsErrors = "A'B";
325 Assert.AreEqual ("/warnaserror+:\"A'B\"", clbe.ToString (), "A1");
328 public void TestWarningNotAsErrors ()
330 CscExtended csc = new CscExtended ();
331 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
333 csc.WarningsNotAsErrors = "A'B";
336 Assert.AreEqual ("/warnaserror-:\"A'B\"", clbe.ToString (), "A1");
342 public void TestAdditionalLibPaths ()
344 CscExtended csc = new CscExtended ();
345 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
346 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
348 csc.AdditionalLibPaths = new string [2] { "A'Foo", "B" };
352 Assert.AreEqual ("/lib:\"A'Foo\",B", c1.ToString (), "A1");
353 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
356 // Behavior for this intentionally differs from .net .
357 // msbuild doesn't quote the define args, but we do
358 // that to make it easier to copy/paste and execute
359 // compiler command lines, helps in debugging.
360 [Category ("NotDotNet")]
362 public void TestDefineConstants ()
364 CscExtended csc = new CscExtended ();
365 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
366 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
368 csc.DefineConstants = "A;B;;CD;;;Foo Bar";
372 Assert.AreEqual ("/define:\"A;B;CD;Foo;Bar\"", c1.ToString (), "A1");
373 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
377 public void TestDefineConstants2 ()
379 CscExtended csc = new CscExtended ();
380 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
381 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
383 csc.DefineConstants = ";;;";
387 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
388 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
392 public void TestMainEntryPoint ()
394 CscExtended csc = new CscExtended ();
395 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
396 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
398 csc.MainEntryPoint = "A;B";
402 Assert.AreEqual ("/main:\"A;B\"", c1.ToString (), "A1");
403 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
407 public void TestReferences ()
409 CscExtended csc = new CscExtended ();
410 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
411 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
413 csc.References = new ITaskItem [2] { new TaskItem ("A;C"), new TaskItem ("B") };
417 Assert.AreEqual ("/reference:\"A;C\" /reference:B", c1.ToString (), "A1");
418 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
422 public void TestResponseFiles ()
424 CscExtended csc = new CscExtended ();
425 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
426 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
428 csc.ResponseFiles = new ITaskItem [2] { new TaskItem ("A\'Foo"), new TaskItem ("B") };
432 Assert.AreEqual ("@\"A'Foo\" @B", c1.ToString (), "A1");
433 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
437 public void TestWin32Resource ()
439 CscExtended csc = new CscExtended ();
440 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
441 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
443 csc.Win32Resource = "A;B";
447 Assert.AreEqual ("/win32res:\"A;B\"", c1.ToString (), "A1");
448 Assert.AreEqual (String.Empty, c2.ToString (), "A2");