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 using MBT = MonoTests.Microsoft.Build.Tasks;
41 namespace MonoTests.Microsoft.Build.BuildEngine {
43 class TestLogger : Logger {
44 int target_started_events = 0;
45 int target_finished_events = 0;
47 public override void Initialize (IEventSource eventSource)
49 eventSource.TargetStarted += new TargetStartedEventHandler(TargetStarted);
50 eventSource.TargetFinished += new TargetFinishedEventHandler(TargetFinished);
51 eventSource.MessageRaised += new BuildMessageEventHandler(Message);
52 eventSource.WarningRaised += new BuildWarningEventHandler(Warning);
55 void TargetStarted (object sender, TargetStartedEventArgs args)
57 target_started_events++;
60 void TargetFinished (object sender, TargetFinishedEventArgs args)
62 target_finished_events++;
65 void Message (object sender, BuildMessageEventArgs args)
69 void Warning (object sender, BuildWarningEventArgs args)
73 public int TargetStartedEvents { get { return target_started_events; } }
75 public int TargetFinishedEvents { get { return target_finished_events; } }
79 public class ProjectTest {
82 Import [] GetImports (ImportCollection ic)
84 List<Import> list = new List<Import> ();
85 foreach (Import i in ic)
87 return list.ToArray ();
92 public void TestAssignment1 ()
96 string documentString =
97 "<Project></Project>";
99 engine = new Engine (Consts.BinPath);
100 DateTime time = DateTime.Now;
101 project = engine.CreateNewProject ();
103 project.LoadXml (documentString);
104 } catch (InvalidProjectFileException) {
105 Assert.AreEqual (true, project.BuildEnabled, "A1");
106 Assert.AreEqual (String.Empty, project.DefaultTargets, "A2");
107 Assert.AreEqual (String.Empty, project.FullFileName, "A3");
108 Assert.AreEqual (false, project.IsDirty, "A4");
109 Assert.AreEqual (false, project.IsValidated, "A5");
110 Assert.AreEqual (engine, project.ParentEngine, "A6");
111 Console.WriteLine ("time: {0} p.t: {1}", time, project.TimeOfLastDirty);
112 Assert.IsTrue (time <= project.TimeOfLastDirty, "A7");
113 Assert.IsTrue (String.Empty != project.Xml, "A8");
117 Assert.Fail ("Expected InvalidProjectFileException");
121 public void TestAssignment2 ()
125 string documentString =
126 "<Project xmlns=\"http://schemas.microsoft.com/developer/msbuild/2003\"></Project>";
128 engine = new Engine (Consts.BinPath);
129 DateTime time = DateTime.Now;
130 project = engine.CreateNewProject ();
131 project.LoadXml (documentString);
133 Assert.AreEqual (true, project.BuildEnabled, "A1");
134 Assert.AreEqual (String.Empty, project.DefaultTargets, "A2");
135 Assert.AreEqual (String.Empty, project.FullFileName, "A3");
136 Assert.AreEqual (true, project.IsDirty, "A4");
137 Assert.AreEqual (false, project.IsValidated, "A5");
138 Assert.AreEqual (engine, project.ParentEngine, "A6");
139 Assert.IsTrue (time <= project.TimeOfLastDirty, "A7");
140 Assert.IsTrue (String.Empty != project.Xml, "A8");
144 [Category ("NotWorking")]
145 public void TestAddNewImport1 ()
150 string documentString = @"
151 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
155 <Import Project='Test/resources/Import.csproj' />
159 engine = new Engine (Consts.BinPath);
160 project = engine.CreateNewProject ();
161 project.LoadXml (documentString);
163 project.AddNewImport ("a", "true");
164 // reevaluation wasn't caused by anything so it has only old import
165 Assert.AreEqual (1, project.Imports.Count, "A1");
169 [Ignore ("Too detailed probably (implementation specific)")]
170 public void TestAddNewItem1 ()
174 BuildItemGroup [] groups = new BuildItemGroup [1];
176 string documentString = @"
177 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
181 engine = new Engine (Consts.BinPath);
182 project = engine.CreateNewProject ();
183 project.LoadXml (documentString);
185 BuildItem item = project.AddNewItem ("A", "B");
187 Assert.AreEqual (1, project.ItemGroups.Count, "A1");
188 project.ItemGroups.CopyTo (groups, 0);
189 Assert.AreEqual (1, groups [0].Count, "A2");
190 Assert.AreEqual ("B", groups [0] [0].Include, "A3");
191 Assert.AreEqual ("B", groups [0] [0].FinalItemSpec, "A4");
192 Assert.AreEqual ("A", groups [0] [0].Name, "A5");
193 //Assert.AreNotSame (item, groups [0] [0], "A6");
194 Assert.IsFalse (object.ReferenceEquals (item, groups [0] [0]), "A6");
196 Assert.AreEqual (1, project.EvaluatedItems.Count, "A7");
197 Assert.AreEqual ("B", project.EvaluatedItems [0].Include, "A8");
198 Assert.AreEqual ("B", project.EvaluatedItems [0].FinalItemSpec, "A9");
199 Assert.AreEqual ("A", project.EvaluatedItems [0].Name, "A10");
200 //Assert.AreNotSame (item, project.EvaluatedItems [0], "A11");
201 Assert.IsFalse (object.ReferenceEquals (item, project.EvaluatedItems [0]), "A11");
205 [Category ("NotWorking")]
206 public void TestAddNewItem2 ()
211 engine = new Engine (Consts.BinPath);
212 project = engine.CreateNewProject ();
214 BuildItem item = project.AddNewItem ("A", "a;b;c");
215 Assert.AreEqual ("a;b;c", item.Include, "A1");
216 Assert.AreEqual ("a", item.FinalItemSpec, "A2");
218 Assert.AreEqual (3, project.EvaluatedItems.Count, "A3");
222 public void TestAddNewItem3 ()
226 BuildItemGroup [] groups = new BuildItemGroup [4];
228 string documentString = @"
229 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
243 engine = new Engine (Consts.BinPath);
244 project = engine.CreateNewProject ();
245 project.LoadXml (documentString);
247 project.AddNewItem ("B", "b");
249 project.ItemGroups.CopyTo (groups, 0);
250 Assert.AreEqual (0, groups [0].Count, "A1");
251 Assert.AreEqual (1, groups [1].Count, "A2");
252 Assert.AreEqual (1, groups [2].Count, "A3");
253 Assert.AreEqual (2, groups [3].Count, "A4");
256 public void TestAddNewItemGroup ()
261 string documentString = @"
262 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
266 engine = new Engine (Consts.BinPath);
267 project = engine.CreateNewProject ();
268 project.LoadXml (documentString);
270 BuildItemGroup big = project.AddNewItemGroup ();
271 Assert.IsNotNull (big, "A1");
272 Assert.AreEqual (String.Empty, big.Condition, "A2");
273 Assert.AreEqual (0, big.Count, "A3");
274 Assert.AreEqual (false, big.IsImported, "A4");
275 Assert.IsTrue (project.IsDirty, "A5");
279 public void TestAddNewPropertyGroup ()
284 string documentString = @"
285 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
289 engine = new Engine (Consts.BinPath);
290 project = engine.CreateNewProject ();
291 project.LoadXml (documentString);
293 BuildPropertyGroup bpg = project.AddNewPropertyGroup (false);
294 Assert.IsNotNull (bpg, "A1");
295 Assert.AreEqual (String.Empty, bpg.Condition, "A2");
296 Assert.AreEqual (0, bpg.Count, "A3");
297 Assert.AreEqual (false, bpg.IsImported, "A4");
298 Assert.IsTrue (project.IsDirty, "A5");
302 public void TestBuild0 ()
306 IDictionary hashtable = new Hashtable ();
308 string documentString = @"
309 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
319 engine = new Engine (Consts.BinPath);
320 project = engine.CreateNewProject ();
321 project.LoadXml (documentString);
323 Assert.AreEqual (true, project.Build (new string [] { "Main" }, hashtable), "A1");
324 Assert.AreEqual (1, hashtable.Count, "A2");
326 IDictionaryEnumerator e = hashtable.GetEnumerator ();
329 string name = (string) e.Key;
330 Assert.AreEqual ("Main", name, "A3");
331 ITaskItem [] arr = (ITaskItem []) e.Value;
333 Assert.AreEqual (3, arr.Length, "A4");
334 Assert.AreEqual ("d", arr [0].ItemSpec, "A5");
335 Assert.AreEqual ("e", arr [1].ItemSpec, "A6");
336 Assert.AreEqual ("f", arr [2].ItemSpec, "A7");
340 public void TestBuild1 ()
344 IDictionary hashtable = new Hashtable ();
346 string documentString = @"
347 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
349 <Microsoft.Build.Tasks.Message Text='Text' />
354 engine = new Engine (Consts.BinPath);
355 project = engine.CreateNewProject ();
356 project.LoadXml (documentString);
358 Assert.AreEqual (true, project.Build (new string[] { "Main" }, hashtable), "A1");
359 Assert.AreEqual (1, hashtable.Count, "A2");
361 IDictionaryEnumerator e = hashtable.GetEnumerator ();
364 string name = (string) e.Key;
365 Assert.AreEqual ("Main", name, "A3");
366 Assert.IsNotNull ((ITaskItem []) e.Value, "A4");
370 public void TestBuild2 ()
375 string documentString = @"
376 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
378 <Message Text='text' />
383 engine = new Engine (Consts.BinPath);
384 MBT.TestMessageLogger tl = new MBT.TestMessageLogger();
385 engine.RegisterLogger (tl);
386 project = engine.CreateNewProject ();
387 project.LoadXml (documentString);
392 Assert.AreEqual (2, tl.TargetStarted, "A1");
393 Assert.AreEqual (2, tl.TargetFinished, "A2");
394 Assert.AreEqual (2, tl.TaskStarted, "A3");
395 Assert.AreEqual (2, tl.TaskFinished, "A4");
399 public void TestBuild3 ()
404 string documentString = @"
405 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
407 <Message Text='text' />
412 engine = new Engine (Consts.BinPath);
413 MBT.TestMessageLogger tl = new MBT.TestMessageLogger ();
414 engine.RegisterLogger (tl);
415 project = engine.CreateNewProject ();
416 project.LoadXml (documentString);
418 project.Build (new string [1] { "T" }, null, BuildSettings.None);
419 project.Build (new string [1] { "T" }, null, BuildSettings.None);
421 Assert.AreEqual (2, tl.TargetStarted, "A1");
422 Assert.AreEqual (2, tl.TargetFinished, "A2");
423 Assert.AreEqual (2, tl.TaskStarted, "A3");
424 Assert.AreEqual (2, tl.TaskFinished, "A4");
428 public void TestBuild4 ()
433 string documentString = @"
434 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
436 <Message Text='text' />
441 engine = new Engine (Consts.BinPath);
442 MBT.TestMessageLogger tl = new MBT.TestMessageLogger ();
443 engine.RegisterLogger (tl);
444 project = engine.CreateNewProject ();
445 project.LoadXml (documentString);
447 project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets);
448 project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets);
450 Assert.AreEqual (1, tl.TargetStarted, "A1");
451 Assert.AreEqual (1, tl.TargetFinished, "A2");
452 Assert.AreEqual (1, tl.TaskStarted, "A3");
453 Assert.AreEqual (1, tl.TaskFinished, "A4");
457 public void TestBuild5 ()
462 string documentString = @"
463 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
467 engine = new Engine (Consts.BinPath);
468 project = engine.CreateNewProject ();
469 project.LoadXml (documentString);
471 Assert.IsFalse (project.Build ("target_that_doesnt_exist"));
475 public void TestEvaluatedItems1 ()
480 string documentString = @"
481 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
484 <B Include='b' Condition='false' />
489 engine = new Engine (Consts.BinPath);
490 project = engine.CreateNewProject ();
491 project.LoadXml (documentString);
493 Assert.AreEqual (1, project.EvaluatedItems.Count, "A1");
495 BuildItem bi = project.EvaluatedItems [0];
500 BuildItemGroup [] big = new BuildItemGroup [1];
501 project.ItemGroups.CopyTo (big, 0);
502 Assert.AreEqual ("C", big [0] [0].Name, "A2");
503 Assert.AreEqual ("c", big [0] [0].Include, "A3");
507 public void TestEvaluatedItems2 ()
512 string documentString = @"
513 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
515 <A Include='a;b;c' />
520 engine = new Engine (Consts.BinPath);
521 project = engine.CreateNewProject ();
522 project.LoadXml (documentString);
524 BuildItemGroup [] big = new BuildItemGroup [1];
525 project.ItemGroups.CopyTo (big, 0);
527 Assert.AreEqual (3, project.EvaluatedItems.Count, "A1");
528 Assert.AreEqual ("a;b;c", big [0] [0].Include, "A2");
529 Assert.AreEqual (1, big [0].Count, "A3");
531 BuildItem bi = project.EvaluatedItems [0];
535 Assert.AreEqual (3, big [0].Count, "A4");
536 Assert.AreEqual ("d", big [0] [0].Include, "A5");
537 Assert.AreEqual ("b", big [0] [1].Include, "A6");
538 Assert.AreEqual ("c", big [0] [2].Include, "A7");
542 [Category ("NotWorking")]
543 public void TestGetConditionedPropertyValues ()
548 string documentString = @"
549 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
550 <PropertyGroup Condition='true'>
552 <B Condition='true'>A</B>
555 <C Condition='true'>A</C>
556 <C Condition='false'>B</C>
557 <C Condition='!false'>C</C>
559 <E Condition="" '$(C)' == 'A' "">E</E>
564 engine = new Engine (Consts.BinPath);
565 project = engine.CreateNewProject ();
566 project.LoadXml (documentString);
568 Assert.AreEqual (0, project.GetConditionedPropertyValues ("A").Length, "A1");
569 Assert.AreEqual (0, project.GetConditionedPropertyValues ("B").Length, "A2");
570 Assert.AreEqual (1, project.GetConditionedPropertyValues ("C").Length, "A3");
571 Assert.AreEqual (0, project.GetConditionedPropertyValues ("D").Length, "A4");
572 Assert.AreEqual (0, project.GetConditionedPropertyValues ("E").Length, "A5");
573 Assert.AreEqual ("A", project.GetConditionedPropertyValues ("C") [0], "A6");
577 [ExpectedException (typeof (ArgumentNullException))]
578 public void TestGetEvaluatedItemsByName1 ()
583 string documentString = @"
584 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
588 engine = new Engine (Consts.BinPath);
589 project = engine.CreateNewProject ();
590 project.LoadXml (documentString);
592 project.GetEvaluatedItemsByName (null);
596 public void TestGetEvaluatedItemsByName2 ()
601 string documentString = @"
602 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
605 <B Include='2' Condition='true' />
606 <C Include='3' Condition='false' />
611 engine = new Engine (Consts.BinPath);
612 project = engine.CreateNewProject ();
613 project.LoadXml (documentString);
617 big = project.GetEvaluatedItemsByName (String.Empty);
619 Assert.AreEqual (0, big.Count, "A1");
621 big = project.GetEvaluatedItemsByName ("A");
623 Assert.AreEqual (1, big.Count, "A2");
624 Assert.AreEqual ("1", big [0].FinalItemSpec, "A3");
626 big = project.GetEvaluatedItemsByName ("B");
628 Assert.AreEqual (1, big.Count, "A4");
629 Assert.AreEqual ("2", big [0].FinalItemSpec, "A5");
631 big = project.GetEvaluatedItemsByName ("C");
633 Assert.AreEqual (0, big.Count, "A6");
637 [ExpectedException (typeof (ArgumentNullException))]
638 public void TestGetEvaluatedItemsByNameIgnoringCondition1 ()
643 string documentString = @"
644 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
648 engine = new Engine (Consts.BinPath);
649 project = engine.CreateNewProject ();
650 project.LoadXml (documentString);
652 project.GetEvaluatedItemsByNameIgnoringCondition (null);
656 public void TestGetEvaluatedItemsByNameIgnoringCondition2 ()
661 string documentString = @"
662 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
665 <B Include='2' Condition='true' />
666 <C Include='3' Condition='false' />
671 engine = new Engine (Consts.BinPath);
672 project = engine.CreateNewProject ();
673 project.LoadXml (documentString);
677 big = project.GetEvaluatedItemsByNameIgnoringCondition (String.Empty);
679 Assert.AreEqual (0, big.Count, "A1");
681 big = project.GetEvaluatedItemsByNameIgnoringCondition ("A");
683 Assert.AreEqual (1, big.Count, "A2");
684 Assert.AreEqual ("1", big [0].FinalItemSpec, "A3");
686 big = project.GetEvaluatedItemsByNameIgnoringCondition ("B");
688 Assert.AreEqual (1, big.Count, "A4");
689 Assert.AreEqual ("2", big [0].FinalItemSpec, "A5");
691 big = project.GetEvaluatedItemsByNameIgnoringCondition ("C");
693 Assert.AreEqual (1, big.Count, "A6");
694 Assert.AreEqual ("3", big [0].FinalItemSpec, "A7");
698 [ExpectedException (typeof (ArgumentNullException))]
699 public void TestGetEvaluatedProperty1 ()
704 string documentString = @"
705 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
709 engine = new Engine (Consts.BinPath);
710 project = engine.CreateNewProject ();
711 project.LoadXml (documentString);
713 project.GetEvaluatedProperty (null);
716 public void TestGetEvaluatedProperty2 ()
721 string documentString = @"
722 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
725 <B Condition='true'>2</B>
726 <C Condition='false'>3</C>
731 engine = new Engine (Consts.BinPath);
732 project = engine.CreateNewProject ();
733 project.LoadXml (documentString);
735 Assert.AreEqual ("1", project.GetEvaluatedProperty ("A"), "A1");
736 Assert.AreEqual ("2", project.GetEvaluatedProperty ("B"), "A2");
737 Assert.IsNull (project.GetEvaluatedProperty ("C"), "A3");
741 public void TestGetProjectExtensions ()
746 string documentString = @"
747 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
754 engine = new Engine (Consts.BinPath);
755 project = engine.CreateNewProject ();
756 project.LoadXml (documentString);
758 Assert.AreEqual (String.Empty, project.GetProjectExtensions (null), "A1");
759 Assert.AreEqual (String.Empty, project.GetProjectExtensions (String.Empty), "A2");
760 Assert.AreEqual (String.Empty, project.GetProjectExtensions ("something"), "A3");
761 Assert.AreEqual ("Text", project.GetProjectExtensions ("Node"), "A4");
765 public void TestGlobalProperties1 ()
770 string documentString = @"
771 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
775 engine = new Engine (Consts.BinPath);
776 project = engine.CreateNewProject ();
777 project.LoadXml (documentString);
779 Assert.AreEqual (0, project.GlobalProperties.Count, "A1");
783 public void TestGlobalProperties2 ()
788 string documentString = @"
789 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
793 engine = new Engine (Consts.BinPath);
794 engine.GlobalProperties.SetProperty ("Property", "Value");
796 project = engine.CreateNewProject ();
797 project.LoadXml (documentString);
799 Assert.AreEqual (1, project.GlobalProperties.Count, "A1");
800 Assert.AreEqual ("Property", project.GlobalProperties ["Property"].Name, "A2");
801 Assert.AreEqual ("Value", project.GlobalProperties ["Property"].Value, "A3");
802 Assert.AreEqual ("Value", project.GlobalProperties ["Property"].FinalValue, "A4");
803 Assert.AreEqual ("Property", project.EvaluatedProperties ["Property"].Name, "A2");
804 Assert.AreEqual ("Value", project.EvaluatedProperties ["Property"].Value, "A3");
805 Assert.AreEqual ("Value", project.EvaluatedProperties ["Property"].FinalValue, "A4");
809 [Category ("NotDotNet")]
810 [ExpectedException (typeof (ArgumentNullException))]
811 public void TestGlobalProperties3 ()
816 string documentString = @"
817 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
821 engine = new Engine (Consts.BinPath);
822 project = engine.CreateNewProject ();
823 project.LoadXml (documentString);
825 project.GlobalProperties = null;
829 [Ignore ("needs rewriting")]
830 public void TestGlobalProperties4 ()
835 string documentString = @"
836 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
838 <Property>a</Property>
843 engine = new Engine (Consts.BinPath);
844 project = engine.CreateNewProject ();
845 project.LoadXml (documentString);
847 BuildPropertyGroup[] groups = new BuildPropertyGroup [1];
848 project.PropertyGroups.CopyTo (groups, 0);
850 project.GlobalProperties = groups [0];
851 project.GlobalProperties = project.EvaluatedProperties;
855 [Category ("NotDotNet")]
856 [ExpectedException (typeof (InvalidOperationException))]
857 public void TestGlobalProperties5 ()
862 string documentString = @"
863 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
865 <Property>a</Property>
870 engine = new Engine (Consts.BinPath);
871 project = engine.CreateNewProject ();
872 project.LoadXml (documentString);
874 BuildPropertyGroup[] groups = new BuildPropertyGroup [1];
875 project.PropertyGroups.CopyTo (groups, 0);
876 project.GlobalProperties = groups [0];
880 [ExpectedException (typeof (InvalidProjectFileException))]
881 public void TestLoad1 ()
886 string documentString = @"
887 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
892 engine = new Engine (Consts.BinPath);
893 project = engine.CreateNewProject ();
894 project.LoadXml (documentString);
898 [ExpectedException (typeof (InvalidProjectFileException))]
899 public void TestLoad2 ()
904 engine = new Engine (Consts.BinPath);
905 project = engine.CreateNewProject ();
906 project.LoadXml ("project_file_that_doesnt_exist");
910 public void TestParentEngine ()
915 engine = new Engine (Consts.BinPath);
916 project = engine.CreateNewProject ();
918 Assert.AreEqual (engine, project.ParentEngine, "A1");
922 [Category ("NotDotNet")]
923 [ExpectedException (typeof (ArgumentNullException))]
924 public void TestRemoveItemGroup1 ()
929 engine = new Engine (Consts.BinPath);
930 p1 = engine.CreateNewProject ();
932 p1.RemoveItemGroup (null);
935 // The "BuildItemGroup" object specified does not belong to the correct "Project" object.
937 [ExpectedException (typeof (InvalidOperationException))]
938 [Category ("NotWorking")]
939 public void TestRemoveItemGroup2 ()
944 BuildItemGroup [] groups = new BuildItemGroup [1];
946 engine = new Engine (Consts.BinPath);
947 p1 = engine.CreateNewProject ();
948 p2 = engine.CreateNewProject ();
950 p1.AddNewItem ("A", "B");
951 p1.ItemGroups.CopyTo (groups, 0);
953 p2.RemoveItemGroup (groups [0]);
957 [Category ("NotDotNet")]
958 [ExpectedException (typeof (ArgumentNullException))]
959 public void TestRemoveItem1 ()
964 engine = new Engine (Consts.BinPath);
965 project = engine.CreateNewProject ();
967 project.RemoveItem (null);
970 // The object passed in is not part of the project.
972 [ExpectedException (typeof (InvalidOperationException))]
973 public void TestRemoveItem2 ()
978 engine = new Engine (Consts.BinPath);
979 project = engine.CreateNewProject ();
981 project.RemoveItem (new BuildItem ("name", "include"));
984 // The "BuildItemGroup" object specified does not belong to the correct "Project" object.
986 [ExpectedException (typeof (InvalidOperationException))]
987 public void TestRemoveItem3 ()
993 engine = new Engine (Consts.BinPath);
994 p1 = engine.CreateNewProject ();
995 p2 = engine.CreateNewProject ();
997 p1.AddNewItem ("A", "B");
999 p2.RemoveItem (p1.EvaluatedItems [0]);
1003 [Category ("NotDotNet")]
1004 [ExpectedException (typeof (InvalidOperationException))]
1005 public void TestRemoveItem4 ()
1011 engine = new Engine (Consts.BinPath);
1012 p1 = engine.CreateNewProject ();
1013 p2 = engine.CreateNewProject ();
1015 p1.AddNewItem ("A", "B");
1016 p1.AddNewItem ("A", "C");
1018 p2.RemoveItem (p1.EvaluatedItems [0]);
1022 public void TestRemoveItem5 ()
1026 BuildItemGroup [] groups = new BuildItemGroup [1];
1028 string documentString = @"
1029 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1036 engine = new Engine (Consts.BinPath);
1037 project = engine.CreateNewProject ();
1038 project.LoadXml (documentString);
1040 project.RemoveItem (project.EvaluatedItems [0]);
1041 Assert.AreEqual (0, project.EvaluatedItems.Count, "A1");
1042 project.ItemGroups.CopyTo (groups, 0);
1043 Assert.IsNull (groups [0], "A2");
1044 Assert.AreEqual (0, project.ItemGroups.Count, "A3");
1048 public void TestResetBuildStatus ()
1053 string documentString = @"
1054 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1055 <Target Name='T' Inputs='Test\resources\TestTasks.cs' Outputs='Test\resources\TestTasks.dll'>
1056 <Message Text='text' />
1061 engine = new Engine (Consts.BinPath);
1062 TestLogger tl = new TestLogger ();
1063 engine.RegisterLogger (tl);
1064 project = engine.CreateNewProject ();
1065 project.LoadXml (documentString);
1067 project.Build ("T");
1068 project.ResetBuildStatus ();
1069 project.Build (new string [1] { "T" }, null, BuildSettings.DoNotResetPreviouslyBuiltTargets);
1071 Assert.AreEqual (2, tl.TargetStartedEvents, "A1");
1072 Assert.AreEqual (2, tl.TargetFinishedEvents, "A1");
1076 public void TestSchemaFile ()
1081 string documentString = @"
1082 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1086 engine = new Engine (Consts.BinPath);
1087 project = engine.CreateNewProject ();
1088 project.LoadXml (documentString);
1090 Assert.IsNull (project.SchemaFile, "A1");
1093 [Category ("NotDotNet")]
1094 [ExpectedException (typeof (ArgumentNullException))]
1095 public void TestSetProjectExtensions1 ()
1100 string documentString = @"
1101 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1105 engine = new Engine (Consts.BinPath);
1106 project = engine.CreateNewProject ();
1107 project.LoadXml (documentString);
1109 project.SetProjectExtensions (null, null);
1113 public void TestSetProjectExtensions2 ()
1118 string documentString = @"
1119 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1123 engine = new Engine (Consts.BinPath);
1124 project = engine.CreateNewProject ();
1125 project.LoadXml (documentString);
1127 project.SetProjectExtensions ("name", "1");
1128 Assert.AreEqual ("1", project.GetProjectExtensions ("name"), "A1");
1129 project.SetProjectExtensions ("name", "2");
1130 Assert.AreEqual ("2", project.GetProjectExtensions ("name"), "A2");
1131 Assert.IsTrue (project.IsDirty, "A3");
1135 public void TestSetProjectExtensions3 ()
1140 string documentString = @"
1141 <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
1143 </ProjectExtensions>
1147 engine = new Engine (Consts.BinPath);
1148 project = engine.CreateNewProject ();
1149 project.LoadXml (documentString);
1151 project.SetProjectExtensions ("name", "1");
1152 Assert.AreEqual ("1", project.GetProjectExtensions ("name"), "A1");
1153 Assert.IsTrue (project.IsDirty, "A2");
1157 public void TestBuildProjectError1 ()
1159 Engine engine = new Engine (Consts.BinPath);
1160 Project project = engine.CreateNewProject ();
1162 Assert.IsFalse (project.Build ((string) null), "A1");
1163 Assert.IsFalse (project.Build ((string[]) null), "A2");
1164 Assert.IsFalse (project.Build ((string []) null, null), "A3");
1165 Assert.IsFalse (project.Build ((string []) null, null, BuildSettings.None), "A4");
1169 public void TestBuildProjectError2 ()
1171 Engine engine = new Engine (Consts.BinPath);
1172 Project project = engine.CreateNewProject ();
1175 project.Build (new string [] { null });
1179 Assert.Fail ("Expected exception for project.Build, null string in targetNames []");
1183 public void TestBuildProjectFile1 ()
1185 Project project = CreateAndLoadProject ("foo.proj", false, new string [] { "1", "2" }, new bool [] { true, true }, "TBPF1");
1186 CheckProjectBuild (project, new string [] { "main" }, true, new string [] { "main" }, "TBPF1");
1190 public void TestBuildProjectFileXml1 ()
1192 Project project = CreateAndLoadProject (null, false, new string [] { "1", "2" }, new bool [] { true, true }, "TBPFX1");
1193 CheckProjectBuild (project, new string [] { "main" }, true, new string [] { "main" }, "TBPFX1");
1197 public void TestBuildProjectFile2 ()
1199 Project project = CreateAndLoadProject ("foo.proj", false, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPF2");
1200 CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPF2");
1204 public void TestBuildProjectFileXml2 ()
1206 Project project = CreateAndLoadProject (null, false, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPFX2");
1207 CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPFX2");
1211 public void TestBuildProjectFile3 ()
1213 Project project = CreateAndLoadProject ("foo.proj", false, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPF3");
1214 CheckProjectBuild (project, new string [] { "1", "2" }, true, new string [] { "1", "2" }, "TBPF3");
1218 public void TestBuildProjectFileXml3 ()
1220 Project project = CreateAndLoadProject (null, false, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPFX3");
1221 CheckProjectBuild (project, new string [] { "1", "2" }, true, new string [] { "1", "2" }, "TBPFX3");
1225 public void TestBuildProjectFile4 ()
1227 Project project = CreateAndLoadProject ("foo.proj", false, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPF4");
1228 CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPF4");
1232 public void TestBuildProjectFileXml4 ()
1234 Project project = CreateAndLoadProject (null, false, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPFX4");
1235 CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPFX4");
1238 //Run separate tests
1242 public void TestBuildProjectFile5 ()
1244 Project project = CreateAndLoadProject ("foo.proj", true, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPF5");
1245 CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPF5");
1249 public void TestBuildProjectFileXml5 ()
1251 Project project = CreateAndLoadProject (null, true, new string [] { "1", "2", "3" }, new bool [] { true, false, true }, "TBPFX5");
1252 CheckProjectBuild (project, new string [] { "main" }, false, new string [0], "TBPFX5");
1256 public void TestBuildProjectFile6 ()
1258 Project project = CreateAndLoadProject ("foo.proj", true, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPF6");
1259 CheckProjectBuild (project, new string [] { "main" }, true, new string [] { "main" }, "TBPF6");
1263 public void TestBuildProjectFileXml6 ()
1265 Project project = CreateAndLoadProject (null, true, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPFX6");
1266 CheckProjectBuild (project, new string [] { "main" }, true, new string [] { "main" }, "TBPFX6");
1269 // run multiple targets
1271 public void TestBuildProjectFile7 ()
1273 Project project = CreateAndLoadProject ("foo.proj", true, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPF7");
1274 CheckProjectBuild (project, new string [] { "1", "2", "3" }, true, new string [] { "1", "2", "3" }, "TBPF7");
1278 public void TestBuildProjectFileXml7 ()
1280 Project project = CreateAndLoadProject (null, true, new string [] { "1", "2", "3" }, new bool [] { true, true, true }, "TBPFX7");
1281 CheckProjectBuild (project, new string [] { "1", "2", "3" }, true, new string [] { "1", "2", "3" }, "TBPFX7");
1285 public void TestBuildProjectFile8 ()
1287 Project project = CreateAndLoadProject ("foo.proj", true, new string [] { "1", "2", "3" }, new bool [] { true, true, false }, "TBPF8");
1288 CheckProjectBuild (project, new string [] { "1", "2", "3" }, false, new string [] { "1", "2"}, "TBPF8");
1292 public void TestBuildProjectFileXml8 ()
1294 Project project = CreateAndLoadProject (null, true, new string [] { "1", "2", "3" }, new bool [] { true, true, false }, "TBPFX8");
1295 CheckProjectBuild (project, new string [] { "1", "2", "3" }, false, new string [] { "1", "2"}, "TBPFX8");
1299 public void TestBatchedMetadataRef1 ()
1301 //test for multiple items with same metadata also
1302 string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1303 <UsingTask TaskName=""BatchingTestTask"" AssemblyFile=""Test/resources/TestTasks.dll"" />
1305 <Coll1 Include=""A1""><Name>Abc</Name></Coll1>
1306 <Coll1 Include=""A2""><Name>Def</Name></Coll1>
1307 <Coll1 Include=""A3""><Name>Xyz</Name></Coll1>
1308 <Coll1 Include=""A4""><Name>Xyz</Name></Coll1>
1309 <Coll2 Include=""B1""></Coll2>
1311 <Target Name=""ShowMessage"">
1312 <BatchingTestTask Sources=""%(Coll1.Name)"">
1313 <Output TaskParameter=""Output"" ItemName=""FinalList"" />
1315 <Message Text=""Msg: %(Coll1.Name)"" />
1319 Engine engine = new Engine (Consts.BinPath);
1320 Project project = engine.CreateNewProject ();
1322 project.LoadXml (projectString);
1323 Assert.IsTrue (project.Build ("ShowMessage"), "A1: Build failed");
1325 BuildItemGroup include = project.GetEvaluatedItemsByName ("FinalList");
1326 Assert.AreEqual (3, include.Count, "A2");
1328 Assert.AreEqual ("FinalList", include [0].Name, "A3");
1329 Assert.AreEqual ("Abc", include [0].FinalItemSpec, "A4");
1331 Assert.AreEqual ("FinalList", include [1].Name, "A5");
1332 Assert.AreEqual ("Def", include [1].FinalItemSpec, "A6");
1334 Assert.AreEqual ("FinalList", include [2].Name, "A7");
1335 Assert.AreEqual ("Xyz", include [2].FinalItemSpec, "A8");
1339 public void TestBatchedMetadataRef2 ()
1341 string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1342 <UsingTask TaskName=""BatchingTestTask"" AssemblyFile=""Test/resources/TestTasks.dll"" />
1344 <Coll1 Include=""A1""><Name>Abc</Name></Coll1>
1345 <Coll1 Include=""A2""><Name>Def</Name></Coll1>
1346 <Coll1 Include=""A3""><Name>Xyz</Name></Coll1>
1347 <Coll1 Include=""A4""><Name>Abc</Name></Coll1>
1348 <Coll2 Include=""B1""><Name>Bar</Name></Coll2>
1349 <Coll2 Include=""B2""><Name>Bar</Name></Coll2>
1351 <Target Name=""ShowMessage"">
1352 <BatchingTestTask Sources=""%(Name)"" Strings=""@(Coll2)"">
1353 <Output TaskParameter=""Output"" ItemName=""FinalList"" />
1355 <Message Text=""Msg: %(Coll1.Name)"" />
1357 <Target Name=""ShowMessage2"">
1358 <BatchingTestTask Sources=""%(Name)"" Strings=""@(Coll1)"">
1359 <Output TaskParameter=""Output"" ItemName=""FinalList2"" />
1361 <Message Text=""Msg: %(Coll1.Name)"" />
1365 Engine engine = new Engine (Consts.BinPath);
1366 Project project = engine.CreateNewProject ();
1368 project.LoadXml (projectString);
1369 Assert.IsTrue (project.Build ("ShowMessage"), "A1: Build failed");
1371 BuildItemGroup include = project.GetEvaluatedItemsByName ("FinalList");
1372 Assert.AreEqual (1, include.Count, "A2");
1374 Assert.AreEqual ("FinalList", include [0].Name, "A3");
1375 Assert.AreEqual ("Bar", include [0].FinalItemSpec, "A4");
1377 Assert.IsTrue (project.Build ("ShowMessage2"), "A1: Build failed");
1378 include = project.GetEvaluatedItemsByName ("FinalList2");
1379 Assert.AreEqual (3, include.Count, "A5");
1381 Assert.AreEqual ("FinalList2", include [0].Name, "A6");
1382 Assert.AreEqual ("Abc", include [0].FinalItemSpec, "A7");
1384 Assert.AreEqual ("FinalList2", include [1].Name, "A8");
1385 Assert.AreEqual ("Def", include [1].FinalItemSpec, "A9");
1387 Assert.AreEqual ("FinalList2", include [2].Name, "A10");
1388 Assert.AreEqual ("Xyz", include [2].FinalItemSpec, "A11");
1392 public void TestBatchedMetadataRef3 ()
1394 string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1395 <UsingTask TaskName=""BatchingTestTask"" AssemblyFile=""Test/resources/TestTasks.dll"" />
1397 <Coll1 Include=""A1""><Name>Abc</Name></Coll1>
1398 <Coll1 Include=""A2""><Name>Def</Name></Coll1>
1399 <Coll1 Include=""A3""><Name>Xyz</Name></Coll1>
1400 <Coll1 Include=""A4""><Name>Abc</Name></Coll1>
1401 <Coll2 Include=""B1""><Name>Bar</Name></Coll2>
1402 <Coll2 Include=""B2""><Name>Bar</Name></Coll2>
1404 <Target Name=""ShowMessage"">
1405 <BatchingTestTask SingleTaskItem=""%(Coll2.Name)"" >
1406 <Output TaskParameter=""SingleStringOutput"" ItemName=""FinalList"" />
1408 <Message Text=""Msg: %(Coll1.Name)"" />
1412 Engine engine = new Engine (Consts.BinPath);
1413 Project project = engine.CreateNewProject ();
1415 project.LoadXml (projectString);
1416 Assert.IsTrue (project.Build ("ShowMessage"), "A1: Build failed");
1418 BuildItemGroup include = project.GetEvaluatedItemsByName ("FinalList");
1419 Assert.AreEqual (1, include.Count, "A2");
1421 Assert.AreEqual ("FinalList", include [0].Name, "A3");
1422 Assert.AreEqual ("Bar", include [0].FinalItemSpec, "A4");
1427 public void TestBatchedMetadataRef4 ()
1429 string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1430 <UsingTask TaskName=""BatchingTestTask"" AssemblyFile=""Test/resources/TestTasks.dll"" />
1432 <Coll1 Include=""A1""><Name>Abc</Name></Coll1>
1433 <Coll1 Include=""A2""><Name>Def</Name></Coll1>
1434 <Coll1 Include=""A3""><Name>Xyz</Name></Coll1>
1435 <Coll2 Include=""B1""><Name>Bar</Name></Coll2>
1437 <Target Name=""ShowMessage"">
1438 <BatchingTestTask SingleTaskItem=""%(Coll3.Name)"" >
1439 <Output TaskParameter=""SingleStringOutput"" ItemName=""FinalList"" />
1444 Engine engine = new Engine (Consts.BinPath);
1445 Project project = engine.CreateNewProject ();
1447 project.LoadXml (projectString);
1448 Assert.IsTrue (project.Build ("ShowMessage"), "A1: Build failed");
1450 BuildItemGroup include = project.GetEvaluatedItemsByName ("FinalList");
1451 Assert.AreEqual (0, include.Count, "A2");
1455 public void TestBatchedMetadataRef5 ()
1457 string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1458 <UsingTask TaskName=""BatchingTestTask"" AssemblyFile=""Test/resources/TestTasks.dll"" />
1460 <Coll1 Include=""A1""><Name>Abc</Name></Coll1>
1461 <Coll1 Include=""A2""><Name>Def</Name></Coll1>
1462 <Coll1 Include=""A3""><Name>Xyz</Name></Coll1>
1463 <Coll2 Include=""B1""><Name>Bar</Name></Coll2>
1465 <Target Name=""ShowMessage"">
1466 <Message Text=""Coll1: @(Coll1->'Foo%(Name)Bar')"" />
1467 <BatchingTestTask Sources=""@(Coll1->'Foo%(Name)Bar')"" >
1468 <Output TaskParameter=""Output"" ItemName=""FinalList"" />
1473 Engine engine = new Engine (Consts.BinPath);
1474 Project project = engine.CreateNewProject ();
1475 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
1476 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
1477 engine.RegisterLogger (logger);
1479 project.LoadXml (projectString);
1480 bool result = project.Build ("ShowMessage");
1482 logger.DumpMessages ();
1483 Assert.Fail ("A1: Build failed");
1485 logger.DumpMessages ();
1486 BuildItemGroup include = project.GetEvaluatedItemsByName ("FinalList");
1487 Assert.AreEqual (3, include.Count, "A2");
1491 public void TestInitialTargets ()
1493 Engine engine = new Engine (Consts.BinPath);
1494 Project project = engine.CreateNewProject ();
1496 project.LoadXml (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" InitialTargets=""pre "">
1497 <Target Name=""boo"">
1498 <Message Text=""Executing boo target""/>
1500 <Target Name=""pre"">
1501 <Message Text=""Executing pre target""/>
1505 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
1506 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
1507 engine.RegisterLogger (logger);
1510 Assert.IsTrue (project.Build (), "Build failed");
1512 Assert.AreEqual (0, logger.CheckHead ("Executing pre target", MessageImportance.Normal), "A1");
1513 Assert.AreEqual (0, logger.CheckHead ("Executing boo target", MessageImportance.Normal), "A2");
1514 Assert.AreEqual (0, logger.Count, "A3");
1516 logger.DumpMessages ();
1522 public void TestRequiredTask_String1 ()
1524 CheckProjectForRequiredTests ("RequiredTestTask_String", "@(NonExistant)",
1525 false, "Should've failed: No value specified for required field - 'Property' of RequiredTestTask_String");
1529 public void TestRequiredTask_String2 ()
1531 CheckProjectForRequiredTests ("RequiredTestTask_String", "$(NonExistant)",
1532 false, "Should've failed: No value specified for required field - 'Property' of RequiredTestTask_String");
1536 public void TestRequiredTask_TaskItem1 ()
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_TaskItem2 ()
1545 Project p = CheckProjectForRequiredTests ("RequiredTestTask_TaskItem", "$(NonExistant)",
1546 false, "Should've failed: No value specified for required field - 'Property' of RequiredTestTask_TaskItem");
1550 public void TestRequiredTask_TaskItemArray1 ()
1552 Project p = CheckProjectForRequiredTests ("RequiredTestTask_TaskItems", "@(NonExistant)",
1553 true, "Build failed");
1555 BuildItemGroup group = p.GetEvaluatedItemsByName ("OutItem");
1556 Assert.AreEqual (1, group.Count, "A2");
1557 Assert.AreEqual ("count: 0", group [0].FinalItemSpec, "A3");
1561 public void TestRequiredTask_TaskItemArray2 ()
1563 Project p = CheckProjectForRequiredTests ("RequiredTestTask_TaskItems", "$(NonExistant)",
1564 true, "Build failed");
1566 BuildItemGroup group = p.GetEvaluatedItemsByName ("OutItem");
1567 Assert.AreEqual (1, group.Count, "A2");
1568 Assert.AreEqual ("count: 0", group [0].FinalItemSpec, "A3");
1572 public void TestRequiredTask_TaskItemArray3 ()
1574 Project p = CheckProjectForRequiredTests ("RequiredTestTask_IntArray", "$(NonExistant)",
1575 true, "Build failed");
1577 BuildItemGroup group = p.GetEvaluatedItemsByName ("OutItem");
1578 Assert.AreEqual (1, group.Count, "A2");
1579 Assert.AreEqual ("count: 0", group [0].FinalItemSpec, "A3");
1583 Project CheckProjectForRequiredTests (string taskname, string property_arg, bool expected_result, string error_msg)
1585 string projectString = String.Format (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
1586 <UsingTask TaskName=""{0}"" AssemblyFile=""Test/resources/TestTasks.dll"" />
1587 <Target Name=""foo"">
1588 <{0} Property=""{1}"">
1589 <Output TaskParameter=""Output"" ItemName=""OutItem""/>
1592 </Project>", taskname, property_arg);
1594 Engine engine = new Engine (Consts.BinPath);
1595 MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
1596 new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
1597 engine.RegisterLogger (logger);
1598 Project project = engine.CreateNewProject ();
1599 project.LoadXml (projectString);
1602 Assert.AreEqual (expected_result, project.Build (), error_msg);
1604 logger.DumpMessages ();
1609 static void CheckBuildItem (BuildItem item, string name, string [,] metadata, string finalItemSpec, string prefix)
1611 Assert.AreEqual (name, item.Name, prefix + "#1");
1612 for (int i = 0; i < metadata.GetLength (0); i++) {
1613 string key = metadata [i, 0];
1614 string val = metadata [i, 1];
1615 Assert.IsTrue (item.HasMetadata (key), String.Format ("{0}#2: Expected metadata '{1}' not found", prefix, key));
1616 Assert.AreEqual (val, item.GetMetadata (key), String.Format ("{0}#3: Value for metadata {1}", prefix, key));
1617 Assert.AreEqual (val, item.GetEvaluatedMetadata (key), String.Format ("{0}#4: Value for evaluated metadata {1}", prefix, key));
1619 Assert.AreEqual (finalItemSpec, item.FinalItemSpec, prefix + "#5");
1622 void CheckProjectBuild (Project project, string [] targetNames, bool result, string [] outputNames, string prefix)
1624 IDictionary targetOutputs = new Hashtable ();
1626 Assert.AreEqual (result, project.Build (targetNames, targetOutputs), prefix + "A1");
1627 Assert.AreEqual (outputNames.Length, targetOutputs.Keys.Count, prefix + "A2");
1629 foreach (string outputName in outputNames) {
1630 Assert.IsTrue (targetOutputs.Contains (outputName), prefix + " A3: target " + outputName);
1632 object o = targetOutputs [outputName];
1633 Assert.IsTrue (typeof (ITaskItem []).IsAssignableFrom (o.GetType ()), prefix + " A4: target " + outputName);
1635 ITaskItem [] items = (ITaskItem [])o;
1636 Assert.AreEqual (0, items.Length, prefix + "A5: target " + outputName);
1640 string CreateProjectString (bool run_separate, string [] targets, bool [] results, string prefix)
1642 StringBuilder sb = new StringBuilder ();
1643 sb.Append (@"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">");
1644 sb.AppendFormat ("<Target Name = \"{0}\"><Message Text = \"#Target {1}:{0} called\" />", "main", prefix);
1646 sb.AppendFormat ("<CallTarget Targets=\"");
1647 for (int i = 0; i < targets.Length; i++)
1648 sb.AppendFormat ("{0};", targets [i]);
1649 sb.AppendFormat ("\" ");
1652 sb.AppendFormat (" RunEachTargetSeparately=\"true\" ");
1653 sb.AppendFormat ("/></Target>\n");
1655 for (int i = 0; i < targets.Length; i++) {
1656 sb.AppendFormat ("<Target Name = \"{0}\"><Message Text = \"#Target {1}:{0} called\" />", targets [i], prefix);
1658 sb.AppendFormat ("<Error Text = \"#Error message for target {0}:{1}\"/>", prefix, targets [i]);
1659 sb.Append ("</Target>\n");
1662 sb.Append ("</Project>");
1664 return sb.ToString ();
1667 void CreateProjectFile (string fname, bool run_separate, string [] targets, bool [] results, string prefix)
1669 using (StreamWriter sw = new StreamWriter (fname))
1670 sw.Write (CreateProjectString (run_separate, targets, results, prefix));
1673 Project CreateAndLoadProject (string fname, bool run_separate, string [] targets, bool [] results, string prefix)
1675 Engine engine = new Engine (Consts.BinPath);
1676 Project project = engine.CreateNewProject ();
1678 string projectXml = CreateProjectString (run_separate, targets, results, prefix);
1679 if (fname == null) {
1680 project.LoadXml (projectXml);
1682 using (StreamWriter sw = new StreamWriter (fname))
1683 sw.Write (projectXml);
1684 project.Load (fname);
1685 File.Delete (fname);