[xbuild] Clean up test logs.
[mono.git] / mcs / class / Microsoft.Build.Engine / Test / Microsoft.Build.BuildEngine / BuildItemTest.cs
index de90f1fe57aafa74173cd8be7c688cd402f4285c..36f5e52f9b098933a5e1c2271a4c2dd179069e79 100644 (file)
@@ -80,7 +80,8 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                }
 
                [Test]
-               [Ignore ("NullRefException on MS .NET 2.0")]
+               [ExpectedException (typeof (ArgumentNullException))]
+               [Category ("NotDotNet")]
                public void TestCtor4 ()
                {
                        new BuildItem (null, (ITaskItem) null);
@@ -92,16 +93,16 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                        new BuildItem (null, "something");
                }
 
+               // Parameter "itemInclude" cannot have zero length.
                [Test]
-               [ExpectedException (typeof (ArgumentException),
-                       "Parameter \"itemInclude\" cannot have zero length.")]
+               [ExpectedException (typeof (ArgumentException))]
                public void TestCtor6 ()
                {
                        new BuildItem (null, String.Empty);
                }
 
                [Test]
-               [Ignore ("IndexOutOfRange on MS .NET 2.0")]
+               [Category ("NotDotNet")] //IndexOutOfRange throw by MS .NET 2.0
                public void TestCtor7 ()
                {
                        new BuildItem (String.Empty, "something");
@@ -123,9 +124,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                        Assert.AreEqual ("name", item2.Name, "A6");
                }
 
+               // Cannot set a condition on an object not represented by an XML element in the project file.
                [Test]
-               [ExpectedException (typeof (InvalidOperationException),
-                       "Cannot set a condition on an object not represented by an XML element in the project file.")]
+               [ExpectedException (typeof (InvalidOperationException))]
                public void TestCondition1 ()
                {
                        item = new BuildItem ("name", "1");
@@ -205,9 +206,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                        Assert.AreEqual (metadataValue, destination.GetEvaluatedMetadata (metadataName), "A2");
                }
 
-               // NOTE: it's weird that they don't throw ArgumentNullException
                [Test]
-               [Ignore ("MS throws NullRefException")]
+               [ExpectedException (typeof (ArgumentNullException))]
+               [Category ("NotDotNet")]
                public void TestCopyCustomMetadataTo2 ()
                {
                        BuildItem item = new BuildItem ("name", "include");
@@ -216,9 +217,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                        item.CopyCustomMetadataTo (null);
                }
 
+               // Assigning the "Exclude" attribute of a virtual item is not allowed.
                [Test]
-               [ExpectedException (typeof (InvalidOperationException),
-                       "Assigning the \"Exclude\" attribute of a virtual item is not allowed.")]
+               [ExpectedException (typeof (InvalidOperationException))]
                public void TestExclude1 ()
                {
                        item = new BuildItem ("name", "1");
@@ -331,6 +332,7 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                        item.SetMetadata (metadataName, metadataValue);
 
                        Assert.AreEqual (metadataValue, item.GetEvaluatedMetadata (metadataName), "A2");
+                       Assert.AreEqual (itemInclude, item.GetEvaluatedMetadata ("Identity"), "A3");
                }
 
                [Test]
@@ -559,9 +561,9 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                        item.RemoveMetadata ("undefined_metadata");
                }
 
+               // "Filename" is a reserved item meta-data, and cannot be modified or deleted.
                [Test]
-               [ExpectedException (typeof (ArgumentException),
-                       "\"Filename\" is a reserved item meta-data, and cannot be modified or deleted.")]
+               [ExpectedException (typeof (ArgumentException))]
                public void TestRemoveMetadata4 ()
                {
                        item = new BuildItem ("name", "value");
@@ -603,7 +605,6 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void TestRemoveMetadata6 ()
                {
                        Engine engine;
@@ -670,9 +671,10 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                        Assert.AreEqual (Utilities.Escape ("$(A)"), item.GetMetadata ("b"), "A5");
                        Assert.AreEqual ("$(A)", item.GetMetadata ("c"), "A6");
                }
+
+               // "Filename" is a reserved item meta-data, and cannot be modified or deleted.
                [Test]
-               [ExpectedException (typeof (ArgumentException),
-                       "\"Filename\" is a reserved item meta-data, and cannot be modified or deleted.")]
+               [ExpectedException (typeof (ArgumentException))]
                public void TestSetMetadata4 ()
                {
                        item = new BuildItem ("name", "include");
@@ -680,7 +682,6 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                }
 
                [Test]
-               [Category ("NotWorking")]
                public void TestSetMetadata5 ()
                {
                        Engine engine;
@@ -715,6 +716,82 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                        Assert.AreEqual ("A", project.EvaluatedItems [1].GetEvaluatedMetadata ("Meta"), "A6");
                }
 
+               [Test]
+               public void TestSetMetadata5a () {
+                       Engine engine;
+                       Project project;
+                       BuildItemGroup[] groups = new BuildItemGroup[1];
+
+                       string documentString = @"
+                               <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'>
+                                       <PropertyGroup>
+                                               <A>A</A>
+                                               <C>@(D)</C>
+                                       </PropertyGroup>
+                                       <ItemGroup>
+                                               <D Include='D'/>
+                                               <C Include='$(C)'/>
+                                               <A Include='a;b'>
+                                                       <Md>@(C)</Md>
+                                               </A>
+                                               <B Include='$(A)'/>
+                                       </ItemGroup>
+                                       <Target Name='main'>
+                                               <Message Text=""a.md: %(A.Md)""/>
+                                               <Message Text=""a.md: %(A.Meta)""/>
+                                       </Target>
+                               </Project>
+                       ";
+
+                       engine = new Engine (Consts.BinPath);
+                       project = engine.CreateNewProject ();
+                       MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
+                       engine.RegisterLogger (logger);
+                       project.LoadXml (documentString);
+
+                       CheckMetadata (project, "A", "Md", new string [] {"@(C)", "@(C)"}, "G1");
+                       CheckEvaluatedMetadata (project, "A", "Md", new string[] { "D", "D" }, "G2");
+
+                       //@(B)
+                       Assert.AreEqual ("A", project.GetEvaluatedItemsByName ("B")[0].FinalItemSpec, "B2");
+
+                       project.ItemGroups.CopyTo (groups, 0);
+                       /*Broken right now:
+                         CheckBuildItemGroup (groups[0], new string[] {
+                               "D", "D",
+                               "C", "$(C)",
+                               "A", "a;b",
+                               "B", "$(A)"
+                       }, "H1");*/
+
+                       CheckBuildItemGroup (project.GetEvaluatedItemsByName ("C"), new string[] {
+                               "C", "D"
+                       }, "H2");
+
+                       CheckBuildItemGroup (project.GetEvaluatedItemsByName ("C"), new string[] {
+                               "C", "D"
+                       }, "I");
+
+                       project.GetEvaluatedItemsByName ("A")[0].SetMetadata ("Meta", "@(B)");
+
+                       Assert.AreEqual (5, project.EvaluatedItems.Count, "A0");
+                       Assert.AreEqual (2, project.GetEvaluatedItemsByName ("A").Count, "A7");
+
+                       CheckMetadata (project, "A", "Meta", new string[] { "@(B)", "" }, "J");
+
+                       if (!project.Build ()) {
+                               logger.DumpMessages ();
+                               Assert.Fail ("Build failed");
+                       }
+
+                       CheckMetadata (project, "A", "Meta", new string[] { "@(B)", "" }, "K1");
+                       CheckEvaluatedMetadata (project, "A", "Meta", new string[] { "", "" }, "K2");
+
+                       logger.CheckLoggedMessageHead ("a.md: D", "E10");
+                       logger.CheckLoggedMessageHead ("a.md: ", "E11");
+                       Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected messages left");
+               }
+
                [Test]
                public void TestSetMetadata6 ()
                {
@@ -802,5 +879,89 @@ namespace MonoTests.Microsoft.Build.BuildEngine {
                        project.ItemGroups.CopyTo (groups, 0);
                        Assert.AreEqual (1, groups [0].Count, "A3");
                }
+
+               [Test]
+               public void TestBuildItemTransform ()
+               {
+                       string projectText = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"">
+                               <UsingTask TaskName='BatchingTestTask' AssemblyFile='Test\resources\TestTasks.dll' />
+
+                               <ItemGroup>
+                                       <Foo Include='abc'/>
+                                       <Foo Include='def'/>
+                               </ItemGroup>
+                               <PropertyGroup>
+                                       <FooProp>PropValue/</FooProp>
+                               </PropertyGroup>
+
+                               <Target Name=""main"">
+                                       <CreateItem Include=""@(Foo)"">
+                                               <Output TaskParameter =""Include"" ItemName=""SyntheticFoo""/>
+                                       </CreateItem>
+
+                                       <BatchingTestTask
+                                               TaskItemsOutput=""@(SyntheticFoo->'$(FooProp)%(Identity).txt')"">
+                                               <Output TaskParameter='TaskItemsOutput' ItemName='I0' />
+                                       </BatchingTestTask>
+                               </Target>
+                       </Project>";
+
+                       Engine engine = new Engine (Consts.BinPath);
+                       MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger =
+                               new MonoTests.Microsoft.Build.Tasks.TestMessageLogger ();
+                       engine.RegisterLogger (logger);
+                       Project project = engine.CreateNewProject ();
+                       project.LoadXml (projectText);
+
+                       bool result = project.Build ("main");
+                       if (!result) {
+                               logger.DumpMessages ();
+                               Assert.Fail ("Build failed");
+                       }
+
+                       BuildItemGroup grp = project.GetEvaluatedItemsByName ("I0");
+                       Assert.AreEqual (2, grp.Count, "A1");
+                       Assert.AreEqual ("PropValue/abc.txt", grp [0].FinalItemSpec, "A2");
+                       Assert.AreEqual ("PropValue/def.txt", grp [1].FinalItemSpec, "A3");
+               }
+
+               void CheckMetadata (Project p, string itemname, string metadataname, string[] values, string prefix)
+               {
+                       BuildItemGroup group = p.GetEvaluatedItemsByName (itemname);
+
+                       Assert.AreEqual (values.Length, group.Count, "Number of items for itemname " + itemname);
+
+                       for (int i = 0; i < values.Length; i++) {
+                               Assert.AreEqual (values[i], group [i].GetMetadata (metadataname), prefix + "#" + i.ToString ());
+                       }
+               }
+
+               void CheckEvaluatedMetadata (Project p, string itemname, string metadataname, string[] values, string prefix)
+               {
+                       BuildItemGroup group = p.GetEvaluatedItemsByName (itemname);
+
+                       Assert.AreEqual (values.Length, group.Count, "Number of items for itemname " + itemname);
+
+                       for (int i = 0; i < values.Length; i++) {
+                               Assert.AreEqual (values[i], group [i].GetEvaluatedMetadata (metadataname), prefix + "#" + i.ToString ());
+                       }
+               }
+
+               void CheckBuildItemGroup (BuildItemGroup group, string[] names, string prefix)
+               {
+                       try {
+                               Assert.AreEqual (group.Count, names.Length / 2, "Number of items in group");
+                               for (int i = 0; i < group.Count; i++) {
+                                       Assert.AreEqual (names[i * 2], group[i].Name, String.Format ("{0}#{1} : item name", prefix, i));
+                                       Assert.AreEqual (names[(i * 2) + 1], group[i].FinalItemSpec, String.Format ("{0}#{1} : FinalItemSpec", prefix, i));
+                               }
+                       } catch (AssertionException) {
+                               for (int i = 0; i < group.Count; i++) {
+                                       Console.WriteLine ("group[{0}] = {1}", i, group[i].Name);
+                                       Console.WriteLine ("group[{0}] = {1}", i, group[i].FinalItemSpec);
+                               }
+                               throw;
+                       }
+               }
        }
 }