5 // Marek Sieradzki (marek.sieradzki@gmail.com)
6 // Ankit Jain (jankit@novell.com)
8 // (C) 2006 Marek Sieradzki
9 // Copyright 2009 Novell, Inc (http://www.novell.com)
11 // Permission is hereby granted, free of charge, to any person obtaining
12 // a copy of this software and associated documentation files (the
13 // "Software"), to deal in the Software without restriction, including
14 // without limitation the rights to use, copy, modify, merge, publish,
15 // distribute, sublicense, and/or sell copies of the Software, and to
16 // permit persons to whom the Software is furnished to do so, subject to
17 // the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
26 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
27 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
28 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 using Microsoft.Build.BuildEngine;
34 using NUnit.Framework;
36 namespace MonoTests.Microsoft.Build.BuildEngine.Various {
39 private string GetItems (Project proj, string name)
41 BuildItemGroup big = proj.GetEvaluatedItemsByName (name);
42 string str = String.Empty;
46 foreach (BuildItem bi in big) {
47 if (str == String.Empty)
48 str = bi.FinalItemSpec;
50 str += ";" + bi.FinalItemSpec;
56 private void CheckItems (Project proj, string name, string prefix, params string [] values)
58 BuildItemGroup big = proj.GetEvaluatedItemsByName (name);
60 Assert.Fail ("{0}: Item corresponding '{1}' not found.", prefix, name);
64 if (values.Length != big.Count) {
65 Console.Write ("Expected> ");
66 foreach (string s in values)
67 Console.Write ("{0}|", s);
69 Console.Write ("Actual> ");
70 foreach (BuildItem item in big)
71 Console.Write ("{0}|", item.FinalItemSpec);
73 Assert.AreEqual (values.Length, big.Count, String.Format ("{0}: Number of items", prefix));
75 for (int i = 0; i < values.Length; i ++)
76 Assert.AreEqual (values [i], big [i].FinalItemSpec,
77 String.Format ("{0}: Item named {1}, numbered {2}", prefix, name, i));
81 public void TestItems1 ()
83 Engine engine = new Engine (Consts.BinPath);
84 Project proj = engine.CreateNewProject ();
86 string documentString = @"
87 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
90 <Item1 Include='A;B;C' />
91 <Item2 Include='@(Item1);A;D' />
92 <Item3 Include='@(Item2)' Exclude='A' />
93 <Item4 Include='@(Item1);Q' Exclude='@(Item2)' />
94 <Item5 Include='@(Item1)' Exclude='@(Item2)' />
95 <Item6 Include='@(Item2)' Exclude='@(Item1)' />
96 <Item7 Include='@(item_that_doesnt_exist)' />
101 proj.LoadXml (documentString);
102 CheckItems (proj, "Item0", "A1", "A");
103 CheckItems (proj, "Item1", "A2", "A", "B", "C");
104 CheckItems (proj, "Item2", "A3", "A", "B", "C", "A", "D");
105 CheckItems (proj, "Item3", "A4", "B", "C", "D");
106 CheckItems (proj, "Item4", "A5", "Q");
107 CheckItems (proj, "Item5", "A6");
108 CheckItems (proj, "Item6", "A7", "D");
109 CheckItems (proj, "Item7", "A8");
113 public void TestItems2 ()
115 Engine engine = new Engine (Consts.BinPath);
116 Project proj = engine.CreateNewProject ();
118 string documentString = @"
119 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
121 <Item1 Include='A;B;C' />
122 <Item2 Include=""@(Item1,'-')"" />
123 <Item3 Include=""@(Item1,'xx')"" />
128 proj.LoadXml (documentString);
130 CheckItems (proj, "Item2", "A1", "A-B-C");
131 CheckItems (proj, "Item3", "A2", "AxxBxxC");
135 public void TestItems3 ()
137 Engine engine = new Engine (Consts.BinPath);
138 Project proj = engine.CreateNewProject ();
140 string documentString = @"
141 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
143 <Item1 Include='A;B;C' />
144 <Item2 Include=""@(Item1, '-')"" />
149 proj.LoadXml (documentString);
151 CheckItems (proj, "Item2", "A1", "A-B-C");
156 public void TestItems4 ()
158 Engine engine = new Engine (Consts.BinPath);
159 Project proj = engine.CreateNewProject ();
161 string documentString = @"
162 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
164 <Prop1>@(Item0)</Prop1>
167 <Item0 Include=""Foo""/>
168 <Item1 Include='A;B;C' />
169 <Item2 Include=""A\B.txt;A\C.txt;B\B.zip;B\C.zip"" />
170 <ItemT0 Include=""@(Item1)"" />
171 <ItemT1 Include=""@(Item1->'%(Identity)')"" />
172 <ItemT2 Include=""@(Item1->'%(Identity)%(Identity)')"" />
173 <ItemT3 Include=""@(Item1->'(-%(Identity)-)')"" />
174 <ItemT4 Include=""@(Item2->'%(Extension)')"" />
175 <ItemT5 Include=""@(Item2->'%(Filename)/%(Extension)')"" />
176 <ItemT6 Include=""@(Item2->'%(Extension)/$(Prop1)')"" />
181 proj.LoadXml (documentString);
183 //Assert.IsTrue (proj.Build (), "Build failed");
185 Assert.AreEqual ("@(Item0)", proj.EvaluatedProperties["Prop1"].FinalValue, "A0");
186 //Assert.AreEqual ("@(Item2->'%(Extension)/$(Prop1)')", proj.EvaluatedItems [7].FinalItemSpec, "B0");
188 CheckItems (proj, "ItemT0", "A1", "A", "B", "C");
189 CheckItems (proj, "ItemT1", "A1", "A", "B", "C");
190 CheckItems (proj, "ItemT2", "A2", "AA", "BB", "CC");
191 CheckItems (proj, "ItemT3", "A3", "(-A-)", "(-B-)", "(-C-)");
192 CheckItems (proj, "ItemT4", "A4", ".txt", ".txt", ".zip", ".zip");
193 CheckItems (proj, "ItemT5", "A5", "B/.txt", "C/.txt", "B/.zip", "C/.zip");
194 CheckItems (proj, "ItemT6", "A6", ".txt/@(Item0)", ".txt/@(Item0)", ".zip/@(Item0)", ".zip/@(Item0)");
198 public void TestItems5 ()
200 Engine engine = new Engine (Consts.BinPath);
201 Project proj = engine.CreateNewProject ();
203 string documentString = @"
204 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
206 <Item Include=""A\B.txt;A\C.txt;B\B.zip;B\C.zip"" />
207 <ItemT Include=""@(Item->'%(RelativeDir)X/%(Filename)')"" />
212 proj.LoadXml (documentString);
214 CheckItems (proj, "ItemT", "A1", @"A\X/B", @"A\X/C", @"B\X/B", @"B\X/C");
218 public void TestItems6 ()
220 Engine engine = new Engine (Consts.BinPath);
221 Project proj = engine.CreateNewProject ();
223 string documentString = @"
224 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
230 <Item1 Include='A;B;C' />
231 <Item2 Include='%(A.B)' />
232 <Item3 Include='$(Z)' />
233 <Item4 Include=""@(Item1, '$(A)')"" />
234 <Item5 Include=""@(Item1, '%(A)')"" />
235 <Item6 Include=""@(Item1, '@(A)')"" />
236 <Item7 Include=""@(Item1-> '%(Filename)')"" />
241 proj.LoadXml (documentString);
243 CheckItems (proj, "Item2", "A1", "%(A.B)");
244 CheckItems (proj, "Item3", "A2");
245 CheckItems (proj, "Item4", "A3", "AABAC");
246 CheckItems (proj, "Item5", "A4", "A%(A)B%(A)C");
247 CheckItems (proj, "Item6", "A6", "A@(A)B@(A)C");
248 CheckItems (proj, "Item7", "A6", "A", "B", "C");
251 // The expression "@(Item1, '@(A,'')')" cannot be used in this context.
252 // Item lists cannot be concatenated with other strings where an item list is expected.
253 // Use a semicolon to separate multiple item lists.
255 [ExpectedException (typeof (InvalidProjectFileException))]
256 [Category ("NotWorking")]
257 public void TestItems7 ()
259 Engine engine = new Engine (Consts.BinPath);
260 Project proj = engine.CreateNewProject ();
262 string documentString = @"
263 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
265 <Item1 Include='A;B;C' />
266 <Item7 Include=""@(Item1, '@(A,'')')"" />
271 proj.LoadXml (documentString);
274 // The expression "@(Item1, '@(A->'')')" cannot be used in this context.
275 // Item lists cannot be concatenated with other strings where an item list is expected.
276 // Use a semicolon to separate multiple item lists.
278 [ExpectedException (typeof (InvalidProjectFileException))]
279 [Category ("NotWorking")]
280 public void TestItems8 ()
282 Engine engine = new Engine (Consts.BinPath);
283 Project proj = engine.CreateNewProject ();
285 string documentString = @"
286 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
288 <Item1 Include='A;B;C' />
289 <Item8 Include=""@(Item1, '@(A->'')')"" />
294 proj.LoadXml (documentString);
297 // The expression "@(Item1, '@(A->'','')')" cannot be used in this context.
298 // Item lists cannot be concatenated with other strings where an item list is expected.
299 // Use a semicolon to separate multiple item lists.
301 [ExpectedException (typeof (InvalidProjectFileException))]
302 [Category ("NotWorking")]
303 public void TestItems9 ()
305 Engine engine = new Engine (Consts.BinPath);
306 Project proj = engine.CreateNewProject ();
308 string documentString = @"
309 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
311 <Item1 Include='A;B;C' />
312 <Item9 Include=""@(Item1, '@(A->'','')')"" />
317 proj.LoadXml (documentString);
321 // test item metadata
322 public void TestItems10 ()
324 string project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
326 <Prop1>@(Item0)</Prop1>
327 <Prop2>@(Ref1)</Prop2>
330 <Item0 Include=""Foo""/>
331 <Ref1 Include=""File1"" />
332 <IWithM Include=""A"">
339 <Message Text=""IWithM.md: %(IWithM.Md)""/>
340 <Message Text=""IWithM.md2: %(IWithM.Md2)""/>
342 <CreateItem Include=""Bar;Xyz"">
343 <Output TaskParameter=""Include"" ItemName=""Item0""/>
346 <Message Text=""IWithM.md: %(IWithM.Md)""/>
347 <Message Text=""IWithM.md2: %(IWithM.Md2)""/>
352 Engine engine = new Engine (Consts.BinPath);
353 Project proj = engine.CreateNewProject ();
354 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
355 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
356 proj.LoadXml (project_xml);
357 engine.RegisterLogger (logger);
359 if (!proj.Build ("1")) {
360 logger.DumpMessages ();
361 Assert.Fail ("Build failed");
364 logger.CheckLoggedMessageHead ("IWithM.md: Foo", "A1");
365 logger.CheckLoggedMessageHead ("IWithM.md2: File1", "A2");
367 logger.CheckLoggedMessageHead ("IWithM.md: Foo", "A3");
368 logger.CheckLoggedMessageHead ("IWithM.md2: File1", "A4");
369 Assert.AreEqual (0, logger.NormalMessageCount, "unexpected messages found");
373 // Test Item/prop references in conditions
374 public void TestItems11 () {
375 string project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
377 <Prop1>@(Item0)</Prop1>
380 <Item0 Include=""Foo""/>
381 <Item1 Include=""@(Item0)""/>
383 <CondItem Condition=""'@(Item1)' == '@(Item0)'"" Include=""Equal to item0""/>
384 <CondItem Condition=""'@(Item1)' == 'Foo'"" Include=""Equal to item0's value""/>
386 <CondItem1 Condition=""'$(Prop1)' == '@(Item0)'"" Include=""Equal to item0""/>
387 <CondItem1 Condition=""'$(Prop1)' == 'Foo'"" Include=""Equal to item0's value""/>
391 <Message Text = ""CondItem: %(CondItem.Identity)""/>
392 <Message Text = ""CondItem1: %(CondItem1.Identity)""/>
397 Engine engine = new Engine (Consts.BinPath);
398 Project proj = engine.CreateNewProject ();
399 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
400 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
401 proj.LoadXml (project_xml);
402 engine.RegisterLogger (logger);
404 if (!proj.Build ("1")) {
405 logger.DumpMessages ();
406 Assert.Fail ("Build failed");
409 logger.CheckLoggedMessageHead ("CondItem: Equal to item0", "A1");
410 logger.CheckLoggedMessageHead ("CondItem: Equal to item0's value", "A2");
411 logger.CheckLoggedMessageHead ("CondItem1: Equal to item0", "A3");
412 logger.CheckLoggedMessageHead ("CondItem1: Equal to item0's value", "A4");
413 Assert.AreEqual (0, logger.NormalMessageCount, "unexpected messages found");
417 // test properties and item refs, with dynamic properties/items
418 public void TestItems12 ()
420 string project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
422 <Prop2>@(Ref1)</Prop2>
425 <Ref1 Include=""File1"" />
426 <Files Include=""@(Ref1)""/>
430 <Message Text=""Prop2: $(Prop2)""/>
432 <Message Text=""Files: @(Files)""/>
433 <CreateItem Include=""foobar"">
434 <Output TaskParameter=""Include"" ItemName=""Ref1""/>
436 <Message Text=""Files: @(Files)""/>
438 <Message Text=""Prop2: $(Prop2)""/>
439 <CreateProperty Value=""NewValue"">
440 <Output TaskParameter=""Value"" PropertyName=""Prop2""/>
442 <Message Text=""Prop2: $(Prop2)""/>
447 Engine engine = new Engine (Consts.BinPath);
448 Project proj = engine.CreateNewProject ();
449 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
450 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
451 proj.LoadXml (project_xml);
452 engine.RegisterLogger (logger);
454 if (!proj.Build ("1")) {
455 logger.DumpMessages ();
456 Assert.Fail ("Build failed");
459 logger.DumpMessages ();
460 logger.CheckLoggedMessageHead ("Prop2: File1", "A1");
461 logger.CheckLoggedMessageHead ("Files: File1", "A1");
462 logger.CheckLoggedMessageHead ("Files: File1", "A1");
463 logger.CheckLoggedMessageHead ("Prop2: File1;foobar", "A1");
464 logger.CheckLoggedMessageHead ("Prop2: NewValue", "A1");
465 Assert.AreEqual (0, logger.NormalMessageCount, "unexpected messages found");
469 // test item refs in properties
470 public void TestItems13 () {
471 string project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
473 <Prop1>@(Item0)</Prop1>
476 <Item0 Include=""Foo""/>
477 <Item1 Include=""A\B.txt;A\C.txt;B\B.zip;B\C.zip"" />
478 <Item2 Include=""@(Item1->'%(Extension)/$(Prop1)')"" />
482 <Message Text=""Item2: @(Item2)""/>
486 Engine engine = new Engine (Consts.BinPath);
487 Project proj = engine.CreateNewProject ();
488 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
489 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
490 proj.LoadXml (project_xml);
491 engine.RegisterLogger (logger);
493 if (!proj.Build ("1")) {
494 logger.DumpMessages ();
495 Assert.Fail ("Build failed");
498 logger.CheckLoggedMessageHead ("Item2: .txt/@(Item0);.txt/@(Item0);.zip/@(Item0);.zip/@(Item0)", "A1");
499 Assert.AreEqual (0, logger.NormalMessageCount, "unexpected messages found");
503 public void TestSelfRefrentialItems ()
505 string project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
507 <Prop1>@(Item1);Val</Prop1>
508 <Prop2>@(Item2)</Prop2>
509 <Prop3>@(Item3)</Prop3>
512 <Item1 Include=""Item1OldVal""/>
513 <Item1 Include=""@(Item1);$(Prop1)""/>
515 <Item2 Include=""Item2OldVal""/>
516 <Item2 Include=""@(Item2->'%(Identity)');$(Prop2)""/>
518 <Item3 Include=""Item3OldVal""/>
519 <Item3 Include=""@(Item3, '_');$(Prop3)""/>
521 <Item4 Include=""@(Item4)""/>
525 <Message Text=""Item1: %(Item1.Identity)""/>
526 <Message Text=""Item2: %(Item2.Identity)""/>
527 <Message Text=""Item3: %(Item3.Identity)""/>
528 <Message Text=""%(Item4.Identity)""/>
529 <Message Text=""Item4: %(Item4.Identity)""/>
534 Engine engine = new Engine (Consts.BinPath);
535 Project proj = engine.CreateNewProject ();
536 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
537 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
538 proj.LoadXml (project_xml);
539 engine.RegisterLogger (logger);
541 if (!proj.Build ("1")) {
542 logger.DumpMessages ();
543 Assert.Fail ("Build failed");
546 logger.DumpMessages ();
547 logger.CheckLoggedMessageHead ("Item1: Item1OldVal", "A1");
548 logger.CheckLoggedMessageHead ("Item1: Val", "A2");
549 logger.CheckLoggedMessageHead ("Item2: Item2OldVal", "A3");
550 logger.CheckLoggedMessageHead ("Item3: Item3OldVal", "A4");
551 logger.CheckLoggedMessageHead ("Item4: ", "A5");
552 Assert.AreEqual (0, logger.NormalMessageCount, "unexpected messages found");
556 public void TestEmptyItemsWithBatching ()
558 string project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
559 <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
560 <UsingTask TaskName='TestTask_TaskItem' AssemblyFile='Test\resources\TestTasks.dll' />
561 <UsingTask TaskName='TestTask_TaskItems' AssemblyFile='Test\resources\TestTasks.dll' />
563 <StringTestTask Property=""%(Item4.Identity)"">
564 <Output TaskParameter=""OutputString"" PropertyName=""OutputString""/>
566 <Message Text='output1: $(OutputString)'/>
568 <StringTestTask Property="" %(Item4.Identity)"">
569 <Output TaskParameter=""OutputString"" PropertyName=""OutputString""/>
571 <Message Text='output2: $(OutputString)'/>
573 <StringTestTask Array=""%(Item4.Identity)"">
574 <Output TaskParameter=""OutputString"" PropertyName=""OutputString""/>
576 <Message Text='output3: $(OutputString)'/>
578 <StringTestTask Array="" %(Item4.Identity)"">
579 <Output TaskParameter=""OutputString"" PropertyName=""OutputString""/>
581 <Message Text='output4: $(OutputString)'/>
584 <TestTask_TaskItem Property=""%(Item4.Identity)"">
585 <Output TaskParameter=""Output"" PropertyName=""OutputString""/>
587 <Message Text='output5: $(OutputString)'/>
589 <TestTask_TaskItem Property="" %(Item4.Identity)"">
590 <Output TaskParameter=""Output"" PropertyName=""OutputString""/>
592 <Message Text='output6: $(OutputString)'/>
595 <TestTask_TaskItems Property="" %(Item4.Identity)"">
596 <Output TaskParameter=""Output"" PropertyName=""OutputString""/>
597 </TestTask_TaskItems>
598 <Message Text='output7: $(OutputString)'/>
601 <!-- no space in property -->
602 <TestTask_TaskItems Property=""%(Item4.Identity)"">
603 <Output TaskParameter=""Output"" PropertyName=""OutputString""/>
604 </TestTask_TaskItems>
605 <Message Text='output8: $(OutputString)'/>
611 Engine engine = new Engine (Consts.BinPath);
612 Project proj = engine.CreateNewProject ();
613 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
614 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
615 proj.LoadXml (project_xml);
616 engine.RegisterLogger (logger);
618 if (!proj.Build ("1")) {
619 logger.DumpMessages ();
620 Assert.Fail ("Build failed");
623 logger.DumpMessages ();
624 logger.CheckLoggedMessageHead ("output1: property: null ## array: null", "A1");
625 logger.CheckLoggedMessageHead ("output2: property: ## array: null", "A2");
626 logger.CheckLoggedMessageHead ("output3: property: null ## array: null", "A3");
627 logger.CheckLoggedMessageHead ("output4: property: null ## array: null", "A4");
629 logger.CheckLoggedMessageHead ("output5: null", "A5");
630 logger.CheckLoggedMessageHead ("output6: null", "A6");
631 logger.CheckLoggedMessageHead ("output7: null", "A7");
632 logger.CheckLoggedMessageHead ("output8: null", "A8");
634 Assert.AreEqual (0, logger.NormalMessageCount, "unexpected messages found");
638 public void TestItemsInTarget1 ()
640 Engine engine = new Engine (Consts.BinPath);
641 Project proj = engine.CreateNewProject ();
643 string documentString = @"
644 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
645 <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
651 <A Include='A;B;C' />
655 <StringTestTask Property='@(A)@(Z)'>
656 <Output TaskParameter='Property' PropertyName='P1' />
658 <StringTestTask Property=""@(A,'')"">
659 <Output TaskParameter='Property' PropertyName='P2' />
661 <StringTestTask Property=""@(A,'@(A)')"">
662 <Output TaskParameter='Property' PropertyName='P3' />
664 <StringTestTask Property=""@(A,'$(A)')"">
665 <Output TaskParameter='Property' PropertyName='P4' />
667 <StringTestTask Property=""@(A,'@(A,'')')"">
668 <Output TaskParameter='Property' PropertyName='P5' />
670 <StringTestTask Property=""@(A,'$(B)')"">
671 <Output TaskParameter='Property' PropertyName='P6' />
673 <StringTestTask Property=""%(A.Filename)"">
674 <Output TaskParameter='Property' ItemName='I1' />
676 <StringTestTask Property=""@(A) %(Filename)"">
677 <Output TaskParameter='Property' ItemName='I2' />
683 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
684 engine.RegisterLogger (logger);
685 proj.LoadXml (documentString);
686 if (!proj.Build ("1")) {
687 logger.DumpMessages ();
688 Assert.Fail ("build failed");
691 Assert.AreEqual ("A;B;C", proj.GetEvaluatedProperty ("P1"), "A1");
692 Assert.AreEqual ("ABC", proj.GetEvaluatedProperty ("P2"), "A2");
693 Assert.AreEqual ("A@(A)B@(A)C", proj.GetEvaluatedProperty ("P3"), "A3");
694 Assert.AreEqual ("AABAC", proj.GetEvaluatedProperty ("P4"), "A4");
695 Assert.AreEqual ("@(A,'ABC')", proj.GetEvaluatedProperty ("P5"), "A5");
696 Assert.AreEqual ("A@(A)gB@(A)gC", proj.GetEvaluatedProperty ("P6"), "A6");
697 CheckItems (proj, "I1", "A6", "A", "B", "C");
698 CheckItems (proj, "I2", "A7", "A A", "B B", "C C");
702 [Category ("NotWorking")]
703 public void TestItemsInTarget2 ()
705 Engine engine = new Engine (Consts.BinPath);
706 Project proj = engine.CreateNewProject ();
708 string documentString = @"
709 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
710 <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
712 <A Include='A;B;C' />
716 <StringTestTask Property=""%(Filename)"">
717 <Output TaskParameter='Property' ItemName='I2' />
723 proj.LoadXml (documentString);
724 Assert.IsFalse (proj.Build ("1"), "A1");
728 public void TestItemsInTarget3 ()
730 Engine engine = new Engine (Consts.BinPath);
731 Project proj = engine.CreateNewProject ();
733 string documentString = @"
734 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
735 <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
742 <A Include='A;B;C' />
745 documentString += CreateTargetFragment ("StringTestTask", "Array", "Array", "I",
757 proj.LoadXml (documentString);
758 Assert.IsTrue (proj.Build ("1"), "Build failed");
760 CheckItems (proj, "I0", "A0", "AA");
761 CheckItems (proj, "I1", "A1", "A", "BA", "B");
762 CheckItems (proj, "I2", "A2", "A");
763 CheckItems (proj, "I3", "A3", "A", "A");
764 CheckItems (proj, "I4", "A4", "A", "B", "C", "A");
765 CheckItems (proj, "I5", "A5", "A", "B", "C", "A", "B", "C");
766 CheckItems (proj, "I6", "A6", "Foo", "A", "B", "C");
767 CheckItems (proj, "I7", "A7", "A", "B", "C", "Foo");
771 //Test with ITaskItem[]
772 public void TestItemsInTarget3a ()
774 Engine engine = new Engine (Consts.BinPath);
775 Project proj = engine.CreateNewProject ();
777 string documentString = @"
778 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
779 <UsingTask TaskName='BatchingTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
786 <A Include='A;B;C' />
790 documentString += CreateTargetFragment ("BatchingTestTask", "Sources", "Output", "I",
797 " $(C) Foo $(C) Bar ; $(B) ",
800 " abc; @(A) ; $(C) ;foo",
804 proj.LoadXml (documentString);
805 Assert.IsTrue (proj.Build ("1"), "Build failed");
807 CheckItems (proj, "I0", "A0", "AA");
808 CheckItems (proj, "I1", "A1", "A", "BA", "B");
809 CheckItems (proj, "I2", "A2", "A");
810 CheckItems (proj, "I3", "A3", "A", "A");
811 CheckItems (proj, "I4", "A4", "A", "A");
812 CheckItems (proj, "I5", "A5", "A", "Foo A", "Bar", "A", "B");
813 CheckItems (proj, "I6", "A6", "A", "B", "C", "A");
814 CheckItems (proj, "I7", "A7", "A", "B", "C", "A", "B", "C");
815 CheckItems(proj, "I8", "A8", "abc", "A", "B", "C", "A", "foo");
820 public void TestItemsInTarget3b ()
822 Engine engine = new Engine (Consts.BinPath);
823 Project proj = engine.CreateNewProject ();
825 string documentString = @"
826 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
827 <UsingTask TaskName='BatchingTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
834 <A Include='A;B;;;C' />
837 documentString += CreateTargetFragment ("BatchingTestTask", "Strings", "StringsOutput", "I",
843 "$(C) $(C) $(C)Bar$(C)",
848 proj.LoadXml (documentString);
849 Assert.IsTrue (proj.Build ("1"), "Build failed");
851 CheckItems (proj, "I0", "A0", "AA");
852 CheckItems (proj, "I1", "A1", "A", "BA", "B");
853 CheckItems (proj, "I2", "A2", "A");
854 CheckItems (proj, "I3", "A3", "A", "A");
855 CheckItems (proj, "I4", "A4", "A", "A", "A", "BarA");
856 CheckItems (proj, "I5", "A5", "A", "B", "C", "A");
857 CheckItems (proj, "I6", "A6", "A", "B", "C", "A", "B", "C");
862 public void TestItemsInTarget3c ()
864 Engine engine = new Engine (Consts.BinPath);
865 Project proj = engine.CreateNewProject ();
866 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
867 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger();
868 engine.RegisterLogger(logger);
870 string documentString = @"
871 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
872 <UsingTask TaskName='BatchingTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
880 <A Include='A;B;;;C' />
883 documentString += CreateTargetFragment ("BatchingTestTask", "SingleString", "SingleStringOutput", "I",
895 proj.LoadXml (documentString);
896 if (!proj.Build("1")) {
897 logger.DumpMessages();
898 Assert.Fail("Build failed");
901 BuildProperty bp = proj.EvaluatedProperties ["D"];
902 Assert.AreEqual ("$(C);Foo", bp.Value, "B0");
903 Assert.AreEqual ("A;;;Foo", bp.FinalValue, "B1");
905 bp = proj.EvaluatedProperties ["C"];
906 Assert.AreEqual ("A;;", bp.Value, "B3");
907 Assert.AreEqual ("A;;", bp.FinalValue, "B4");
909 CheckItems (proj, "I0", "A0", "AA");
910 CheckItems (proj, "I1", "A1", "A;BA;B");
911 CheckItems (proj, "I2", "A2", "A;;");
912 CheckItems (proj, "I3", "A3", "A;;A;;");
913 CheckItems (proj, "I4", "A4", "A;; A;;");
914 CheckItems (proj, "I5", "A5", "A;B;C;A;;");
915 CheckItems (proj, "I6", "A6", "A;B;C;A;B;C");
916 CheckItems (proj, "I7", "A7", "A;B;C A;; A;B;C");
920 public void TestSingleTaskItemError1 ()
922 CheckSingleTaskItemProject ("$(B)$(B)");
926 public void TestSingleTaskItemError2 ()
928 CheckSingleTaskItemProject ("$(C)$(C)");
932 public void TestSingleTaskItemError3 ()
934 CheckSingleTaskItemProject ("$(C) $(C)");
938 public void TestSingleTaskItemError4 ()
940 CheckSingleTaskItemProject ("@(A)");
944 public void TestSingleTaskItemError5 ()
946 CheckSingleTaskItemProject ("@(A);$(C))");
950 public void TestSingleTaskItemError6 ()
952 CheckSingleTaskItemProject ("@(A);A;B;C");
956 public void TestSingleTaskItemError7 ()
958 CheckSingleTaskItemProject ("@(Item1)$(C)");
962 public void TestSingleTaskItemError8 ()
964 CheckSingleTaskItemProject ("$(B).foo");
968 public void TestSingleTaskItem1 ()
970 Project proj = BuildProjectForSingleTaskItem ("$(D)$(C)");
971 CheckItems (proj, "I0", "A0", "A");
975 public void TestSingleTaskItem2 ()
977 Project proj = BuildProjectForSingleTaskItem ("@(Item1)");
978 CheckItems (proj, "I0", "A0", "F");
982 public void TestSingleTaskItem3 ()
984 Project proj = BuildProjectForSingleTaskItem ("$(A).foo");
985 CheckItems (proj, "I0", "A0", "A.foo");
989 public void TestSingleTaskItem4 ()
991 Project proj = BuildProjectForSingleTaskItem ("$(C)");
992 CheckItems (proj, "I0", "A0", "A");
995 void CheckSingleTaskItemProject (string expression)
997 string documentString = CreateProjectForSingleTaskItem (expression);
998 Engine engine = new Engine (Consts.BinPath);
999 Project proj = engine.CreateNewProject ();
1000 proj.LoadXml (documentString);
1001 Assert.IsFalse (proj.Build ("1"), "Build should've failed");
1004 Project BuildProjectForSingleTaskItem (string expression)
1006 string documentString = CreateProjectForSingleTaskItem (expression);
1007 Engine engine = new Engine (Consts.BinPath);
1008 Project proj = engine.CreateNewProject ();
1009 proj.LoadXml (documentString);
1010 Assert.IsTrue (proj.Build ("1"), "Build failed");
1015 string CreateProjectForSingleTaskItem (string expression)
1018 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1019 <UsingTask TaskName='BatchingTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
1027 <A Include='A;B;C' />
1028 <Item1 Include='F' />
1032 <BatchingTestTask SingleTaskItem='" + expression + @"'>
1033 <Output TaskParameter='SingleStringOutput' ItemName='I0' />
1039 string CreateTargetFragment (string taskname, string task_param_in, string task_param_out, string item_prefix,
1042 StringBuilder sb = new StringBuilder ();
1044 sb.Append ("<Target Name='1'>");
1045 for (int i = 0; i < args.Length; i ++) {
1046 sb.AppendFormat ("<{0} {1}='{2}'>\n", taskname, task_param_in, args [i]);
1047 sb.AppendFormat ("\t<Output TaskParameter='{0}' ItemName='{1}{2}' />\n", task_param_out, item_prefix, i);
1048 sb.AppendFormat ("</{0}>\n", taskname);
1050 sb.Append ("</Target>");
1052 return sb.ToString ();
1056 public void TestItemsInTarget4 ()
1058 Engine engine = new Engine (Consts.BinPath);
1059 Project proj = engine.CreateNewProject ();
1061 string documentString = @"
1062 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1063 <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
1065 <A Include='A;B;C' />
1068 <StringTestTask Array='@(A)@(A)'>
1069 <Output TaskParameter='Array' ItemName='I1' />
1075 proj.LoadXml (documentString);
1076 Assert.IsFalse (proj.Build ("1"));
1080 public void TestItemsInTarget5 ()
1082 Engine engine = new Engine (Consts.BinPath);
1083 Project proj = engine.CreateNewProject ();
1085 string documentString = @"
1086 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1087 <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
1089 <A Include='A;B;C' />
1092 <StringTestTask Array='@(A)AAA'>
1093 <Output TaskParameter='Array' ItemName='I1' />
1099 proj.LoadXml (documentString);
1100 Assert.IsFalse (proj.Build ("1"));
1104 public void TestItemsInTarget6 ()
1106 Engine engine = new Engine (Consts.BinPath);
1107 Project proj = engine.CreateNewProject ();
1109 string documentString = @"
1110 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1111 <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
1113 <A Include='A;B;C' />
1119 <StringTestTask Array='@(A)$(A)'>
1120 <Output TaskParameter='Array' ItemName='I1' />
1126 proj.LoadXml (documentString);
1127 Assert.IsFalse (proj.Build ("1"));
1131 public void TestItemsInTarget7 ()
1133 Engine engine = new Engine (Consts.BinPath);
1134 Project proj = engine.CreateNewProject ();
1136 string documentString = @"
1137 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1138 <UsingTask TaskName='BatchingTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
1140 <A Include='A;B;C' />
1141 <B Include='Foo;' />
1144 <BatchingTestTask SingleTaskItem='Bar%(B.Identity)@(A)' />
1149 proj.LoadXml (documentString);
1150 Assert.IsFalse (proj.Build ("1"));
1154 public void TestItemsInTarget8 ()
1156 Engine engine = new Engine (Consts.BinPath);
1157 Project proj = engine.CreateNewProject ();
1159 string documentString = @"
1160 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1173 proj.LoadXml (documentString);
1175 Assert.AreEqual (1, proj.EvaluatedItems.Count, "A1");
1176 BuildItem bi = proj.EvaluatedItems [0];
1177 Assert.AreEqual ("False", bi.GetMetadata ("M"), "A2");
1182 public void TestItemsInTarget9 ()
1184 Engine engine = new Engine (Consts.BinPath);
1185 Project proj = engine.CreateNewProject ();
1187 string documentString = @"
1188 <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1194 <M Condition="" '$(Foo)' == 'Five' "">True</M>
1195 <M Condition="" '$(Foo)' != 'Five' "">False</M>
1201 proj.LoadXml (documentString);
1203 Assert.AreEqual (1, proj.EvaluatedItems.Count, "A1");
1204 BuildItem bi = proj.EvaluatedItems [0];
1205 Assert.AreEqual ("True", bi.GetMetadata ("M"), "A2");
1206 Assert.AreEqual (0, bi.Condition.Length, "A3");
1208 BuildItemGroup big = proj.GetEvaluatedItemsByNameIgnoringCondition ("A");
1209 Assert.AreEqual (1, big.Count, "A4");
1211 Assert.AreEqual ("True", bi.GetMetadata ("M"), "A5");
1212 Assert.AreEqual ("True", bi.GetEvaluatedMetadata ("M"), "A6");
1214 /*proj.SetProperty ("Foo", "Six");
1216 bi = proj.GetEvaluatedItemsByName ("A") [0];
1217 Assert.AreEqual ("False", bi.GetMetadata ("M"), "A7");
1218 Assert.AreEqual ("False", bi.GetEvaluatedMetadata ("M"), "A7a");
1219 Assert.AreEqual (0, bi.Condition.Length, "A8");
1221 big = proj.GetEvaluatedItemsByNameIgnoringCondition ("A");
1222 Assert.AreEqual (1, big.Count, "A9");
1224 Assert.AreEqual ("True", bi.GetMetadata ("M"), "A10");
1225 Assert.AreEqual ("True", bi.GetEvaluatedMetadata ("M"), "A11");*/