5 // Marek Sieradzki (marek.sieradzki@gmail.com)
7 // (C) 2005 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 System.Collections.Generic;
33 using Microsoft.Build.BuildEngine;
34 using Microsoft.Build.Framework;
35 using Microsoft.Build.Utilities;
36 using NUnit.Framework;
39 namespace MonoTests.Microsoft.Build.BuildEngine {
41 class TestLogger : Logger {
42 int target_started_events = 0;
43 int target_finished_events = 0;
45 public override void Initialize (IEventSource eventSource)
47 eventSource.TargetStarted += new TargetStartedEventHandler(TargetStarted);
48 eventSource.TargetFinished += new TargetFinishedEventHandler(TargetFinished);
49 eventSource.MessageRaised += new BuildMessageEventHandler(Message);
50 eventSource.WarningRaised += new BuildWarningEventHandler(Warning);
53 void TargetStarted (object sender, TargetStartedEventArgs args)
55 target_started_events++;
58 void TargetFinished (object sender, TargetFinishedEventArgs args)
60 target_finished_events++;
63 void Message (object sender, BuildMessageEventArgs args)
67 void Warning (object sender, BuildWarningEventArgs args)
71 public int TargetStartedEvents { get { return target_started_events; } }
73 public int TargetFinishedEvents { get { return target_finished_events; } }
77 public class ProjectTest {
80 Import [] GetImports (ImportCollection ic)
82 List<Import> list = new List<Import> ();
83 foreach (Import i in ic)
85 return list.ToArray ();
90 [ExpectedException (typeof (InvalidProjectFileException),
91 @"The default XML namespace of the project must be the MSBuild XML namespace." +
92 " If the project is authored in the MSBuild 2003 format, please add " +
93 "xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\" to the <Project> element. " +
94 "If the project has been authored in the old 1.0 or 1.2 format, please convert it to MSBuild 2003 format. ")]
95 public void TestAssignment1 ()
99 string documentString =
100 "<Project></Project>";
102 engine = new Engine (Consts.BinPath);
103 DateTime time = DateTime.Now;
104 project = engine.CreateNewProject ();
105 project.LoadXml (documentString);
107 Assert.AreEqual (true, project.BuildEnabled, "A1");
108 Assert.AreEqual (String.Empty, project.DefaultTargets, "A2");
109 Assert.AreEqual (String.Empty, project.FullFileName, "A3");
110 Assert.AreEqual (false, project.IsDirty, "A4");
111 Assert.AreEqual (false, project.IsValidated, "A5");
112 Assert.AreEqual (engine, project.ParentEngine, "A6");
113 Assert.IsTrue (time <= project.TimeOfLastDirty, "A7");
114 Assert.IsTrue (String.Empty != project.Xml, "A8");
118 public void TestAssignment2 ()
122 string documentString =
123 "<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\"></Project>";
125 engine = new Engine (Consts.BinPath);
126 DateTime time = DateTime.Now;
127 project = engine.CreateNewProject ();
128 project.LoadXml (documentString);
130 Assert.AreEqual (true, project.BuildEnabled, "A1");
131 Assert.AreEqual (String.Empty, project.DefaultTargets, "A2");
132 Assert.AreEqual (String.Empty, project.FullFileName, "A3");
133 Assert.AreEqual (true, project.IsDirty, "A4");
134 Assert.AreEqual (false, project.IsValidated, "A5");
135 Assert.AreEqual (engine, project.ParentEngine, "A6");
136 Assert.IsTrue (time <= project.TimeOfLastDirty, "A7");
137 Assert.IsTrue (String.Empty != project.Xml, "A8");
141 [Category ("NotWorking")]
142 public void TestAddNewImport1 ()
147 string documentString = @"
148 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
152 <Import Project='Test/resources/Import.csproj' />
156 engine = new Engine (Consts.BinPath);
157 project = engine.CreateNewProject ();
158 project.LoadXml (documentString);
160 project.AddNewImport ("a", "true");
161 // reevaluation wasn't caused by anything so it has only old import
162 Assert.AreEqual (1, project.Imports.Count, "A1");
166 [Ignore ("Too detailed probably (implementation specific)")]
167 public void TestAddNewItem1 ()
171 BuildItemGroup [] groups = new BuildItemGroup [1];
173 string documentString = @"
174 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
178 engine = new Engine (Consts.BinPath);
179 project = engine.CreateNewProject ();
180 project.LoadXml (documentString);
182 BuildItem item = project.AddNewItem ("A", "B");
184 Assert.AreEqual (1, project.ItemGroups.Count, "A1");
185 project.ItemGroups.CopyTo (groups, 0);
186 Assert.AreEqual (1, groups [0].Count, "A2");
187 Assert.AreEqual ("B", groups [0] [0].Include, "A3");
188 Assert.AreEqual ("B", groups [0] [0].FinalItemSpec, "A4");
189 Assert.AreEqual ("A", groups [0] [0].Name, "A5");
190 //Assert.AreNotSame (item, groups [0] [0], "A6");
191 Assert.IsFalse (object.ReferenceEquals (item, groups [0] [0]), "A6");
193 Assert.AreEqual (1, project.EvaluatedItems.Count, "A7");
194 Assert.AreEqual ("B", project.EvaluatedItems [0].Include, "A8");
195 Assert.AreEqual ("B", project.EvaluatedItems [0].FinalItemSpec, "A9");
196 Assert.AreEqual ("A", project.EvaluatedItems [0].Name, "A10");
197 //Assert.AreNotSame (item, project.EvaluatedItems [0], "A11");
198 Assert.IsFalse (object.ReferenceEquals (item, project.EvaluatedItems [0]), "A11");
202 [Category ("NotWorking")]
203 public void TestAddNewItem2 ()
208 engine = new Engine (Consts.BinPath);
209 project = engine.CreateNewProject ();
211 BuildItem item = project.AddNewItem ("A", "a;b;c");
212 Assert.AreEqual ("a;b;c", item.Include, "A1");
213 Assert.AreEqual ("a", item.FinalItemSpec, "A2");
215 Assert.AreEqual (3, project.EvaluatedItems.Count, "A3");
219 public void TestAddNewItem3 ()
223 BuildItemGroup [] groups = new BuildItemGroup [4];
225 string documentString = @"
226 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
240 engine = new Engine (Consts.BinPath);
241 project = engine.CreateNewProject ();
242 project.LoadXml (documentString);
244 project.AddNewItem ("B", "b");
246 project.ItemGroups.CopyTo (groups, 0);
247 Assert.AreEqual (0, groups [0].Count, "A1");
248 Assert.AreEqual (1, groups [1].Count, "A2");
249 Assert.AreEqual (1, groups [2].Count, "A3");
250 Assert.AreEqual (2, groups [3].Count, "A4");
253 public void TestAddNewItemGroup ()
258 string documentString = @"
259 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
263 engine = new Engine (Consts.BinPath);
264 project = engine.CreateNewProject ();
265 project.LoadXml (documentString);
267 BuildItemGroup big = project.AddNewItemGroup ();
268 Assert.IsNotNull (big, "A1");
269 Assert.AreEqual (String.Empty, big.Condition, "A2");
270 Assert.AreEqual (0, big.Count, "A3");
271 Assert.AreEqual (false, big.IsImported, "A4");
272 Assert.IsTrue (project.IsDirty, "A5");
276 public void TestAddNewPropertyGroup ()
281 string documentString = @"
282 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
286 engine = new Engine (Consts.BinPath);
287 project = engine.CreateNewProject ();
288 project.LoadXml (documentString);
290 BuildPropertyGroup bpg = project.AddNewPropertyGroup (false);
291 Assert.IsNotNull (bpg, "A1");
292 Assert.AreEqual (String.Empty, bpg.Condition, "A2");
293 Assert.AreEqual (0, bpg.Count, "A3");
294 Assert.AreEqual (false, bpg.IsImported, "A4");
295 Assert.IsTrue (project.IsDirty, "A5");
299 public void TestBuild0 ()
303 IDictionary hashtable = new Hashtable ();
305 string documentString = @"
306 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
316 engine = new Engine (Consts.BinPath);
317 project = engine.CreateNewProject ();
318 project.LoadXml (documentString);
320 Assert.AreEqual (true, project.Build (new string [] { "Main" }, hashtable), "A1");
321 Assert.AreEqual (1, hashtable.Count, "A2");
323 IDictionaryEnumerator e = hashtable.GetEnumerator ();
326 string name = (string) e.Key;
327 Assert.AreEqual ("Main", name, "A3");
328 ITaskItem [] arr = (ITaskItem []) e.Value;
330 Assert.AreEqual (3, arr.Length, "A4");
331 Assert.AreEqual ("d", arr [0].ItemSpec, "A5");
332 Assert.AreEqual ("e", arr [1].ItemSpec, "A6");
333 Assert.AreEqual ("f", arr [2].ItemSpec, "A7");
337 public void TestBuild1 ()
341 IDictionary hashtable = new Hashtable ();
343 string documentString = @"
344 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
346 <Microsoft.Build.Tasks.Message Text='Text' />
351 engine = new Engine (Consts.BinPath);
352 project = engine.CreateNewProject ();
353 project.LoadXml (documentString);
355 Assert.AreEqual (true, project.Build (new string[] { "Main" }, hashtable), "A1");
356 Assert.AreEqual (1, hashtable.Count, "A2");
358 IDictionaryEnumerator e = hashtable.GetEnumerator ();
361 string name = (string) e.Key;
362 Assert.AreEqual ("Main", name, "A3");
363 Assert.IsNotNull ((ITaskItem []) e.Value, "A4");
367 public void TestBuild2 ()
372 string documentString = @"
373 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
374 <Target Name='T' Inputs='Test\resources\TestTasks.cs' Outputs='Test\resources\TestTasks.dll'>
375 <Message Text='text' />
380 engine = new Engine (Consts.BinPath);
381 TestLogger tl = new TestLogger ();
382 engine.RegisterLogger (tl);
383 project = engine.CreateNewProject ();
384 project.LoadXml (documentString);
389 Assert.AreEqual (2, tl.TargetStartedEvents, "A1");
390 Assert.AreEqual (2, tl.TargetFinishedEvents, "A2");
394 public void TestBuild3 ()
399 string documentString = @"
400 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
401 <Target Name='T' Inputs='Test\resources\TestTasks.cs' Outputs='Test\resources\TestTasks.dll'>
402 <Message Text='text' />
407 engine = new Engine (Consts.BinPath);
408 TestLogger tl = new TestLogger ();
409 engine.RegisterLogger (tl);
410 project = engine.CreateNewProject ();
411 project.LoadXml (documentString);
413 project.Build (new string [1] { "T" }, null, BuildSettings.None);
414 project.Build (new string [1] { "T" }, null, BuildSettings.None);
416 Assert.AreEqual (2, tl.TargetStartedEvents, "A1");
417 Assert.AreEqual (2, tl.TargetFinishedEvents, "A2");
421 [Category ("NotWorking")]
422 public void TestBuild4 ()
427 string documentString = @"
428 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
429 <Target Name='T' Inputs='Test\resources\TestTasks.cs' Outputs='Test\resources\TestTasks.dll'>
430 <Message Text='text' />
435 engine = new Engine (Consts.BinPath);
436 TestLogger tl = new TestLogger ();
437 engine.RegisterLogger (tl);
438 project = engine.CreateNewProject ();
439 project.LoadXml (documentString);
441 project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets);
442 project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets);
444 Assert.AreEqual (1, tl.TargetStartedEvents, "A1");
445 Assert.AreEqual (1, tl.TargetFinishedEvents, "A2");
449 public void TestBuild5 ()
454 string documentString = @"
455 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
459 engine = new Engine (Consts.BinPath);
460 project = engine.CreateNewProject ();
461 project.LoadXml (documentString);
463 Assert.IsFalse (project.Build ("target_that_doesnt_exist"));
467 public void TestEvaluatedItems1 ()
472 string documentString = @"
473 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
476 <B Include='b' Condition='false' />
481 engine = new Engine (Consts.BinPath);
482 project = engine.CreateNewProject ();
483 project.LoadXml (documentString);
485 Assert.AreEqual (1, project.EvaluatedItems.Count, "A1");
487 BuildItem bi = project.EvaluatedItems [0];
492 BuildItemGroup [] big = new BuildItemGroup [1];
493 project.ItemGroups.CopyTo (big, 0);
494 Assert.AreEqual ("C", big [0] [0].Name, "A2");
495 Assert.AreEqual ("c", big [0] [0].Include, "A3");
499 public void TestEvaluatedItems2 ()
504 string documentString = @"
505 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
507 <A Include='a;b;c' />
512 engine = new Engine (Consts.BinPath);
513 project = engine.CreateNewProject ();
514 project.LoadXml (documentString);
516 BuildItemGroup [] big = new BuildItemGroup [1];
517 project.ItemGroups.CopyTo (big, 0);
519 Assert.AreEqual (3, project.EvaluatedItems.Count, "A1");
520 Assert.AreEqual ("a;b;c", big [0] [0].Include, "A2");
521 Assert.AreEqual (1, big [0].Count, "A3");
523 BuildItem bi = project.EvaluatedItems [0];
527 Assert.AreEqual (3, big [0].Count, "A4");
528 Assert.AreEqual ("d", big [0] [0].Include, "A5");
529 Assert.AreEqual ("b", big [0] [1].Include, "A6");
530 Assert.AreEqual ("c", big [0] [2].Include, "A7");
534 [Category ("NotWorking")]
535 public void TestGetConditionedPropertyValues ()
540 string documentString = @"
541 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
542 <PropertyGroup Condition='true'>
544 <B Condition='true'>A</B>
547 <C Condition='true'>A</C>
548 <C Condition='false'>B</C>
549 <C Condition='!false'>C</C>
551 <E Condition="" '$(C)' == 'A' "">E</E>
556 engine = new Engine (Consts.BinPath);
557 project = engine.CreateNewProject ();
558 project.LoadXml (documentString);
560 Assert.AreEqual (0, project.GetConditionedPropertyValues ("A").Length, "A1");
561 Assert.AreEqual (0, project.GetConditionedPropertyValues ("B").Length, "A2");
562 Assert.AreEqual (1, project.GetConditionedPropertyValues ("C").Length, "A3");
563 Assert.AreEqual (0, project.GetConditionedPropertyValues ("D").Length, "A4");
564 Assert.AreEqual (0, project.GetConditionedPropertyValues ("E").Length, "A5");
565 Assert.AreEqual ("A", project.GetConditionedPropertyValues ("C") [0], "A6");
569 [ExpectedException (typeof (ArgumentNullException))]
570 public void TestGetEvaluatedItemsByName1 ()
575 string documentString = @"
576 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
580 engine = new Engine (Consts.BinPath);
581 project = engine.CreateNewProject ();
582 project.LoadXml (documentString);
584 project.GetEvaluatedItemsByName (null);
588 public void TestGetEvaluatedItemsByName2 ()
593 string documentString = @"
594 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
597 <B Include='2' Condition='true' />
598 <C Include='3' Condition='false' />
603 engine = new Engine (Consts.BinPath);
604 project = engine.CreateNewProject ();
605 project.LoadXml (documentString);
609 big = project.GetEvaluatedItemsByName (String.Empty);
611 Assert.AreEqual (0, big.Count, "A1");
613 big = project.GetEvaluatedItemsByName ("A");
615 Assert.AreEqual (1, big.Count, "A2");
616 Assert.AreEqual ("1", big [0].FinalItemSpec, "A3");
618 big = project.GetEvaluatedItemsByName ("B");
620 Assert.AreEqual (1, big.Count, "A4");
621 Assert.AreEqual ("2", big [0].FinalItemSpec, "A5");
623 big = project.GetEvaluatedItemsByName ("C");
625 Assert.AreEqual (0, big.Count, "A6");
629 [ExpectedException (typeof (ArgumentNullException))]
630 public void TestGetEvaluatedItemsByNameIgnoringCondition1 ()
635 string documentString = @"
636 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
640 engine = new Engine (Consts.BinPath);
641 project = engine.CreateNewProject ();
642 project.LoadXml (documentString);
644 project.GetEvaluatedItemsByNameIgnoringCondition (null);
648 public void TestGetEvaluatedItemsByNameIgnoringCondition2 ()
653 string documentString = @"
654 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
657 <B Include='2' Condition='true' />
658 <C Include='3' Condition='false' />
663 engine = new Engine (Consts.BinPath);
664 project = engine.CreateNewProject ();
665 project.LoadXml (documentString);
669 big = project.GetEvaluatedItemsByNameIgnoringCondition (String.Empty);
671 Assert.AreEqual (0, big.Count, "A1");
673 big = project.GetEvaluatedItemsByNameIgnoringCondition ("A");
675 Assert.AreEqual (1, big.Count, "A2");
676 Assert.AreEqual ("1", big [0].FinalItemSpec, "A3");
678 big = project.GetEvaluatedItemsByNameIgnoringCondition ("B");
680 Assert.AreEqual (1, big.Count, "A4");
681 Assert.AreEqual ("2", big [0].FinalItemSpec, "A5");
683 big = project.GetEvaluatedItemsByNameIgnoringCondition ("C");
685 Assert.AreEqual (1, big.Count, "A6");
686 Assert.AreEqual ("3", big [0].FinalItemSpec, "A7");
690 [ExpectedException (typeof (ArgumentNullException))]
691 public void TestGetEvaluatedProperty1 ()
696 string documentString = @"
697 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
701 engine = new Engine (Consts.BinPath);
702 project = engine.CreateNewProject ();
703 project.LoadXml (documentString);
705 project.GetEvaluatedProperty (null);
708 public void TestGetEvaluatedProperty2 ()
713 string documentString = @"
714 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
717 <B Condition='true'>2</B>
718 <C Condition='false'>3</C>
723 engine = new Engine (Consts.BinPath);
724 project = engine.CreateNewProject ();
725 project.LoadXml (documentString);
727 Assert.AreEqual ("1", project.GetEvaluatedProperty ("A"), "A1");
728 Assert.AreEqual ("2", project.GetEvaluatedProperty ("B"), "A2");
729 Assert.IsNull (project.GetEvaluatedProperty ("C"), "A3");
733 public void TestGetProjectExtensions ()
738 string documentString = @"
739 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
746 engine = new Engine (Consts.BinPath);
747 project = engine.CreateNewProject ();
748 project.LoadXml (documentString);
750 Assert.AreEqual (String.Empty, project.GetProjectExtensions (null), "A1");
751 Assert.AreEqual (String.Empty, project.GetProjectExtensions (String.Empty), "A2");
752 Assert.AreEqual (String.Empty, project.GetProjectExtensions ("something"), "A3");
753 Assert.AreEqual ("Text", project.GetProjectExtensions ("Node"), "A4");
757 public void TestGlobalProperties1 ()
762 string documentString = @"
763 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
767 engine = new Engine (Consts.BinPath);
768 project = engine.CreateNewProject ();
769 project.LoadXml (documentString);
771 Assert.AreEqual (0, project.GlobalProperties.Count, "A1");
775 public void TestGlobalProperties2 ()
780 string documentString = @"
781 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
785 engine = new Engine (Consts.BinPath);
786 engine.GlobalProperties.SetProperty ("Property", "Value");
788 project = engine.CreateNewProject ();
789 project.LoadXml (documentString);
791 Assert.AreEqual (1, project.GlobalProperties.Count, "A1");
792 Assert.AreEqual ("Property", project.GlobalProperties ["Property"].Name, "A2");
793 Assert.AreEqual ("Value", project.GlobalProperties ["Property"].Value, "A3");
794 Assert.AreEqual ("Value", project.GlobalProperties ["Property"].FinalValue, "A4");
795 Assert.AreEqual ("Property", project.EvaluatedProperties ["Property"].Name, "A2");
796 Assert.AreEqual ("Value", project.EvaluatedProperties ["Property"].Value, "A3");
797 Assert.AreEqual ("Value", project.EvaluatedProperties ["Property"].FinalValue, "A4");
801 [Category ("NotDotNet")]
802 [ExpectedException (typeof (ArgumentNullException))]
803 public void TestGlobalProperties3 ()
808 string documentString = @"
809 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
813 engine = new Engine (Consts.BinPath);
814 project = engine.CreateNewProject ();
815 project.LoadXml (documentString);
817 project.GlobalProperties = null;
821 [Ignore ("needs rewriting")]
822 public void TestGlobalProperties4 ()
827 string documentString = @"
828 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
830 <Property>a</Property>
835 engine = new Engine (Consts.BinPath);
836 project = engine.CreateNewProject ();
837 project.LoadXml (documentString);
839 BuildPropertyGroup[] groups = new BuildPropertyGroup [1];
840 project.PropertyGroups.CopyTo (groups, 0);
842 project.GlobalProperties = groups [0];
843 project.GlobalProperties = project.EvaluatedProperties;
847 [Category ("NotDotNet")]
848 [ExpectedException (typeof (InvalidOperationException))]
849 public void TestGlobalProperties5 ()
854 string documentString = @"
855 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
857 <Property>a</Property>
862 engine = new Engine (Consts.BinPath);
863 project = engine.CreateNewProject ();
864 project.LoadXml (documentString);
866 BuildPropertyGroup[] groups = new BuildPropertyGroup [1];
867 project.PropertyGroups.CopyTo (groups, 0);
868 project.GlobalProperties = groups [0];
872 [ExpectedException (typeof (InvalidProjectFileException))]
873 public void TestLoad1 ()
878 string documentString = @"
879 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
884 engine = new Engine (Consts.BinPath);
885 project = engine.CreateNewProject ();
886 project.LoadXml (documentString);
890 [ExpectedException (typeof (InvalidProjectFileException))]
891 public void TestLoad2 ()
896 engine = new Engine (Consts.BinPath);
897 project = engine.CreateNewProject ();
898 project.LoadXml ("project_file_that_doesnt_exist");
902 public void TestParentEngine ()
907 engine = new Engine (Consts.BinPath);
908 project = engine.CreateNewProject ();
910 Assert.AreEqual (engine, project.ParentEngine, "A1");
914 [Category ("NotDotNet")]
915 [ExpectedException (typeof (ArgumentNullException))]
916 public void TestRemoveItemGroup1 ()
921 engine = new Engine (Consts.BinPath);
922 p1 = engine.CreateNewProject ();
924 p1.RemoveItemGroup (null);
928 [ExpectedException (typeof (InvalidOperationException),
929 "The \"BuildItemGroup\" object specified does not belong to the correct \"Project\" object.")]
930 [Category ("NotWorking")]
931 public void TestRemoveItemGroup2 ()
936 BuildItemGroup [] groups = new BuildItemGroup [1];
938 engine = new Engine (Consts.BinPath);
939 p1 = engine.CreateNewProject ();
940 p2 = engine.CreateNewProject ();
942 p1.AddNewItem ("A", "B");
943 p1.ItemGroups.CopyTo (groups, 0);
945 p2.RemoveItemGroup (groups [0]);
949 [Category ("NotDotNet")]
950 [ExpectedException (typeof (ArgumentNullException))]
951 public void TestRemoveItem1 ()
956 engine = new Engine (Consts.BinPath);
957 project = engine.CreateNewProject ();
959 project.RemoveItem (null);
963 [ExpectedException (typeof (InvalidOperationException),
964 "The object passed in is not part of the project.")]
965 public void TestRemoveItem2 ()
970 engine = new Engine (Consts.BinPath);
971 project = engine.CreateNewProject ();
973 project.RemoveItem (new BuildItem ("name", "include"));
977 [ExpectedException (typeof (InvalidOperationException),
978 "The \"BuildItemGroup\" object specified does not belong to the correct \"Project\" object.")]
979 public void TestRemoveItem3 ()
985 engine = new Engine (Consts.BinPath);
986 p1 = engine.CreateNewProject ();
987 p2 = engine.CreateNewProject ();
989 p1.AddNewItem ("A", "B");
991 p2.RemoveItem (p1.EvaluatedItems [0]);
995 [Category ("NotDotNet")]
996 [ExpectedException (typeof (InvalidOperationException))]
997 public void TestRemoveItem4 ()
1003 engine = new Engine (Consts.BinPath);
1004 p1 = engine.CreateNewProject ();
1005 p2 = engine.CreateNewProject ();
1007 p1.AddNewItem ("A", "B");
1008 p1.AddNewItem ("A", "C");
1010 p2.RemoveItem (p1.EvaluatedItems [0]);
1014 public void TestRemoveItem5 ()
1018 BuildItemGroup [] groups = new BuildItemGroup [1];
1020 string documentString = @"
1021 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1028 engine = new Engine (Consts.BinPath);
1029 project = engine.CreateNewProject ();
1030 project.LoadXml (documentString);
1032 project.RemoveItem (project.EvaluatedItems [0]);
1033 Assert.AreEqual (0, project.EvaluatedItems.Count, "A1");
1034 project.ItemGroups.CopyTo (groups, 0);
1035 Assert.IsNull (groups [0], "A2");
1036 Assert.AreEqual (0, project.ItemGroups.Count, "A3");
1040 [Category ("NotWorking")]
1041 public void TestResetBuildStatus ()
1046 string documentString = @"
1047 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1048 <Target Name='T' Inputs='Test\resources\TestTasks.cs' Outputs='Test\resources\TestTasks.dll'>
1049 <Message Text='text' />
1054 engine = new Engine (Consts.BinPath);
1055 TestLogger tl = new TestLogger ();
1056 engine.RegisterLogger (tl);
1057 project = engine.CreateNewProject ();
1058 project.LoadXml (documentString);
1060 project.Build ("T");
1061 project.ResetBuildStatus ();
1062 project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets);
1064 Assert.AreEqual (2, tl.TargetStartedEvents, "A1");
1065 Assert.AreEqual (2, tl.TargetFinishedEvents, "A1");
1069 public void TestSchemaFile ()
1074 string documentString = @"
1075 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1079 engine = new Engine (Consts.BinPath);
1080 project = engine.CreateNewProject ();
1081 project.LoadXml (documentString);
1083 Assert.IsNull (project.SchemaFile, "A1");
1086 [Category ("NotDotNet")]
1087 [ExpectedException (typeof (ArgumentNullException))]
1088 public void TestSetProjectExtensions1 ()
1093 string documentString = @"
1094 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1098 engine = new Engine (Consts.BinPath);
1099 project = engine.CreateNewProject ();
1100 project.LoadXml (documentString);
1102 project.SetProjectExtensions (null, null);
1106 public void TestSetProjectExtensions2 ()
1111 string documentString = @"
1112 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1116 engine = new Engine (Consts.BinPath);
1117 project = engine.CreateNewProject ();
1118 project.LoadXml (documentString);
1120 project.SetProjectExtensions ("name", "1");
1121 Assert.AreEqual ("1", project.GetProjectExtensions ("name"), "A1");
1122 project.SetProjectExtensions ("name", "2");
1123 Assert.AreEqual ("2", project.GetProjectExtensions ("name"), "A2");
1124 Assert.IsTrue (project.IsDirty, "A3");
1128 public void TestSetProjectExtensions3 ()
1133 string documentString = @"
1134 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1136 </ProjectExtensions>
1140 engine = new Engine (Consts.BinPath);
1141 project = engine.CreateNewProject ();
1142 project.LoadXml (documentString);
1144 project.SetProjectExtensions ("name", "1");
1145 Assert.AreEqual ("1", project.GetProjectExtensions ("name"), "A1");
1146 Assert.IsTrue (project.IsDirty, "A2");
1150 public void TestBuildProjectError1 ()
1152 Engine engine = new Engine (Consts.BinPath);
1153 Project project = engine.CreateNewProject ();
1155 Assert.IsFalse (project.Build ((string) null), "A1");
1156 Assert.IsFalse (project.Build ((string[]) null), "A2");
1157 Assert.IsFalse (project.Build ((string []) null, null), "A3");
1158 Assert.IsFalse (project.Build ((string []) null, null, BuildSettings.None), "A4");
1162 public void TestBuildProjectError2 ()
1164 Engine engine = new Engine (Consts.BinPath);
1165 Project project = engine.CreateNewProject ();
1168 project.Build (new string [] { null });
1172 Assert.Fail ("Expected exception for project.Build, null string in targetNames []");
1176 public void TestBuildProjectFile1 ()
1178 Project project = CreateAndLoadProject ("foo.proj", false, new string [] { "1", "2" }, new bool [] { true, true }, "TBPF1");
1179 CheckProjectBuild (project, new string [] { "main" }, true, new string [] { "main" }, "TBPF1");
1183 public void TestBuildProjectFileXml1 ()
1185 Project project = CreateAndLoadProject (null, false, new string [] { "1", "2" }, new bool [] { true, true }, "TBPFX1");
1186 CheckProjectBuild (project, new string [] { "main" }, true, new string [] { "main" }, "TBPFX1");
1190 public void TestBuildProjectFile2 ()
1192 Project project = CreateAndLoadProject ("foo.proj", false, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPF2");
1193 CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPF2");
1197 public void TestBuildProjectFileXml2 ()
1199 Project project = CreateAndLoadProject (null, false, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPFX2");
1200 CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPFX2");
1204 public void TestBuildProjectFile3 ()
1206 Project project = CreateAndLoadProject ("foo.proj", false, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPF3");
1207 CheckProjectBuild (project, new string [] { "1", "2" }, true, new string [] { "1", "2" }, "TBPF3");
1211 public void TestBuildProjectFileXml3 ()
1213 Project project = CreateAndLoadProject (null, false, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPFX3");
1214 CheckProjectBuild (project, new string [] { "1", "2" }, true, new string [] { "1", "2" }, "TBPFX3");
1218 public void TestBuildProjectFile4 ()
1220 Project project = CreateAndLoadProject ("foo.proj", false, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPF4");
1221 CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPF4");
1225 public void TestBuildProjectFileXml4 ()
1227 Project project = CreateAndLoadProject (null, false, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPFX4");
1228 CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPFX4");
1231 //Run separate tests
1235 public void TestBuildProjectFile5 ()
1237 Project project = CreateAndLoadProject ("foo.proj", true, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPF5");
1238 CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPF5");
1242 public void TestBuildProjectFileXml5 ()
1244 Project project = CreateAndLoadProject (null, true, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPFX5");
1245 CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPFX5");
1249 public void TestBuildProjectFile6 ()
1251 Project project = CreateAndLoadProject ("foo.proj", true, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPF6");
1252 CheckProjectBuild (project, new string [] { "main" }, true, new string [] { "main" }, "TBPF6");
1256 public void TestBuildProjectFileXml6 ()
1258 Project project = CreateAndLoadProject (null, true, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPFX6");
1259 CheckProjectBuild (project, new string [] { "main" }, true, new string [] { "main" }, "TBPFX6");
1262 // run multiple targets
1264 public void TestBuildProjectFile7 ()
1266 Project project = CreateAndLoadProject ("foo.proj", true, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPF7");
1267 CheckProjectBuild (project, new string [] { "1", "2", "3" }, true, new string [] { "1", "2", "3" }, "TBPF7");
1271 public void TestBuildProjectFileXml7 ()
1273 Project project = CreateAndLoadProject (null, true, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPFX7");
1274 CheckProjectBuild (project, new string [] { "1", "2", "3" }, true, new string [] { "1", "2", "3" }, "TBPFX7");
1278 public void TestBuildProjectFile8 ()
1280 Project project = CreateAndLoadProject ("foo.proj", true, new string [] { "1", "2", "3" }, new bool [] { true, true, false }, "TBPF8");
1281 CheckProjectBuild (project, new string [] { "1", "2", "3" }, false, new string [] { "1", "2"}, "TBPF8");
1285 public void TestBuildProjectFileXml8 ()
1287 Project project = CreateAndLoadProject (null, true, new string [] { "1", "2", "3" }, new bool [] { true, true, false }, "TBPFX8");
1288 CheckProjectBuild (project, new string [] { "1", "2", "3" }, false, new string [] { "1", "2"}, "TBPFX8");
1292 public void TestBatchedMetadataRef1 ()
1294 //test for multiple items with same metadata also
1295 string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1296 <UsingTask TaskName=""BatchingTestTask"" AssemblyFile=""Test/resources/TestTasks.dll"" />
1298 <Coll1 Include=""A1""><Name>Abc</Name></Coll1>
1299 <Coll1 Include=""A2""><Name>Def</Name></Coll1>
1300 <Coll1 Include=""A3""><Name>Xyz</Name></Coll1>
1301 <Coll1 Include=""A4""><Name>Xyz</Name></Coll1>
1302 <Coll2 Include=""B1""></Coll2>
1304 <Target Name=""ShowMessage"">
1305 <BatchingTestTask Sources=""%(Coll1.Name)"">
1306 <Output TaskParameter=""Output"" ItemName=""FinalList"" />
1308 <Message Text=""Msg: %(Coll1.Name)"" />
1312 Engine engine = new Engine (Consts.BinPath);
1313 Project project = engine.CreateNewProject ();
1315 project.LoadXml (projectString);
1316 Assert.IsTrue (project.Build ("ShowMessage"), "A1: Build failed");
1318 BuildItemGroup include = project.GetEvaluatedItemsByName ("FinalList");
1319 Assert.AreEqual (3, include.Count, "A2");
1321 Assert.AreEqual ("FinalList", include [0].Name, "A3");
1322 Assert.AreEqual ("Abc", include [0].FinalItemSpec, "A4");
1324 Assert.AreEqual ("FinalList", include [1].Name, "A5");
1325 Assert.AreEqual ("Def", include [1].FinalItemSpec, "A6");
1327 Assert.AreEqual ("FinalList", include [2].Name, "A7");
1328 Assert.AreEqual ("Xyz", include [2].FinalItemSpec, "A8");
1332 public void TestBatchedMetadataRef2 ()
1334 string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1335 <UsingTask TaskName=""BatchingTestTask"" AssemblyFile=""Test/resources/TestTasks.dll"" />
1337 <Coll1 Include=""A1""><Name>Abc</Name></Coll1>
1338 <Coll1 Include=""A2""><Name>Def</Name></Coll1>
1339 <Coll1 Include=""A3""><Name>Xyz</Name></Coll1>
1340 <Coll1 Include=""A4""><Name>Abc</Name></Coll1>
1341 <Coll2 Include=""B1""><Name>Bar</Name></Coll2>
1342 <Coll2 Include=""B2""><Name>Bar</Name></Coll2>
1344 <Target Name=""ShowMessage"">
1345 <BatchingTestTask Sources=""%(Name)"" Strings=""@(Coll2)"">
1346 <Output TaskParameter=""Output"" ItemName=""FinalList"" />
1348 <Message Text=""Msg: %(Coll1.Name)"" />
1350 <Target Name=""ShowMessage2"">
1351 <BatchingTestTask Sources=""%(Name)"" Strings=""@(Coll1)"">
1352 <Output TaskParameter=""Output"" ItemName=""FinalList2"" />
1354 <Message Text=""Msg: %(Coll1.Name)"" />
1358 Engine engine = new Engine (Consts.BinPath);
1359 Project project = engine.CreateNewProject ();
1361 project.LoadXml (projectString);
1362 Assert.IsTrue (project.Build ("ShowMessage"), "A1: Build failed");
1364 BuildItemGroup include = project.GetEvaluatedItemsByName ("FinalList");
1365 Assert.AreEqual (1, include.Count, "A2");
1367 Assert.AreEqual ("FinalList", include [0].Name, "A3");
1368 Assert.AreEqual ("Bar", include [0].FinalItemSpec, "A4");
1370 Assert.IsTrue (project.Build ("ShowMessage2"), "A1: Build failed");
1371 include = project.GetEvaluatedItemsByName ("FinalList2");
1372 Assert.AreEqual (3, include.Count, "A5");
1374 Assert.AreEqual ("FinalList2", include [0].Name, "A6");
1375 Assert.AreEqual ("Abc", include [0].FinalItemSpec, "A7");
1377 Assert.AreEqual ("FinalList2", include [1].Name, "A8");
1378 Assert.AreEqual ("Def", include [1].FinalItemSpec, "A9");
1380 Assert.AreEqual ("FinalList2", include [2].Name, "A10");
1381 Assert.AreEqual ("Xyz", include [2].FinalItemSpec, "A11");
1385 public void TestBatchedMetadataRef3 ()
1387 string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1388 <UsingTask TaskName=""BatchingTestTask"" AssemblyFile=""Test/resources/TestTasks.dll"" />
1390 <Coll1 Include=""A1""><Name>Abc</Name></Coll1>
1391 <Coll1 Include=""A2""><Name>Def</Name></Coll1>
1392 <Coll1 Include=""A3""><Name>Xyz</Name></Coll1>
1393 <Coll1 Include=""A4""><Name>Abc</Name></Coll1>
1394 <Coll2 Include=""B1""><Name>Bar</Name></Coll2>
1395 <Coll2 Include=""B2""><Name>Bar</Name></Coll2>
1397 <Target Name=""ShowMessage"">
1398 <BatchingTestTask SingleTaskItem=""%(Coll2.Name)"" >
1399 <Output TaskParameter=""SingleStringOutput"" ItemName=""FinalList"" />
1401 <Message Text=""Msg: %(Coll1.Name)"" />
1405 Engine engine = new Engine (Consts.BinPath);
1406 Project project = engine.CreateNewProject ();
1408 project.LoadXml (projectString);
1409 Assert.IsTrue (project.Build ("ShowMessage"), "A1: Build failed");
1411 BuildItemGroup include = project.GetEvaluatedItemsByName ("FinalList");
1412 Assert.AreEqual (1, include.Count, "A2");
1414 Assert.AreEqual ("FinalList", include [0].Name, "A3");
1415 Assert.AreEqual ("Bar", include [0].FinalItemSpec, "A4");
1420 public void TestBatchedMetadataRef4 ()
1422 string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1423 <UsingTask TaskName=""BatchingTestTask"" AssemblyFile=""Test/resources/TestTasks.dll"" />
1425 <Coll1 Include=""A1""><Name>Abc</Name></Coll1>
1426 <Coll1 Include=""A2""><Name>Def</Name></Coll1>
1427 <Coll1 Include=""A3""><Name>Xyz</Name></Coll1>
1428 <Coll2 Include=""B1""><Name>Bar</Name></Coll2>
1430 <Target Name=""ShowMessage"">
1431 <BatchingTestTask SingleTaskItem=""%(Coll3.Name)"" >
1432 <Output TaskParameter=""SingleStringOutput"" ItemName=""FinalList"" />
1437 Engine engine = new Engine (Consts.BinPath);
1438 Project project = engine.CreateNewProject ();
1440 project.LoadXml (projectString);
1441 Assert.IsTrue (project.Build ("ShowMessage"), "A1: Build failed");
1443 BuildItemGroup include = project.GetEvaluatedItemsByName ("FinalList");
1444 Assert.AreEqual (0, include.Count, "A2");
1448 public void TestBatchedMetadataRef5 ()
1450 string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1451 <UsingTask TaskName=""BatchingTestTask"" AssemblyFile=""Test/resources/TestTasks.dll"" />
1453 <Coll1 Include=""A1""><Name>Abc</Name></Coll1>
1454 <Coll1 Include=""A2""><Name>Def</Name></Coll1>
1455 <Coll1 Include=""A3""><Name>Xyz</Name></Coll1>
1456 <Coll2 Include=""B1""><Name>Bar</Name></Coll2>
1458 <Target Name=""ShowMessage"">
1459 <Message Text=""Coll1: @(Coll1->'Foo%(Name)Bar')"" />
1460 <BatchingTestTask Sources=""@(Coll1->'Foo%(Name)Bar')"" >
1461 <Output TaskParameter=""Output"" ItemName=""FinalList"" />
1466 Engine engine = new Engine (Consts.BinPath);
1467 Project project = engine.CreateNewProject ();
1468 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
1469 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
1470 engine.RegisterLogger (logger);
1472 project.LoadXml (projectString);
1473 bool result = project.Build ("ShowMessage");
1475 logger.DumpMessages ();
1476 Assert.Fail ("A1: Build failed");
1478 logger.DumpMessages ();
1479 BuildItemGroup include = project.GetEvaluatedItemsByName ("FinalList");
1480 Assert.AreEqual (3, include.Count, "A2");
1484 public void TestInitialTargets ()
1486 Engine engine = new Engine (Consts.BinPath);
1487 Project project = engine.CreateNewProject ();
1489 project.LoadXml (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" InitialTargets=""pre "">
1490 <Target Name=""boo"">
1491 <Message Text=""Executing boo target""/>
1493 <Target Name=""pre"">
1494 <Message Text=""Executing pre target""/>
1498 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
1499 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
1500 engine.RegisterLogger (logger);
1503 Assert.IsTrue (project.Build (), "Build failed");
1505 Assert.AreEqual (0, logger.CheckHead ("Executing pre target", MessageImportance.Normal), "A1");
1506 Assert.AreEqual (0, logger.CheckHead ("Executing boo target", MessageImportance.Normal), "A2");
1507 Assert.AreEqual (0, logger.Count, "A3");
1509 logger.DumpMessages ();
1515 public void TestRequiredTask_String1 ()
1517 CheckProjectForRequiredTests ("RequiredTestTask_String", "@(NonExistant)",
1518 false, "Should've failed: No value specified for required field - 'Property' of RequiredTestTask_String");
1522 public void TestRequiredTask_String2 ()
1524 CheckProjectForRequiredTests ("RequiredTestTask_String", "$(NonExistant)",
1525 false, "Should've failed: No value specified for required field - 'Property' of RequiredTestTask_String");
1529 public void TestRequiredTask_TaskItem1 ()
1531 Project p = CheckProjectForRequiredTests ("RequiredTestTask_TaskItem", "@(NonExistant)",
1532 false, "Should've failed: No value specified for required field - 'Property' of RequiredTestTask_TaskItem");
1536 public void TestRequiredTask_TaskItem2 ()
1538 Project p = CheckProjectForRequiredTests ("RequiredTestTask_TaskItem", "$(NonExistant)",
1539 false, "Should've failed: No value specified for required field - 'Property' of RequiredTestTask_TaskItem");
1543 public void TestRequiredTask_TaskItemArray1 ()
1545 Project p = CheckProjectForRequiredTests ("RequiredTestTask_TaskItems", "@(NonExistant)",
1546 true, "Build failed");
1548 BuildItemGroup group = p.GetEvaluatedItemsByName ("OutItem");
1549 Assert.AreEqual (1, group.Count, "A2");
1550 Assert.AreEqual ("count: 0", group [0].FinalItemSpec, "A3");
1554 public void TestRequiredTask_TaskItemArray2 ()
1556 Project p = CheckProjectForRequiredTests ("RequiredTestTask_TaskItems", "$(NonExistant)",
1557 true, "Build failed");
1559 BuildItemGroup group = p.GetEvaluatedItemsByName ("OutItem");
1560 Assert.AreEqual (1, group.Count, "A2");
1561 Assert.AreEqual ("count: 0", group [0].FinalItemSpec, "A3");
1565 public void TestRequiredTask_TaskItemArray3 ()
1567 Project p = CheckProjectForRequiredTests ("RequiredTestTask_IntArray", "$(NonExistant)",
1568 true, "Build failed");
1570 BuildItemGroup group = p.GetEvaluatedItemsByName ("OutItem");
1571 Assert.AreEqual (1, group.Count, "A2");
1572 Assert.AreEqual ("count: 0", group [0].FinalItemSpec, "A3");
1576 Project CheckProjectForRequiredTests (string taskname, string property_arg, bool expected_result, string error_msg)
1578 string projectString = String.Format (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1579 <UsingTask TaskName=""{0}"" AssemblyFile=""Test/resources/TestTasks.dll"" />
1580 <Target Name=""foo"">
1581 <{0} Property=""{1}"">
1582 <Output TaskParameter=""Output"" ItemName=""OutItem""/>
1585 </Project>", taskname, property_arg);
1587 Engine engine = new Engine (Consts.BinPath);
1588 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
1589 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
1590 engine.RegisterLogger (logger);
1591 Project project = engine.CreateNewProject ();
1592 project.LoadXml (projectString);
1595 Assert.AreEqual (expected_result, project.Build (), error_msg);
1597 logger.DumpMessages ();
1602 static void CheckBuildItem (BuildItem item, string name, string [,] metadata, string finalItemSpec, string prefix)
1604 Assert.AreEqual (name, item.Name, prefix + "#1");
1605 for (int i = 0; i < metadata.GetLength (0); i++) {
1606 string key = metadata [i, 0];
1607 string val = metadata [i, 1];
1608 Assert.IsTrue (item.HasMetadata (key), String.Format ("{0}#2: Expected metadata '{1}' not found", prefix, key));
1609 Assert.AreEqual (val, item.GetMetadata (key), String.Format ("{0}#3: Value for metadata {1}", prefix, key));
1610 Assert.AreEqual (val, item.GetEvaluatedMetadata (key), String.Format ("{0}#4: Value for evaluated metadata {1}", prefix, key));
1612 Assert.AreEqual (finalItemSpec, item.FinalItemSpec, prefix + "#5");
1615 void CheckProjectBuild (Project project, string [] targetNames, bool result, string [] outputNames, string prefix)
1617 IDictionary targetOutputs = new Hashtable ();
1619 Assert.AreEqual (result, project.Build (targetNames, targetOutputs), prefix + "A1");
1620 Assert.AreEqual (outputNames.Length, targetOutputs.Keys.Count, prefix + "A2");
1622 foreach (string outputName in outputNames) {
1623 Assert.IsTrue (targetOutputs.Contains (outputName), prefix + " A3: target " + outputName);
1625 object o = targetOutputs [outputName];
1626 Assert.IsTrue (typeof (ITaskItem []).IsAssignableFrom (o.GetType ()), prefix + " A4: target " + outputName);
1628 ITaskItem [] items = (ITaskItem [])o;
1629 Assert.AreEqual (0, items.Length, prefix + "A5: target " + outputName);
1633 string CreateProjectString (bool run_separate, string [] targets, bool [] results, string prefix)
1635 StringBuilder sb = new StringBuilder ();
1636 sb.Append (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">");
1637 sb.AppendFormat ("<Target Name = \"{0}\"><Message Text = \"#Target {1}:{0} called\" />", "main", prefix);
1639 sb.AppendFormat ("<CallTarget Targets=\"");
1640 for (int i = 0; i < targets.Length; i++)
1641 sb.AppendFormat ("{0};", targets [i]);
1642 sb.AppendFormat ("\" ");
1645 sb.AppendFormat (" RunEachTargetSeparately=\"true\" ");
1646 sb.AppendFormat ("/></Target>\n");
1648 for (int i = 0; i < targets.Length; i++) {
1649 sb.AppendFormat ("<Target Name = \"{0}\"><Message Text = \"#Target {1}:{0} called\" />", targets [i], prefix);
1651 sb.AppendFormat ("<Error Text = \"#Error message for target {0}:{1}\"/>", prefix, targets [i]);
1652 sb.Append ("</Target>\n");
1655 sb.Append ("</Project>");
1657 return sb.ToString ();
1660 void CreateProjectFile (string fname, bool run_separate, string [] targets, bool [] results, string prefix)
1662 using (StreamWriter sw = new StreamWriter (fname))
1663 sw.Write (CreateProjectString (run_separate, targets, results, prefix));
1666 Project CreateAndLoadProject (string fname, bool run_separate, string [] targets, bool [] results, string prefix)
1668 Engine engine = new Engine (Consts.BinPath);
1669 Project project = engine.CreateNewProject ();
1671 string projectXml = CreateProjectString (run_separate, targets, results, prefix);
1672 if (fname == null) {
1673 project.LoadXml (projectXml);
1675 using (StreamWriter sw = new StreamWriter (fname))
1676 sw.Write (projectXml);
1677 project.Load (fname);
1678 File.Delete (fname);