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.
31 using Microsoft.Build.BuildEngine;
32 using NUnit.Framework;
34 namespace MonoTests.Microsoft.Build.BuildEngine.Various {
37 private string GetItems (Project proj, string name)
39 BuildItemGroup big = proj.GetEvaluatedItemsByName (name);
40 string str = String.Empty;
44 foreach (BuildItem bi in big) {
45 if (str == String.Empty)
46 str = bi.FinalItemSpec;
48 str += ";" + bi.FinalItemSpec;
55 public void TestItems1 ()
57 Engine engine = new Engine (Consts.BinPath);
58 Project proj = engine.CreateNewProject ();
60 string documentString = @"
61 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
64 <Item1 Include='A;B;C' />
65 <Item2 Include='@(Item1);A;D' />
66 <Item3 Include='@(Item2)' Exclude='A' />
67 <Item4 Include='@(Item1);Q' Exclude='@(Item2)' />
68 <Item5 Include='@(Item1)' Exclude='@(Item2)' />
69 <Item6 Include='@(Item2)' Exclude='@(Item1)' />
70 <Item7 Include='@(item_that_doesnt_exist)' />
75 proj.LoadXml (documentString);
76 Assert.AreEqual ("A", GetItems (proj, "Item0"), "A1");
77 Assert.AreEqual ("A;B;C", GetItems (proj, "Item1"), "A2");
78 Assert.AreEqual ("A;B;C;A;D", GetItems (proj, "Item2"), "A3");
79 Assert.AreEqual ("B;C;D", GetItems (proj, "Item3"), "A4");
80 Assert.AreEqual ("Q", GetItems (proj, "Item4"), "A5");
81 Assert.AreEqual (String.Empty, GetItems (proj, "Item5"), "A6");
82 Assert.AreEqual ("D", GetItems (proj, "Item6"), "A7");
83 Assert.AreEqual (String.Empty, GetItems (proj, "Item7"), "A8");
87 public void TestItems2 ()
89 Engine engine = new Engine (Consts.BinPath);
90 Project proj = engine.CreateNewProject ();
92 string documentString = @"
93 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
95 <Item1 Include='A;B;C' />
96 <Item2 Include=""@(Item1,'-')"" />
97 <Item3 Include=""@(Item1,'xx')"" />
102 proj.LoadXml (documentString);
104 Assert.AreEqual ("A-B-C", GetItems (proj, "Item2"), "A1");
105 Assert.AreEqual ("AxxBxxC", GetItems (proj, "Item3"), "A2");
109 public void TestItems3 ()
111 Engine engine = new Engine (Consts.BinPath);
112 Project proj = engine.CreateNewProject ();
114 string documentString = @"
115 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
117 <Item1 Include='A;B;C' />
118 <Item2 Include=""@(Item1, '-')"" />
123 proj.LoadXml (documentString);
125 Assert.AreEqual ("A-B-C", GetItems (proj, "Item2"), "A1");
130 public void TestItems4 ()
132 Engine engine = new Engine (Consts.BinPath);
133 Project proj = engine.CreateNewProject ();
135 string documentString = @"
136 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
138 <Item1 Include='A;B;C' />
139 <Item2 Include=""A\B.txt;A\C.txt;B\B.zip;B\C.zip"" />
140 <ItemT1 Include=""@(Item1->'%(Identity)')"" />
141 <ItemT2 Include=""@(Item1->'%(Identity)%(Identity)')"" />
142 <ItemT3 Include=""@(Item1->'(-%(Identity)-)')"" />
143 <ItemT4 Include=""@(Item2->'%(Extension)')"" />
144 <ItemT5 Include=""@(Item2->'%(Filename)/%(Extension)')"" />
149 proj.LoadXml (documentString);
151 Assert.AreEqual ("A;B;C", GetItems (proj, "ItemT1"), "A1");
152 Assert.AreEqual ("AA;BB;CC", GetItems (proj, "ItemT2"), "A2");
153 Assert.AreEqual ("(-A-);(-B-);(-C-)", GetItems (proj, "ItemT3"), "A3");
154 Assert.AreEqual (".txt;.txt;.zip;.zip", GetItems (proj, "ItemT4"), "A4");
155 Assert.AreEqual (string.Format ("B{0}.txt;C{0}.txt;B{0}.zip;C{0}.zip", Path.DirectorySeparatorChar), GetItems (proj, "ItemT5"), "A5");
158 [Category ("NotWorking")]
159 public void TestItems5 ()
161 Engine engine = new Engine (Consts.BinPath);
162 Project proj = engine.CreateNewProject ();
164 string documentString = @"
165 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
167 <Item Include=""A\B.txt;A\C.txt;B\B.zip;B\C.zip"" />
168 <ItemT Include=""@(Item->'%(RelativeDir)X/%(Filename)')"" />
173 proj.LoadXml (documentString);
175 Assert.AreEqual (@"A\X/B;A\X/C;B\X/B;B\X/C", GetItems (proj, "ItemT"), "A1");
179 [Category ("NotWorking")]
180 public void TestItems6 ()
182 Engine engine = new Engine (Consts.BinPath);
183 Project proj = engine.CreateNewProject ();
185 string documentString = @"
186 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
192 <Item1 Include='A;B;C' />
193 <Item2 Include='%(A.B)' />
194 <Item3 Include='$(Z)' />
195 <Item4 Include=""@(Item1, '$(A)')"" />
196 <Item5 Include=""@(Item1, '%(A)')"" />
197 <Item6 Include=""@(Item1, '@(A)')"" />
198 <Item7 Include=""@(Item1-> '%(Filename)')"" />
203 proj.LoadXml (documentString);
205 Assert.AreEqual ("%(A.B)", GetItems (proj, "Item2"), "A1");
206 Assert.AreEqual (String.Empty, GetItems (proj, "Item3"), "A2");
207 Assert.AreEqual ("AABAC", GetItems (proj, "Item4"), "A3");
208 Assert.AreEqual ("A%(A)B%(A)C", GetItems (proj, "Item5"), "A4");
209 Assert.AreEqual ("A@(A)B@(A)C", GetItems (proj, "Item6"), "A6");
210 Assert.AreEqual ("A;B;C", GetItems (proj, "Item7"), "A6");
214 [ExpectedException (typeof (InvalidProjectFileException),
215 "The expression \"@(Item1, '@(A,'')')\" cannot be used in this context. " +
216 "Item lists cannot be concatenated with other strings where an item list is expected. " +
217 "Use a semicolon to separate multiple item lists. ")]
218 [Category ("NotWorking")]
219 public void TestItems7 ()
221 Engine engine = new Engine (Consts.BinPath);
222 Project proj = engine.CreateNewProject ();
224 string documentString = @"
225 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
227 <Item1 Include='A;B;C' />
228 <Item7 Include=""@(Item1, '@(A,'')')"" />
233 proj.LoadXml (documentString);
237 [ExpectedException (typeof (InvalidProjectFileException),
238 "The expression \"@(Item1, '@(A->'')')\" cannot be used in this context. " +
239 "Item lists cannot be concatenated with other strings where an item list is expected. " +
240 "Use a semicolon to separate multiple item lists. ")]
241 [Category ("NotWorking")]
242 public void TestItems8 ()
244 Engine engine = new Engine (Consts.BinPath);
245 Project proj = engine.CreateNewProject ();
247 string documentString = @"
248 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
250 <Item1 Include='A;B;C' />
251 <Item8 Include=""@(Item1, '@(A->'')')"" />
256 proj.LoadXml (documentString);
260 [ExpectedException (typeof (InvalidProjectFileException),
261 "The expression \"@(Item1, '@(A->'','')')\" cannot be used in this context. " +
262 "Item lists cannot be concatenated with other strings where an item list is expected. " +
263 "Use a semicolon to separate multiple item lists. ")]
264 [Category ("NotWorking")]
265 public void TestItems9 ()
267 Engine engine = new Engine (Consts.BinPath);
268 Project proj = engine.CreateNewProject ();
270 string documentString = @"
271 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
273 <Item1 Include='A;B;C' />
274 <Item9 Include=""@(Item1, '@(A->'','')')"" />
279 proj.LoadXml (documentString);
283 [Category ("NotWorking")]
284 public void TestItemsInTarget1 ()
286 Engine engine = new Engine (Consts.BinPath);
287 Project proj = engine.CreateNewProject ();
289 string documentString = @"
290 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
291 <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
296 <A Include='A;B;C' />
300 <StringTestTask Property='@(A)@(Z)'>
301 <Output TaskParameter='Property' PropertyName='P1' />
303 <StringTestTask Property=""@(A,'')"">
304 <Output TaskParameter='Property' PropertyName='P2' />
306 <StringTestTask Property=""@(A,'@(A)')"">
307 <Output TaskParameter='Property' PropertyName='P3' />
309 <StringTestTask Property=""@(A,'$(A)')"">
310 <Output TaskParameter='Property' PropertyName='P4' />
312 <StringTestTask Property=""@(A,'@(A,'')')"">
313 <Output TaskParameter='Property' PropertyName='P5' />
315 <StringTestTask Property=""%(A.Filename)"">
316 <Output TaskParameter='Property' ItemName='I1' />
318 <StringTestTask Property=""@(A) %(Filename)"">
319 <Output TaskParameter='Property' ItemName='I2' />
325 proj.LoadXml (documentString);
328 Assert.AreEqual ("A;B;C", proj.GetEvaluatedProperty ("P1"), "A1");
329 Assert.AreEqual ("ABC", proj.GetEvaluatedProperty ("P2"), "A2");
330 Assert.AreEqual ("A@(A)B@(A)C", proj.GetEvaluatedProperty ("P3"), "A3");
331 Assert.AreEqual ("AABAC", proj.GetEvaluatedProperty ("P4"), "A4");
332 Assert.AreEqual ("@(A,'ABC')", proj.GetEvaluatedProperty ("P5"), "A5");
333 Assert.AreEqual ("A;B;C", GetItems (proj, "I1"), "A6");
334 Assert.AreEqual ("A A;B B;C C", GetItems (proj, "I2"), "A7");
338 [Category ("NotWorking")]
339 public void TestItemsInTarget2 ()
341 Engine engine = new Engine (Consts.BinPath);
342 Project proj = engine.CreateNewProject ();
344 string documentString = @"
345 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
346 <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
348 <A Include='A;B;C' />
352 <StringTestTask Property=""%(Filename)"">
353 <Output TaskParameter='Property' ItemName='I2' />
359 proj.LoadXml (documentString);
360 Assert.IsFalse (proj.Build ("1"), "A1");
364 [Category ("NotWorking")]
365 public void TestItemsInTarget3 ()
367 Engine engine = new Engine (Consts.BinPath);
368 Project proj = engine.CreateNewProject ();
370 string documentString = @"
371 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
372 <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
379 <A Include='A;B;C' />
383 <StringTestTask Array='$(A)$(A)'>
384 <Output TaskParameter='Array' ItemName='I0' />
386 <StringTestTask Array='$(B)$(B)'>
387 <Output TaskParameter='Array' ItemName='I1' />
389 <StringTestTask Array='$(C)'>
390 <Output TaskParameter='Array' ItemName='I2' />
392 <StringTestTask Array='$(C)$(C)'>
393 <Output TaskParameter='Array' ItemName='I3' />
396 <StringTestTask Array='@(A);$(C)'>
397 <Output TaskParameter='Array' ItemName='I4' />
399 <StringTestTask Array='@(A);A;B;C'>
400 <Output TaskParameter='Array' ItemName='I5' />
406 proj.LoadXml (documentString);
409 Assert.AreEqual ("AA", GetItems (proj, "I0"), "A1");
410 Assert.AreEqual ("A;BA;B", GetItems (proj, "I1"), "A2");
411 Assert.AreEqual (3, proj.GetEvaluatedItemsByName ("I1").Count, "A3");
412 Assert.AreEqual ("A", GetItems (proj, "I2"), "A4");
413 Assert.AreEqual (1, proj.GetEvaluatedItemsByName ("I2").Count, "A5");
414 Assert.AreEqual ("A;A", GetItems (proj, "I3"), "A6");
415 Assert.AreEqual (2, proj.GetEvaluatedItemsByName ("I3").Count, "A7");
417 Assert.AreEqual ("A;B;C;A", GetItems (proj, "I4"), "A8");
418 Assert.AreEqual (4, proj.GetEvaluatedItemsByName ("I4").Count, "A9");
419 Assert.AreEqual ("A;B;C;A;B;C", GetItems (proj, "I5"), "A10");
420 Assert.AreEqual (6, proj.GetEvaluatedItemsByName ("I5").Count, "A11");
424 [Category ("NotWorking")]
425 public void TestItemsInTarget4 ()
427 Engine engine = new Engine (Consts.BinPath);
428 Project proj = engine.CreateNewProject ();
430 string documentString = @"
431 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
432 <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
434 <A Include='A;B;C' />
437 <StringTestTask Array='@(A)@(A)'>
438 <Output TaskParameter='Array' ItemName='I1' />
444 proj.LoadXml (documentString);
445 Assert.IsFalse (proj.Build ("1"));
449 [Category ("NotWorking")]
450 public void TestItemsInTarget5 ()
452 Engine engine = new Engine (Consts.BinPath);
453 Project proj = engine.CreateNewProject ();
455 string documentString = @"
456 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
457 <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
459 <A Include='A;B;C' />
462 <StringTestTask Array='@(A)AAA'>
463 <Output TaskParameter='Array' ItemName='I1' />
469 proj.LoadXml (documentString);
470 Assert.IsFalse (proj.Build ("1"));
474 [Category ("NotWorking")]
475 public void TestItemsInTarget6 ()
477 Engine engine = new Engine (Consts.BinPath);
478 Project proj = engine.CreateNewProject ();
480 string documentString = @"
481 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
482 <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
484 <A Include='A;B;C' />
490 <StringTestTask Array='@(A)$(A)'>
491 <Output TaskParameter='Array' ItemName='I1' />
497 proj.LoadXml (documentString);
498 Assert.IsFalse (proj.Build ("1"));