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 public void TestItemsInTarget1 ()
285 Engine engine = new Engine (Consts.BinPath);
286 Project proj = engine.CreateNewProject ();
288 string documentString = @"
289 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
290 <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
295 <A Include='A;B;C' />
299 <StringTestTask Property='@(A)@(Z)'>
300 <Output TaskParameter='Property' PropertyName='P1' />
302 <StringTestTask Property=""@(A,'')"">
303 <Output TaskParameter='Property' PropertyName='P2' />
305 <StringTestTask Property=""@(A,'@(A)')"">
306 <Output TaskParameter='Property' PropertyName='P3' />
308 <StringTestTask Property=""@(A,'$(A)')"">
309 <Output TaskParameter='Property' PropertyName='P4' />
311 <StringTestTask Property=""@(A,'@(A,'')')"">
312 <Output TaskParameter='Property' PropertyName='P5' />
314 <StringTestTask Property=""%(A.Filename)"">
315 <Output TaskParameter='Property' ItemName='I1' />
317 <StringTestTask Property=""@(A) %(Filename)"">
318 <Output TaskParameter='Property' ItemName='I2' />
324 proj.LoadXml (documentString);
325 Assert.IsTrue (proj.Build ("1"), "A0, Build failed");
327 Assert.AreEqual ("A;B;C", proj.GetEvaluatedProperty ("P1"), "A1");
328 Assert.AreEqual ("ABC", proj.GetEvaluatedProperty ("P2"), "A2");
329 Assert.AreEqual ("A@(A)B@(A)C", proj.GetEvaluatedProperty ("P3"), "A3");
330 Assert.AreEqual ("AABAC", proj.GetEvaluatedProperty ("P4"), "A4");
331 Assert.AreEqual ("@(A,'ABC')", proj.GetEvaluatedProperty ("P5"), "A5");
332 Assert.AreEqual ("A;B;C", GetItems (proj, "I1"), "A6");
333 Assert.AreEqual ("A A;B B;C C", GetItems (proj, "I2"), "A7");
337 [Category ("NotWorking")]
338 public void TestItemsInTarget2 ()
340 Engine engine = new Engine (Consts.BinPath);
341 Project proj = engine.CreateNewProject ();
343 string documentString = @"
344 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
345 <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
347 <A Include='A;B;C' />
351 <StringTestTask Property=""%(Filename)"">
352 <Output TaskParameter='Property' ItemName='I2' />
358 proj.LoadXml (documentString);
359 Assert.IsFalse (proj.Build ("1"), "A1");
363 [Category ("NotWorking")]
364 public void TestItemsInTarget3 ()
366 Engine engine = new Engine (Consts.BinPath);
367 Project proj = engine.CreateNewProject ();
369 string documentString = @"
370 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
371 <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
378 <A Include='A;B;C' />
382 <StringTestTask Array='$(A)$(A)'>
383 <Output TaskParameter='Array' ItemName='I0' />
385 <StringTestTask Array='$(B)$(B)'>
386 <Output TaskParameter='Array' ItemName='I1' />
388 <StringTestTask Array='$(C)'>
389 <Output TaskParameter='Array' ItemName='I2' />
391 <StringTestTask Array='$(C)$(C)'>
392 <Output TaskParameter='Array' ItemName='I3' />
395 <StringTestTask Array='@(A);$(C)'>
396 <Output TaskParameter='Array' ItemName='I4' />
398 <StringTestTask Array='@(A);A;B;C'>
399 <Output TaskParameter='Array' ItemName='I5' />
405 proj.LoadXml (documentString);
408 Assert.AreEqual ("AA", GetItems (proj, "I0"), "A1");
409 Assert.AreEqual ("A;BA;B", GetItems (proj, "I1"), "A2");
410 Assert.AreEqual (3, proj.GetEvaluatedItemsByName ("I1").Count, "A3");
411 Assert.AreEqual ("A", GetItems (proj, "I2"), "A4");
412 Assert.AreEqual (1, proj.GetEvaluatedItemsByName ("I2").Count, "A5");
413 Assert.AreEqual ("A;A", GetItems (proj, "I3"), "A6");
414 Assert.AreEqual (2, proj.GetEvaluatedItemsByName ("I3").Count, "A7");
416 Assert.AreEqual ("A;B;C;A", GetItems (proj, "I4"), "A8");
417 Assert.AreEqual (4, proj.GetEvaluatedItemsByName ("I4").Count, "A9");
418 Assert.AreEqual ("A;B;C;A;B;C", GetItems (proj, "I5"), "A10");
419 Assert.AreEqual (6, proj.GetEvaluatedItemsByName ("I5").Count, "A11");
423 [Category ("NotWorking")]
424 public void TestItemsInTarget4 ()
426 Engine engine = new Engine (Consts.BinPath);
427 Project proj = engine.CreateNewProject ();
429 string documentString = @"
430 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
431 <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
433 <A Include='A;B;C' />
436 <StringTestTask Array='@(A)@(A)'>
437 <Output TaskParameter='Array' ItemName='I1' />
443 proj.LoadXml (documentString);
444 Assert.IsFalse (proj.Build ("1"));
448 [Category ("NotWorking")]
449 public void TestItemsInTarget5 ()
451 Engine engine = new Engine (Consts.BinPath);
452 Project proj = engine.CreateNewProject ();
454 string documentString = @"
455 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
456 <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
458 <A Include='A;B;C' />
461 <StringTestTask Array='@(A)AAA'>
462 <Output TaskParameter='Array' ItemName='I1' />
468 proj.LoadXml (documentString);
469 Assert.IsFalse (proj.Build ("1"));
473 [Category ("NotWorking")]
474 public void TestItemsInTarget6 ()
476 Engine engine = new Engine (Consts.BinPath);
477 Project proj = engine.CreateNewProject ();
479 string documentString = @"
480 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
481 <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
483 <A Include='A;B;C' />
489 <StringTestTask Array='@(A)$(A)'>
490 <Output TaskParameter='Array' ItemName='I1' />
496 proj.LoadXml (documentString);
497 Assert.IsFalse (proj.Build ("1"));