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.Reflection;
30 using System.Collections;
31 using Microsoft.Build.Framework;
32 using Microsoft.Build.Utilities;
33 using Microsoft.Build.Tasks;
34 using NUnit.Framework;
36 namespace MonoTests.Microsoft.Build.Tasks {
38 class CscExtended : Csc {
44 public void ARFC (CommandLineBuilderExtension commandLine)
46 base.AddResponseFileCommands (commandLine);
48 string s = commandLine.ToString ();
50 Assert.AreEqual ("/sdk:2", s);
52 Assert.AreEqual ("/sdk:2 ", s.Substring (0, 7));
54 BindingFlags flags = BindingFlags.Instance | BindingFlags.NonPublic;
55 PropertyInfo pi = typeof (CommandLineBuilderExtension).GetProperty ("CommandLine", flags);
56 System.Text.StringBuilder sb = (System.Text.StringBuilder) pi.GetValue (commandLine, null);
59 sb.Append (s.Substring (7));
63 public void ACLC (CommandLineBuilderExtension commandLine)
65 base.AddCommandLineCommands (commandLine);
70 public class CscTest {
72 public void TestAssignment ()
76 csc.AllowUnsafeBlocks = true;
77 csc.BaseAddress = "1";
78 csc.CheckForOverflowUnderflow = true;
79 csc.DisabledWarnings = "2";
80 csc.DocumentationFile = "3";
81 csc.ErrorReport = "4";
82 csc.GenerateFullPaths = true;
83 csc.LangVersion = "5";
84 csc.ModuleAssemblyName = "6";
85 csc.NoStandardLib = true;
88 csc.UseHostCompilerIfAvailable = true;
90 csc.WarningsAsErrors = "10";
91 csc.WarningsNotAsErrors = "11";
93 Assert.AreEqual (true, csc.AllowUnsafeBlocks, "A1");
94 Assert.AreEqual ("1", csc.BaseAddress, "A2");
95 Assert.AreEqual (true, csc.CheckForOverflowUnderflow, "A3");
96 Assert.AreEqual ("2", csc.DisabledWarnings, "A4");
97 Assert.AreEqual ("3", csc.DocumentationFile, "A5");
98 Assert.AreEqual ("4", csc.ErrorReport, "A6");
99 Assert.AreEqual (true, csc.GenerateFullPaths, "A7");
100 Assert.AreEqual ("5", csc.LangVersion, "A8");
101 Assert.AreEqual ("6", csc.ModuleAssemblyName, "A9");
102 Assert.AreEqual ("7", csc.PdbFile, "A10");
103 Assert.AreEqual ("8", csc.Platform, "A11");
104 Assert.AreEqual (true, csc.UseHostCompilerIfAvailable, "A12");
105 Assert.AreEqual (9, csc.WarningLevel, "A13");
106 Assert.AreEqual ("10", csc.WarningsAsErrors, "A14");
107 Assert.AreEqual ("11", csc.WarningsNotAsErrors, "A15");
111 public void TestDefaultValues ()
113 Csc csc = new Csc ();
115 Assert.IsFalse (csc.AllowUnsafeBlocks, "A1");
116 Assert.IsNull (csc.BaseAddress, "A2");
117 Assert.IsFalse (csc.CheckForOverflowUnderflow, "A3");
118 Assert.IsNull (csc.DisabledWarnings, "A4");
119 Assert.IsNull (csc.DocumentationFile, "A5");
120 Assert.IsNull (csc.ErrorReport, "A6");
121 Assert.IsFalse (csc.GenerateFullPaths, "A7");
122 Assert.IsNull (csc.LangVersion, "A8");
123 Assert.IsNull (csc.ModuleAssemblyName, "A9");
124 Assert.IsNull (csc.PdbFile, "A10");
125 Assert.IsNull (csc.Platform, "A11");
126 Assert.IsFalse (csc.UseHostCompilerIfAvailable, "A12");
127 Assert.AreEqual (4, csc.WarningLevel, "A13");
128 Assert.IsNull (csc.WarningsAsErrors, "A14");
129 Assert.IsNull (csc.WarningsNotAsErrors, "A15");
132 #region CscSpecificVariables
135 public void TestAllowUnsafeBlocks1 ()
137 CscExtended csc = new CscExtended ();
138 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
140 csc.AllowUnsafeBlocks = true;
143 Assert.AreEqual ("/unsafe+", clbe.ToString (), "A1");
147 public void TestAllowUnsafeBlocks2 ()
149 CscExtended csc = new CscExtended ();
150 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
152 csc.AllowUnsafeBlocks = false;
155 Assert.AreEqual ("/unsafe-", clbe.ToString (), "A1");
159 [Category ("NotWorking")]
160 public void TestBaseAddress ()
162 CscExtended csc = new CscExtended ();
163 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
165 csc.BaseAddress = "A";
168 Assert.AreEqual ("/baseaddress:A", clbe.ToString (), "A1");
172 public void TestCheckForOverflowUnderflow1 ()
174 CscExtended csc = new CscExtended ();
175 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
177 csc.CheckForOverflowUnderflow = true;
180 Assert.AreEqual ("/checked+", clbe.ToString (), "A1");
184 public void TestCheckForOverflowUnderflow2 ()
186 CscExtended csc = new CscExtended ();
187 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
189 csc.CheckForOverflowUnderflow = false;
192 Assert.AreEqual ("/checked-", clbe.ToString (), "A1");
196 public void TestDisabledWarnings ()
198 CscExtended csc = new CscExtended ();
199 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
201 csc.DisabledWarnings = "A";
204 Assert.AreEqual ("/nowarn:A", clbe.ToString (), "A1");
208 public void TestDisabledWarningsComma ()
210 CscExtended csc = new CscExtended ();
211 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
213 csc.DisabledWarnings = "A, B";
216 Assert.AreEqual ("/nowarn:A;B", clbe.ToString (), "A1");
220 public void TestDocumentationFile ()
222 CscExtended csc = new CscExtended ();
223 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
225 csc.DocumentationFile = "A";
228 Assert.AreEqual ("/doc:A", clbe.ToString (), "A1");
232 [Category ("NotWorking")]
233 public void TestErrorReport ()
235 CscExtended csc = new CscExtended ();
236 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
238 csc.ErrorReport = "A";
241 Assert.AreEqual ("/errorreport:A", clbe.ToString (), "A1");
245 public void TestGenerateFullPaths1 ()
247 CscExtended csc = new CscExtended ();
248 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
250 csc.GenerateFullPaths = true;
253 Assert.AreEqual ("/fullpaths", clbe.ToString (), "A1");
257 public void TestGenerateFullPaths2 ()
259 CscExtended csc = new CscExtended ();
260 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
262 csc.GenerateFullPaths = false;
265 Assert.AreEqual ("", clbe.ToString (), "A1");
269 public void TestLangVersion ()
271 CscExtended csc = new CscExtended ();
272 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
274 csc.LangVersion = "A'B";
277 Assert.AreEqual ("/langversion:\"A'B\"", clbe.ToString (), "A1");
281 [Category ("NotWorking")]
282 public void TestModuleAssemblyName ()
284 CscExtended csc = new CscExtended ();
285 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
287 csc.ModuleAssemblyName = "A'B";
290 Assert.AreEqual ("/moduleassemblyname:\"A'B\"", clbe.ToString (), "A1");
294 [Category ("NotWorking")]
295 public void TestPdbFile ()
297 CscExtended csc = new CscExtended ();
298 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
303 Assert.AreEqual ("/pdb:A", clbe.ToString (), "A1");
307 [Category ("NotWorking")]
308 public void TestPlatform ()
310 CscExtended csc = new CscExtended ();
311 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
316 Assert.AreEqual ("/platform:A", clbe.ToString (), "A1");
320 public void TestWarning ()
322 CscExtended csc = new CscExtended ();
323 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
325 csc.WarningLevel = 4;
328 Assert.AreEqual ("/warn:4", clbe.ToString (), "A1");
332 public void TestWarningAsErrors ()
334 CscExtended csc = new CscExtended ();
335 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
337 csc.WarningsAsErrors = "A'B";
340 Assert.AreEqual ("/warnaserror+:\"A'B\"", clbe.ToString (), "A1");
343 public void TestWarningNotAsErrors ()
345 CscExtended csc = new CscExtended ();
346 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
348 csc.WarningsNotAsErrors = "A'B";
351 Assert.AreEqual ("/warnaserror-:\"A'B\"", clbe.ToString (), "A1");
357 public void TestAdditionalLibPaths ()
359 CscExtended csc = new CscExtended ();
360 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
361 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
363 csc.AdditionalLibPaths = new string [2] { "A'Foo", "B" };
367 Assert.AreEqual ("/lib:\"A'Foo\",B", c1.ToString (), "A1");
368 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
371 // Behavior for this intentionally differs from .net .
372 // msbuild doesn't quote the define args, but we do
373 // that to make it easier to copy/paste and execute
374 // compiler command lines, helps in debugging.
375 [Category ("NotDotNet")]
377 public void TestDefineConstants ()
379 CscExtended csc = new CscExtended ();
380 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
381 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
383 csc.DefineConstants = "A;B;;CD;;;Foo Bar";
387 Assert.AreEqual ("/define:\"A;B;CD;Foo;Bar\"", c1.ToString (), "A1");
388 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
392 public void TestDefineConstants2 ()
394 CscExtended csc = new CscExtended ();
395 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
396 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
398 csc.DefineConstants = ";;;";
402 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
403 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
407 public void TestMainEntryPoint ()
409 CscExtended csc = new CscExtended ();
410 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
411 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
413 csc.MainEntryPoint = "A;B";
417 Assert.AreEqual ("/main:\"A;B\"", c1.ToString (), "A1");
418 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
422 public void TestReferences ()
424 CscExtended csc = new CscExtended ();
425 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
426 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
428 csc.References = new ITaskItem [2] { new TaskItem ("A;C"), new TaskItem ("B") };
432 Assert.AreEqual ("/reference:\"A;C\" /reference:B", c1.ToString (), "A1");
433 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
437 public void TestResponseFiles ()
439 CscExtended csc = new CscExtended ();
440 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
441 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
443 csc.ResponseFiles = new ITaskItem [2] { new TaskItem ("A\'Foo"), new TaskItem ("B") };
447 Assert.AreEqual ("@\"A'Foo\" @B", c1.ToString (), "A1");
448 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
452 public void TestWin32Resource ()
454 CscExtended csc = new CscExtended ();
455 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
456 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
458 csc.Win32Resource = "A;B";
462 Assert.AreEqual ("/win32res:\"A;B\"", c1.ToString (), "A1");
463 Assert.AreEqual (String.Empty, c2.ToString (), "A2");