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 TestDocumentationFile ()
195 CscExtended csc = new CscExtended ();
196 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
198 csc.DocumentationFile = "A";
201 Assert.AreEqual ("/doc:A", clbe.ToString (), "A1");
205 [Category ("NotWorking")]
206 public void TestErrorReport ()
208 CscExtended csc = new CscExtended ();
209 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
211 csc.ErrorReport = "A";
214 Assert.AreEqual ("/errorreport:A", clbe.ToString (), "A1");
218 public void TestGenerateFullPaths1 ()
220 CscExtended csc = new CscExtended ();
221 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
223 csc.GenerateFullPaths = true;
226 Assert.AreEqual ("/fullpaths", clbe.ToString (), "A1");
230 public void TestGenerateFullPaths2 ()
232 CscExtended csc = new CscExtended ();
233 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
235 csc.GenerateFullPaths = false;
238 Assert.AreEqual ("", clbe.ToString (), "A1");
242 public void TestLangVersion ()
244 CscExtended csc = new CscExtended ();
245 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
247 csc.LangVersion = "A'B";
250 Assert.AreEqual ("/langversion:\"A'B\"", clbe.ToString (), "A1");
254 [Category ("NotWorking")]
255 public void TestModuleAssemblyName ()
257 CscExtended csc = new CscExtended ();
258 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
260 csc.ModuleAssemblyName = "A'B";
263 Assert.AreEqual ("/moduleassemblyname:\"A'B\"", clbe.ToString (), "A1");
267 [Category ("NotWorking")]
268 public void TestPdbFile ()
270 CscExtended csc = new CscExtended ();
271 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
276 Assert.AreEqual ("/pdb:A", clbe.ToString (), "A1");
280 [Category ("NotWorking")]
281 public void TestPlatform ()
283 CscExtended csc = new CscExtended ();
284 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
289 Assert.AreEqual ("/platform:A", clbe.ToString (), "A1");
293 public void TestWarning ()
295 CscExtended csc = new CscExtended ();
296 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
298 csc.WarningLevel = 4;
301 Assert.AreEqual ("/warn:4", clbe.ToString (), "A1");
305 public void TestWarningAsErrors ()
307 CscExtended csc = new CscExtended ();
308 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
310 csc.WarningsAsErrors = "A'B";
313 Assert.AreEqual ("/warnaserror+:\"A'B\"", clbe.ToString (), "A1");
316 public void TestWarningNotAsErrors ()
318 CscExtended csc = new CscExtended ();
319 CommandLineBuilderExtension clbe = new CommandLineBuilderExtension ();
321 csc.WarningsNotAsErrors = "A'B";
324 Assert.AreEqual ("/warnaserror-:\"A'B\"", clbe.ToString (), "A1");
330 public void TestAdditionalLibPaths ()
332 CscExtended csc = new CscExtended ();
333 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
334 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
336 csc.AdditionalLibPaths = new string [2] { "A'Foo", "B" };
340 Assert.AreEqual ("/lib:\"A'Foo\",B", c1.ToString (), "A1");
341 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
344 // Behavior for this intentionally differs from .net .
345 // msbuild doesn't quote the define args, but we do
346 // that to make it easier to copy/paste and execute
347 // compiler command lines, helps in debugging.
348 [Category ("NotDotNet")]
350 public void TestDefineConstants ()
352 CscExtended csc = new CscExtended ();
353 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
354 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
356 csc.DefineConstants = "A;B;;CD;;;Foo Bar";
360 Assert.AreEqual ("/define:\"A;B;CD;Foo;Bar\"", c1.ToString (), "A1");
361 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
365 public void TestDefineConstants2 ()
367 CscExtended csc = new CscExtended ();
368 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
369 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
371 csc.DefineConstants = ";;;";
375 Assert.AreEqual (String.Empty, c1.ToString (), "A1");
376 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
380 public void TestMainEntryPoint ()
382 CscExtended csc = new CscExtended ();
383 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
384 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
386 csc.MainEntryPoint = "A;B";
390 Assert.AreEqual ("/main:\"A;B\"", c1.ToString (), "A1");
391 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
395 public void TestReferences ()
397 CscExtended csc = new CscExtended ();
398 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
399 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
401 csc.References = new ITaskItem [2] { new TaskItem ("A;C"), new TaskItem ("B") };
405 Assert.AreEqual ("/reference:\"A;C\" /reference:B", c1.ToString (), "A1");
406 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
410 public void TestResponseFiles ()
412 CscExtended csc = new CscExtended ();
413 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
414 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
416 csc.ResponseFiles = new ITaskItem [2] { new TaskItem ("A\'Foo"), new TaskItem ("B") };
420 Assert.AreEqual ("@\"A'Foo\" @B", c1.ToString (), "A1");
421 Assert.AreEqual (String.Empty, c2.ToString (), "A2");
425 public void TestWin32Resource ()
427 CscExtended csc = new CscExtended ();
428 CommandLineBuilderExtension c1 = new CommandLineBuilderExtension ();
429 CommandLineBuilderExtension c2 = new CommandLineBuilderExtension ();
431 csc.Win32Resource = "A;B";
435 Assert.AreEqual ("/win32res:\"A;B\"", c1.ToString (), "A1");
436 Assert.AreEqual (String.Empty, c2.ToString (), "A2");