void CreateAndCheckGlobalPropertiesImportTest(string main, string first) { string basePath = Path.Combine("Test", "resources"); string testProject = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> </Project>"; File.WriteAllText(Path.Combine(basePath, "main.proj"), main); File.WriteAllText(Path.Combine(basePath, "first.proj"), first); File.WriteAllText(Path.Combine(basePath, "test.proj"), testProject); try { Engine engine = new Engine(); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger(); engine.RegisterLogger(logger); Project project = engine.CreateNewProject(); project.Load(Path.Combine(basePath, "main.proj")); bool result = project.Build(); if (!result) { logger.DumpMessages(); Assert.Fail("Build failed"); } logger.CheckAny("Prop: test", MessageImportance.Normal); Assert.AreEqual(0, logger.NormalMessageCount, "Unexpected extra messages found"); } finally { File.Delete(Path.Combine(basePath, "main.proj")); File.Delete(Path.Combine(basePath, "first.proj")); File.Delete(Path.Combine(basePath, "test.proj")); } }
public void TestImportWildcard() { string main_project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""4.0""> <ItemGroup> <FooItem Include=""From main.proj""/> </ItemGroup> <Import Project=""tmp\*""/> <Target Name=""Build""> <Message Text=""FooItem: @(FooItem)""/> </Target> </Project>" ; string other_project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""4.0""> <ItemGroup> <FooItem Include=""From $(MSBuildThisFile)""/> </ItemGroup> </Project>" ; Engine engine = new Engine(Consts.BinPath); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger(); engine.RegisterLogger(logger); string base_dir = Path.GetFullPath(Path.Combine("Test", "resources")) + Path.DirectorySeparatorChar; string tmp_dir = Path.GetFullPath(Path.Combine(base_dir, "tmp")) + Path.DirectorySeparatorChar; string main_project = Path.Combine(base_dir, "main.proj"); string first_project = Path.Combine(tmp_dir, "first.proj"); string second_project = Path.Combine(tmp_dir, "second.proj"); Directory.CreateDirectory(tmp_dir); File.WriteAllText(main_project, main_project_xml); File.WriteAllText(first_project, other_project_xml); File.WriteAllText(second_project, other_project_xml); Project project = engine.CreateNewProject(); project.Load(main_project); try { Assert.IsTrue(project.Build("Build"), "Build failed"); logger.CheckLoggedMessageHead("FooItem: From main.proj;From first.proj;From second.proj", "A1"); Assert.AreEqual(0, logger.NormalMessageCount, "Unexpected extra messages found"); } catch { logger.DumpMessages(); throw; } finally { File.Delete(main_project); File.Delete(first_project); File.Delete(second_project); } }
public void TestBeforeAndAfterTargets() { Engine engine; Project project; string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""4.0""> <Target Name=""DefaultBeforeTarget1"" BeforeTargets=""Default""> <Message Text=""Hello from DefaultBeforeTarget1""/> </Target> <Target Name=""DefaultBeforeTarget2"" BeforeTargets=""Default;Default;NonExistant""> <Message Text=""Hello from DefaultBeforeTarget2""/> </Target> <Target Name=""DefaultAfterTarget"" AfterTargets=""Default ; Foo""> <Message Text=""Hello from DefaultAfterTarget""/> </Target> <Target Name=""Default"" DependsOnTargets=""DefaultDependsOn""> <Message Text=""Hello from Default""/> </Target> <Target Name=""DefaultDependsOn""> <Message Text=""Hello from DefaultDependsOn""/> </Target> </Project>" ; engine = new Engine(); project = engine.CreateNewProject(); project.LoadXml(projectString); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger(); engine.RegisterLogger(logger); if (!project.Build("Default")) { logger.DumpMessages(); Assert.Fail("Build failed"); } logger.CheckLoggedMessageHead("Hello from DefaultDependsOn", "A1"); logger.CheckLoggedMessageHead("Hello from DefaultBeforeTarget1", "A1"); logger.CheckLoggedMessageHead("Hello from DefaultBeforeTarget2", "A1"); logger.CheckLoggedMessageHead("Hello from Default", "A1"); logger.CheckLoggedMessageHead("Hello from DefaultAfterTarget", "A1"); Assert.AreEqual(0, logger.NormalMessageCount, "Unexpected messages found"); //warnings for referencing unknown targets: NonExistant and Foo Assert.AreEqual(2, logger.WarningsCount, "Expected warnings not raised"); }
public void TestOverridingTargets() { Engine engine; Project project; string second = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <Target Name='BeforeBuild'/> <Target Name='AfterBuild'/> <Target Name='Build' DependsOnTargets='BeforeBuild'> <Message Text='Build executing'/> <CallTarget Targets='AfterBuild'/> </Target> </Project>" ; using (StreamWriter sw = new StreamWriter(Path.Combine("Test", Path.Combine("resources", "second.proj")))) { sw.Write(second); } string documentString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <Target Name='AfterBuild'> <Message Text='Overriding AfterBuild'/> </Target> <Import Project='Test/resources/second.proj'/> <Target Name='BeforeBuild'> <Message Text='Overriding BeforeBuild'/> </Target> </Project>" ; engine = new Engine(Consts.BinPath); project = engine.CreateNewProject(); project.LoadXml(documentString); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger(); engine.RegisterLogger(logger); bool result = project.Build("Build"); if (!result) { logger.DumpMessages(); Assert.Fail("Build failed"); } logger.CheckLoggedMessageHead("Overriding BeforeBuild", "A1"); logger.CheckLoggedMessageHead("Build executing", "A1"); Assert.AreEqual(0, logger.NormalMessageCount, "Unexpected extra messages found"); }
public void TestLazyLoad1() { string documentString = @" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <UsingTask AssemblyFile='NonExistantAssembly.dll' TaskName='SimpleTask' /> <Target Name='1'> <Message Text='hello'/> </Target> <Target Name='2'> <SimpleTask Foo='bar'/> </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); if (!project.Build("1")) { logger.DumpMessages(); Assert.Fail("Build failed"); } if (project.Build("2")) { Assert.Fail("Build should've failed, as a task from a nonexistant assembly is referenced"); } IEnumerator en = project.UsingTasks.GetEnumerator(); en.MoveNext(); UsingTask ut = (UsingTask)en.Current; Assert.AreEqual("NonExistantAssembly.dll", ut.AssemblyFile, "A1"); Assert.IsNull(ut.AssemblyName, "A2"); Assert.AreEqual(null, ut.Condition, "A3"); Assert.AreEqual(false, ut.IsImported, "A4"); Assert.AreEqual("SimpleTask", ut.TaskName, "A5"); }
void CheckLoggedMessages(MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger, string [] messages, string prefix) { try { for (int i = 0; i < messages.Length; i++) { logger.CheckLoggedMessageHead(messages [i], String.Format("{0} #{1}", prefix, i)); } } catch { logger.DumpMessages(); throw; } Assert.AreEqual(0, logger.NormalMessageCount, "Number of remaining messages"); }
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 CheckEventCounts(MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger, int project, int target, int task) { try { Assert.AreEqual(project, logger.ProjectStarted, "#project started events"); Assert.AreEqual(project, logger.ProjectFinished, "#project finished events"); Assert.AreEqual(target, logger.TargetStarted, "#target started events"); Assert.AreEqual(target, logger.TargetFinished, "#target finished events"); Assert.AreEqual(task, logger.TaskStarted, "#task started events"); Assert.AreEqual(task, logger.TaskFinished, "#task finished events"); Assert.AreEqual(1, logger.BuildStarted, "#build started events"); Assert.AreEqual(1, logger.BuildFinished, "#build finished events"); } catch (AssertionException) { logger.DumpMessages(); throw; } }
public void TestDuplicate1() { string documentString = @" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <UsingTask AssemblyFile='Test/resources/TestTasks.dll' TaskName='TrueTestTask' /> <UsingTask AssemblyFile='Test/resources/TestTasks.dll' TaskName='TrueTestTask' /> <Target Name='1'> <TrueTestTask/> </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); if (!project.Build("1")) { logger.DumpMessages(); Assert.Fail("Build failed"); } Assert.AreEqual(2, project.UsingTasks.Count, "A0"); foreach (UsingTask ut in project.UsingTasks) { Assert.AreEqual("Test/resources/TestTasks.dll", ut.AssemblyFile, "A1"); Assert.IsNull(ut.AssemblyName, "A2"); Assert.AreEqual(null, ut.Condition, "A3"); Assert.AreEqual(false, ut.IsImported, "A4"); Assert.AreEqual("TrueTestTask", ut.TaskName, "A5"); } }
public void TestLazyLoad3() { string documentString = @" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <UsingTask AssemblyFile='Test/resources/TestTasks.dll' TaskName='Another.SameTask' Condition='false' /> <Target Name='1'> <Another.SameTask /> </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); IEnumerator en = project.UsingTasks.GetEnumerator(); en.MoveNext(); UsingTask ut = (UsingTask)en.Current; Assert.AreEqual("Test/resources/TestTasks.dll", ut.AssemblyFile, "A1"); Assert.IsNull(ut.AssemblyName, "A2"); Assert.AreEqual("false", ut.Condition, "A3"); Assert.AreEqual(false, ut.IsImported, "A4"); Assert.AreEqual("Another.SameTask", ut.TaskName, "A5"); if (project.Build("1")) { logger.DumpMessages(); Assert.Fail("Build should've failed"); } }
public void TestLazyLoad2() { string documentString = @" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <UsingTask AssemblyFile='Test/resources/TestTasks.dll' TaskName='Another.SameTask' /> <UsingTask AssemblyFile='Test/resources/TestTasks.dll' TaskName='Other.SameTask' /> <Target Name='1'> <Other.SameTask> <Output TaskParameter='OutputString' ItemName='I0'/> </Other.SameTask> <Another.SameTask> <Output TaskParameter='OutputString' ItemName='I1'/> </Another.SameTask> <Message Text='I0: @(I0) I1: @(I1)'/> </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); if (!project.Build("1")) { logger.DumpMessages(); Assert.Fail("Build failed"); } logger.CheckLoggedMessageHead("I0: Other.SameTask I1: Another.SameTask", "A1"); }
private MonoTests.Microsoft.Build.Tasks.TestMessageLogger ItemGroupInsideATarget() { var engine = new Engine(Consts.BinPath); var project = engine.CreateNewProject(); var projectXml = GetProjectXmlWithItemGroupInsideATarget(); project.LoadXml(projectXml); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger(); engine.RegisterLogger(logger); bool result = project.Build("Main"); if (!result) { logger.DumpMessages(); Assert.Fail("Build failed"); } return(logger); }
void CreateAndCheckGlobalPropertiesTest(string main, string first, string second, BuildPropertyGroup engine_globals, BuildPropertyGroup project_globals, int project_count, int target_count, int task_count, string [] messages) { WriteGlobalPropertiesProjects(main, first, second); Engine engine = new Engine(Consts.BinPath); if (engine_globals != null) { engine.GlobalProperties = engine_globals; } MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger(); engine.RegisterLogger(logger); Project project = engine.CreateNewProject(); project.Load(Path.Combine("Test", Path.Combine("resources", "main.proj"))); if (project_globals != null) { project.GlobalProperties = project_globals; } bool result = project.Build(); if (!result) { logger.DumpMessages(); Assert.Fail("Build failed"); } CheckEventCounts(logger, project_count, target_count, task_count); CheckLoggedMessages(logger, messages, "A1"); }
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"); }
public void TestImportWildcard () { string main_project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""4.0""> <ItemGroup> <FooItem Include=""From main.proj""/> </ItemGroup> <Import Project=""tmp\*""/> <Target Name=""Build""> <Message Text=""FooItem: @(FooItem)""/> </Target> </Project>"; string other_project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""4.0""> <ItemGroup> <FooItem Include=""From $(MSBuildThisFile)""/> </ItemGroup> </Project>"; Engine engine = new Engine (Consts.BinPath); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); engine.RegisterLogger (logger); string base_dir = Path.GetFullPath (Path.Combine ("Test", "resources")) + Path.DirectorySeparatorChar; string tmp_dir = Path.GetFullPath (Path.Combine (base_dir, "tmp")) + Path.DirectorySeparatorChar; string main_project = Path.Combine (base_dir, "main.proj"); string first_project = Path.Combine (tmp_dir, "first.proj"); string second_project = Path.Combine (tmp_dir, "second.proj"); Directory.CreateDirectory (tmp_dir); File.WriteAllText (main_project, main_project_xml); File.WriteAllText (first_project, other_project_xml); File.WriteAllText (second_project, other_project_xml); Project project = engine.CreateNewProject (); project.Load (main_project); try { Assert.IsTrue (project.Build ("Build"), "Build failed"); logger.CheckLoggedMessageHead ("FooItem: From main.proj;From first.proj;From second.proj", "A1"); Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected extra messages found"); } catch { logger.DumpMessages (); throw; } finally { File.Delete (main_project); File.Delete (first_project); File.Delete (second_project); } }
public void TestBeforeAndAfterTargets () { Engine engine; Project project; string projectString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" ToolsVersion=""4.0""> <Target Name=""DefaultBeforeTarget1"" BeforeTargets=""Default""> <Message Text=""Hello from DefaultBeforeTarget1""/> </Target> <Target Name=""DefaultBeforeTarget2"" BeforeTargets=""Default;Default;NonExistant""> <Message Text=""Hello from DefaultBeforeTarget2""/> </Target> <Target Name=""DefaultAfterTarget"" AfterTargets=""Default ; Foo""> <Message Text=""Hello from DefaultAfterTarget""/> </Target> <Target Name=""Default"" DependsOnTargets=""DefaultDependsOn""> <Message Text=""Hello from Default""/> </Target> <Target Name=""DefaultDependsOn""> <Message Text=""Hello from DefaultDependsOn""/> </Target> </Project>"; engine = new Engine (); project = engine.CreateNewProject (); project.LoadXml (projectString); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); engine.RegisterLogger (logger); if (!project.Build ("Default")) { logger.DumpMessages (); Assert.Fail ("Build failed"); } logger.CheckLoggedMessageHead ("Hello from DefaultDependsOn", "A1"); logger.CheckLoggedMessageHead ("Hello from DefaultBeforeTarget1", "A1"); logger.CheckLoggedMessageHead ("Hello from DefaultBeforeTarget2", "A1"); logger.CheckLoggedMessageHead ("Hello from Default", "A1"); logger.CheckLoggedMessageHead ("Hello from DefaultAfterTarget", "A1"); Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected messages found"); //warnings for referencing unknown targets: NonExistant and Foo Assert.AreEqual (2, logger.WarningsCount, "Expected warnings not raised"); }
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"); }
// test item metadata public void TestItems10 () { string project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <PropertyGroup> <Prop1>@(Item0)</Prop1> <Prop2>@(Ref1)</Prop2> </PropertyGroup> <ItemGroup> <Item0 Include=""Foo""/> <Ref1 Include=""File1"" /> <IWithM Include=""A""> <Md>@(Item0)</Md> <Md2>$(Prop2)</Md2> </IWithM> </ItemGroup> <Target Name=""1""> <Message Text=""IWithM.md: %(IWithM.Md)""/> <Message Text=""IWithM.md2: %(IWithM.Md2)""/> <CreateItem Include=""Bar;Xyz""> <Output TaskParameter=""Include"" ItemName=""Item0""/> </CreateItem> <Message Text=""IWithM.md: %(IWithM.Md)""/> <Message Text=""IWithM.md2: %(IWithM.Md2)""/> </Target> </Project> "; Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); proj.LoadXml (project_xml); engine.RegisterLogger (logger); if (!proj.Build ("1")) { logger.DumpMessages (); Assert.Fail ("Build failed"); } logger.CheckLoggedMessageHead ("IWithM.md: Foo", "A1"); logger.CheckLoggedMessageHead ("IWithM.md2: File1", "A2"); logger.CheckLoggedMessageHead ("IWithM.md: Foo", "A3"); logger.CheckLoggedMessageHead ("IWithM.md2: File1", "A4"); Assert.AreEqual (0, logger.NormalMessageCount, "unexpected messages found"); }
// test properties and item refs, with dynamic properties/items public void TestItems12 () { string project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <PropertyGroup> <Prop2>@(Ref1)</Prop2> </PropertyGroup> <ItemGroup> <Ref1 Include=""File1"" /> <Files Include=""@(Ref1)""/> </ItemGroup> <Target Name=""1""> <Message Text=""Prop2: $(Prop2)""/> <Message Text=""Files: @(Files)""/> <CreateItem Include=""foobar""> <Output TaskParameter=""Include"" ItemName=""Ref1""/> </CreateItem> <Message Text=""Files: @(Files)""/> <Message Text=""Prop2: $(Prop2)""/> <CreateProperty Value=""NewValue""> <Output TaskParameter=""Value"" PropertyName=""Prop2""/> </CreateProperty> <Message Text=""Prop2: $(Prop2)""/> </Target> </Project> "; Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); proj.LoadXml (project_xml); engine.RegisterLogger (logger); if (!proj.Build ("1")) { logger.DumpMessages (); Assert.Fail ("Build failed"); } logger.DumpMessages (); logger.CheckLoggedMessageHead ("Prop2: File1", "A1"); logger.CheckLoggedMessageHead ("Files: File1", "A1"); logger.CheckLoggedMessageHead ("Files: File1", "A1"); logger.CheckLoggedMessageHead ("Prop2: File1;foobar", "A1"); logger.CheckLoggedMessageHead ("Prop2: NewValue", "A1"); Assert.AreEqual (0, logger.NormalMessageCount, "unexpected messages found"); }
void CreateAndCheckGlobalPropertiesImportTest (string main, string first) { string basePath = Path.Combine ("Test", "resources"); string testProject = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> </Project>"; File.WriteAllText (Path.Combine (basePath, "main.proj"), main); File.WriteAllText (Path.Combine (basePath, "first.proj"), first); File.WriteAllText (Path.Combine (basePath, "test.proj"), testProject); try { Engine engine = new Engine (); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); engine.RegisterLogger (logger); Project project = engine.CreateNewProject (); project.Load (Path.Combine (basePath, "main.proj")); bool result = project.Build (); if (!result) { logger.DumpMessages (); Assert.Fail ("Build failed"); } logger.CheckAny ("Prop: test", MessageImportance.Normal); Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected extra messages found"); } finally { File.Delete (Path.Combine (basePath, "main.proj")); File.Delete (Path.Combine (basePath, "first.proj")); File.Delete (Path.Combine (basePath, "test.proj")); } }
public void TestReservedMetadata () { Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); engine.RegisterLogger (logger); string documentString = @" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <ItemGroup><File1 Include=""bar\foo.dll""/></ItemGroup> <Target Name='Main'> <Message Text='file1: @(File1)'/> <Message Text='file1: RootDir: %(File1.RootDir)'/> <Message Text='file1: Directory: %(File1.Directory)'/> </Target> </Project>"; string projectdir = Path.Combine ("Test", "resources"); File.WriteAllText (Path.Combine (projectdir, "test1.proj"), documentString); proj.Load (Path.Combine (projectdir, "test1.proj")); if (!proj.Build ("Main")) { logger.DumpMessages (); Assert.Fail ("Build failed"); } logger.DumpMessages (); logger.CheckLoggedMessageHead ("file1: " + Path.Combine ("bar", "foo.dll"), "A1"); string path_root = Path.GetPathRoot (Path.GetFullPath (projectdir)); logger.CheckLoggedMessageHead ("file1: RootDir: " + path_root, "A2"); string fullpath = Path.GetFullPath (Path.Combine (projectdir, "bar")); logger.CheckLoggedMessageHead ("file1: Directory: " + fullpath.Substring (path_root.Length) + Path.DirectorySeparatorChar, "A3"); if (logger.NormalMessageCount != 0) { logger.DumpMessages (); Assert.Fail ("Unexpected extra messages found"); } }
public void TestMetadataFromItemReferences () { string project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <ItemGroup> <Item1 Include=""Item1Val1;Item1Val2""> <Item1Md>False</Item1Md> </Item1> <Item2 Include=""Val1;Val2;@(Item1);Val3""> <Name>Random name</Name> </Item2> <Item3 Include=""foo;bar;@(Item2);Last""/> </ItemGroup> <Target Name=""Main""> <CreateItem Include=""@(Item3)""> <Output TaskParameter=""Include"" ItemName=""Final""/> </CreateItem> <Message Text=""Final: %(Final.Identity) Item1Md: %(Final.Item1Md) Name: %(Final.Name)""/> </Target> </Project>"; Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); proj.LoadXml (project_xml); engine.RegisterLogger (logger); if (!proj.Build ("Main")) { logger.DumpMessages (); Assert.Fail ("Build failed"); } CheckItems (proj, "Final", "Z", "foo", "bar", "Val1", "Val2", "Item1Val1", "Item1Val2", "Val3", "Last"); logger.CheckLoggedMessageHead ("Final: foo Item1Md: Name: ", "A1"); logger.CheckLoggedMessageHead ("Final: bar Item1Md: Name: ", "A2"); logger.CheckLoggedMessageHead ("Final: Val1 Item1Md: Name: Random name", "A3"); logger.CheckLoggedMessageHead ("Final: Val2 Item1Md: Name: Random name", "A4"); logger.CheckLoggedMessageHead ("Final: Item1Val1 Item1Md: False Name: Random name", "A5"); logger.CheckLoggedMessageHead ("Final: Item1Val2 Item1Md: False Name: Random name", "A6"); logger.CheckLoggedMessageHead ("Final: Val3 Item1Md: Name: Random name", "A7"); logger.CheckLoggedMessageHead ("Final: Last Item1Md: Name: ", "A8"); Assert.AreEqual (0, logger.NormalMessageCount, "unexpected messages found"); }
public void TestEmptyItemsWithBatching () { string project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' /> <UsingTask TaskName='TestTask_TaskItem' AssemblyFile='Test\resources\TestTasks.dll' /> <UsingTask TaskName='TestTask_TaskItems' AssemblyFile='Test\resources\TestTasks.dll' /> <Target Name=""1""> <StringTestTask Property=""%(Item4.Identity)""> <Output TaskParameter=""OutputString"" PropertyName=""OutputString""/> </StringTestTask> <Message Text='output1: $(OutputString)'/> <StringTestTask Property="" %(Item4.Identity)""> <Output TaskParameter=""OutputString"" PropertyName=""OutputString""/> </StringTestTask> <Message Text='output2: $(OutputString)'/> <StringTestTask Array=""%(Item4.Identity)""> <Output TaskParameter=""OutputString"" PropertyName=""OutputString""/> </StringTestTask> <Message Text='output3: $(OutputString)'/> <StringTestTask Array="" %(Item4.Identity)""> <Output TaskParameter=""OutputString"" PropertyName=""OutputString""/> </StringTestTask> <Message Text='output4: $(OutputString)'/> <TestTask_TaskItem Property=""%(Item4.Identity)""> <Output TaskParameter=""Output"" PropertyName=""OutputString""/> </TestTask_TaskItem> <Message Text='output5: $(OutputString)'/> <TestTask_TaskItem Property="" %(Item4.Identity)""> <Output TaskParameter=""Output"" PropertyName=""OutputString""/> </TestTask_TaskItem> <Message Text='output6: $(OutputString)'/> <TestTask_TaskItems Property="" %(Item4.Identity)""> <Output TaskParameter=""Output"" PropertyName=""OutputString""/> </TestTask_TaskItems> <Message Text='output7: $(OutputString)'/> <!-- no space in property --> <TestTask_TaskItems Property=""%(Item4.Identity)""> <Output TaskParameter=""Output"" PropertyName=""OutputString""/> </TestTask_TaskItems> <Message Text='output8: $(OutputString)'/> </Target> </Project> "; Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); proj.LoadXml (project_xml); engine.RegisterLogger (logger); if (!proj.Build ("1")) { logger.DumpMessages (); Assert.Fail ("Build failed"); } logger.DumpMessages (); logger.CheckLoggedMessageHead ("output1: property: null ## array: null", "A1"); logger.CheckLoggedMessageHead ("output2: property: ## array: null", "A2"); logger.CheckLoggedMessageHead ("output3: property: null ## array: null", "A3"); logger.CheckLoggedMessageHead ("output4: property: null ## array: null", "A4"); logger.CheckLoggedMessageHead ("output5: null", "A5"); logger.CheckLoggedMessageHead ("output6: null", "A6"); logger.CheckLoggedMessageHead ("output7: null", "A7"); logger.CheckLoggedMessageHead ("output8: null", "A8"); Assert.AreEqual (0, logger.NormalMessageCount, "unexpected messages found"); }
public void TestTargetOutputsIncludingMetadata() { Engine engine; Project project; string documentString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <ItemGroup> <fruit Include=""apple""><md>a</md></fruit> <fruit Include=""rhubarb""><md>b</md></fruit> <fruit Include=""apricot""><md>c</md></fruit> </ItemGroup> <Target Name=""Main""> <CallTarget Targets=""foo""> <Output TaskParameter=""TargetOutputs"" ItemName=""AllOut""/> </CallTarget> <CallTarget Targets=""foo""> <Output TaskParameter=""TargetOutputs"" ItemName=""AllOut""/> </CallTarget> <Message Text=""AllOut: @(AllOut) metadata: %(AllOut.md)""/> </Target> <Target Name=""foo"" Outputs=""@(FooItem)""> <Message Text=""foo called""/> <CreateItem Include=""@(fruit)""> <Output TaskParameter=""Include"" ItemName=""FooItem""/> </CreateItem> <Message Text=""FooItem: @(FooItem) metadata: %(FooItem.md)""/> </Target> </Project>" ; engine = new Engine(Consts.BinPath); project = engine.CreateNewProject(); project.LoadXml(documentString); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger(); engine.RegisterLogger(logger); bool result = project.Build("Main"); if (!result) { logger.DumpMessages(); Assert.Fail("Build failed"); } try { logger.CheckLoggedMessageHead("foo called", "A1"); logger.CheckLoggedMessageHead("FooItem: apple metadata: a", "A2"); logger.CheckLoggedMessageHead("FooItem: rhubarb metadata: b", "A3"); logger.CheckLoggedMessageHead("FooItem: apricot metadata: c", "A4"); logger.CheckLoggedMessageHead("AllOut: apple;apple metadata: a", "A5"); logger.CheckLoggedMessageHead("AllOut: rhubarb;rhubarb metadata: b", "A6"); logger.CheckLoggedMessageHead("AllOut: apricot;apricot metadata: c", "A7"); Assert.AreEqual(0, logger.NormalMessageCount, "Extra messages found"); Assert.AreEqual(2, logger.TargetStarted, "TargetStarted count"); Assert.AreEqual(2, logger.TargetFinished, "TargetFinished count"); Assert.AreEqual(10, logger.TaskStarted, "TaskStarted count"); Assert.AreEqual(10, logger.TaskFinished, "TaskFinished count"); } catch (AssertionException) { logger.DumpMessages(); throw; } }
public void TestTargetOutputsIncludingMetadata () { Engine engine; Project project; string documentString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <ItemGroup> <fruit Include=""apple""><md>a</md></fruit> <fruit Include=""rhubarb""><md>b</md></fruit> <fruit Include=""apricot""><md>c</md></fruit> </ItemGroup> <Target Name=""Main""> <CallTarget Targets=""foo""> <Output TaskParameter=""TargetOutputs"" ItemName=""AllOut""/> </CallTarget> <CallTarget Targets=""foo""> <Output TaskParameter=""TargetOutputs"" ItemName=""AllOut""/> </CallTarget> <Message Text=""AllOut: @(AllOut) metadata: %(AllOut.md)""/> </Target> <Target Name=""foo"" Outputs=""@(FooItem)""> <Message Text=""foo called""/> <CreateItem Include=""@(fruit)""> <Output TaskParameter=""Include"" ItemName=""FooItem""/> </CreateItem> <Message Text=""FooItem: @(FooItem) metadata: %(FooItem.md)""/> </Target> </Project>"; engine = new Engine (Consts.BinPath); project = engine.CreateNewProject (); project.LoadXml (documentString); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); engine.RegisterLogger (logger); bool result = project.Build ("Main"); if (!result) { logger.DumpMessages (); Assert.Fail ("Build failed"); } try { logger.CheckLoggedMessageHead ("foo called", "A1"); logger.CheckLoggedMessageHead ("FooItem: apple metadata: a", "A2"); logger.CheckLoggedMessageHead ("FooItem: rhubarb metadata: b", "A3"); logger.CheckLoggedMessageHead ("FooItem: apricot metadata: c", "A4"); logger.CheckLoggedMessageHead ("AllOut: apple;apple metadata: a", "A5"); logger.CheckLoggedMessageHead ("AllOut: rhubarb;rhubarb metadata: b", "A6"); logger.CheckLoggedMessageHead ("AllOut: apricot;apricot metadata: c", "A7"); Assert.AreEqual (0, logger.NormalMessageCount, "Extra messages found"); Assert.AreEqual (2, logger.TargetStarted, "TargetStarted count"); Assert.AreEqual (2, logger.TargetFinished, "TargetFinished count"); Assert.AreEqual (10, logger.TaskStarted, "TaskStarted count"); Assert.AreEqual (10, logger.TaskFinished, "TaskFinished count"); } catch (AssertionException) { logger.DumpMessages (); throw; } }
public void TestOverridingTargets () { Engine engine; Project project; string second = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <Target Name='BeforeBuild'/> <Target Name='AfterBuild'/> <Target Name='Build' DependsOnTargets='BeforeBuild'> <Message Text='Build executing'/> <CallTarget Targets='AfterBuild'/> </Target> </Project>"; using (StreamWriter sw = new StreamWriter (Path.Combine ("Test", Path.Combine ("resources", "second.proj")))) { sw.Write (second); } string documentString = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <Target Name='AfterBuild'> <Message Text='Overriding AfterBuild'/> </Target> <Import Project='Test/resources/second.proj'/> <Target Name='BeforeBuild'> <Message Text='Overriding BeforeBuild'/> </Target> </Project>"; engine = new Engine (Consts.BinPath); project = engine.CreateNewProject (); project.LoadXml (documentString); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); engine.RegisterLogger (logger); bool result = project.Build ("Build"); if (!result) { logger.DumpMessages (); Assert.Fail ("Build failed"); } logger.CheckLoggedMessageHead ("Overriding BeforeBuild", "A1"); logger.CheckLoggedMessageHead ("Build executing", "A1"); Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected extra messages found"); }
//Test with string public void TestItemsInTarget3c () { Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger(); engine.RegisterLogger(logger); string documentString = @" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <UsingTask TaskName='BatchingTestTask' AssemblyFile='Test\resources\TestTasks.dll' /> <PropertyGroup> <A>A</A> <B>A;B</B> <C>A;;</C> <D>$(C);Foo</D> </PropertyGroup> <ItemGroup> <A Include='A;B;;;C' /> </ItemGroup>"; documentString += CreateTargetFragment ("BatchingTestTask", "SingleString", "SingleStringOutput", "I", new string [] { "$(A)$(A)", "$(B)$(B)", "$(C)", "$(C)$(C)", "$(C) $(C)", "@(A);$(C)", "@(A);A;B;C", "@(A) $(C) @(A)", }) + "</Project>"; proj.LoadXml (documentString); if (!proj.Build("1")) { logger.DumpMessages(); Assert.Fail("Build failed"); } BuildProperty bp = proj.EvaluatedProperties ["D"]; Assert.AreEqual ("$(C);Foo", bp.Value, "B0"); Assert.AreEqual ("A;;;Foo", bp.FinalValue, "B1"); bp = proj.EvaluatedProperties ["C"]; Assert.AreEqual ("A;;", bp.Value, "B3"); Assert.AreEqual ("A;;", bp.FinalValue, "B4"); CheckItems (proj, "I0", "A0", "AA"); CheckItems (proj, "I1", "A1", "A;BA;B"); CheckItems (proj, "I2", "A2", "A;;"); CheckItems (proj, "I3", "A3", "A;;A;;"); CheckItems (proj, "I4", "A4", "A;; A;;"); CheckItems (proj, "I5", "A5", "A;B;C;A;;"); CheckItems (proj, "I6", "A6", "A;B;C;A;B;C"); CheckItems (proj, "I7", "A7", "A;B;C A;; A;B;C"); }
public void TestLazyLoad1 () { string documentString = @" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <UsingTask AssemblyFile='NonExistantAssembly.dll' TaskName='SimpleTask' /> <Target Name='1'> <Message Text='hello'/> </Target> <Target Name='2'> <SimpleTask Foo='bar'/> </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); if (!project.Build ("1")) { logger.DumpMessages (); Assert.Fail ("Build failed"); } if (project.Build ("2")) Assert.Fail ("Build should've failed, as a task from a nonexistant assembly is referenced"); IEnumerator en = project.UsingTasks.GetEnumerator (); en.MoveNext (); UsingTask ut = (UsingTask) en.Current; Assert.AreEqual ("NonExistantAssembly.dll", ut.AssemblyFile, "A1"); Assert.IsNull (ut.AssemblyName, "A2"); Assert.AreEqual (null, ut.Condition, "A3"); Assert.AreEqual (false, ut.IsImported, "A4"); Assert.AreEqual ("SimpleTask", ut.TaskName, "A5"); }
public void TestItemsWithWildcards () { Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); engine.RegisterLogger (logger); // Setup string basedir = PathCombine ("Test", "resources", "dir"); string aaa = PathCombine ("a", "aa", "aaa"); string bb = Path.Combine ("b", "bb"); string[] dirs = { aaa, bb, "c" }; string [] files = { PathCombine (basedir, aaa, "foo.dll"), PathCombine (basedir, bb, "bar.dll"), PathCombine (basedir, bb, "sample.txt"), Path.Combine (basedir, "xyz.dll") }; string documentString = @" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <ItemGroup> <ItemsRel Include='dir\**\*.dll' Exclude='*\x*.dll' /> <ItemsRelExpanded Include=""@(ItemsRel->'%(FullPath)')"" /> <ItemsAbs Include='$(MSBuildProjectDirectory)\dir\**\*.dll'/> </ItemGroup> <Target Name='Main'> <Message Text=""ItemsRel: %(ItemsRel.FullPath) RecDir: %(ItemsRel.RecursiveDir)""/> <Message Text=""ItemsRelExpanded: %(ItemsRelExpanded.Identity)""/> <Message Text='ItemsAbs: %(ItemsAbs.Identity) RecDir: %(ItemsAbs.RecursiveDir)'/> </Target> </Project>"; try { CreateDirectoriesAndFiles (basedir, dirs, files); string projectdir = Path.Combine ("Test", "resources"); File.WriteAllText (Path.Combine (projectdir, "wild1.proj"), documentString); proj.Load (Path.Combine (projectdir, "wild1.proj")); if (!proj.Build ("Main")) { logger.DumpMessages (); Assert.Fail ("Build failed"); } string full_base_dir = Path.GetFullPath (basedir); logger.CheckLoggedAny (@"ItemsRel: "+ PathCombine (full_base_dir, aaa, "foo.dll") + " RecDir: " + aaa + Path.DirectorySeparatorChar, MessageImportance.Normal, "A1"); logger.CheckLoggedAny (@"ItemsRel: " + PathCombine (full_base_dir, bb, "bar.dll") + " RecDir: " + bb + Path.DirectorySeparatorChar, MessageImportance.Normal, "A2"); logger.CheckLoggedAny (@"ItemsRelExpanded: " + PathCombine (full_base_dir, aaa, "foo.dll"), MessageImportance.Normal, "A3"); logger.CheckLoggedAny (@"ItemsRelExpanded: " + PathCombine (full_base_dir, bb, "bar.dll"), MessageImportance.Normal, "A4"); logger.CheckLoggedAny (@"ItemsAbs: " + PathCombine (full_base_dir, aaa, "foo.dll") + @" RecDir: " + aaa + Path.DirectorySeparatorChar, MessageImportance.Normal, "A5"); logger.CheckLoggedAny (@"ItemsAbs: " + PathCombine (full_base_dir, bb, "bar.dll") + @" RecDir: " + bb + Path.DirectorySeparatorChar, MessageImportance.Normal, "A6"); logger.CheckLoggedAny (@"ItemsAbs: " + PathCombine (full_base_dir, "xyz.dll") + @" RecDir: ", MessageImportance.Normal, "A7"); Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected extra messages found"); } catch (AssertionException) { logger.DumpMessages (); throw; } finally { Directory.Delete (basedir, true); } }
public void TestLazyLoad2 () { string documentString = @" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <UsingTask AssemblyFile='Test/resources/TestTasks.dll' TaskName='Another.SameTask' /> <UsingTask AssemblyFile='Test/resources/TestTasks.dll' TaskName='Other.SameTask' /> <Target Name='1'> <Other.SameTask> <Output TaskParameter='OutputString' ItemName='I0'/> </Other.SameTask> <Another.SameTask> <Output TaskParameter='OutputString' ItemName='I1'/> </Another.SameTask> <Message Text='I0: @(I0) I1: @(I1)'/> </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); if (!project.Build ("1")) { logger.DumpMessages (); Assert.Fail ("Build failed"); } logger.CheckLoggedMessageHead ("I0: Other.SameTask I1: Another.SameTask", "A1"); }
public void TestInheritedMetadataFromItemRefs2 () { Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); engine.RegisterLogger (logger); string documentString = @" <Project xmlns='http://schemas.microsoft.com/developer/msbuild/2003'> <ItemGroup> <Item5 Include='ZZ'> <MD5>Val5</MD5> </Item5> <Item0 Include='D'> <MD0>Val0</MD0> </Item0> <Item1 Include='A;@(Item0)' > <MD1>Val1</MD1> </Item1> <Item2 Include=""@(Item1,'-');@(Item5)"" /> </ItemGroup> <Target Name=""Main""> <Message Text=""Item2: %(Item2.Identity) MD0: %(Item2.MD0) MD1: %(Item2.MD1) MD5: %(Item2.MD5)""/> </Target> </Project> "; proj.LoadXml (documentString); CheckItems (proj, "Item2", "A1", "A-D", "ZZ"); if (!proj.Build ("Main")) { logger.DumpMessages (); Assert.Fail ("Build failed"); } logger.CheckLoggedMessageHead ("Item2: A-D MD0: MD1: MD5: ", "A4"); logger.CheckLoggedMessageHead ("Item2: ZZ MD0: MD1: MD5: Val5", "A5"); Assert.AreEqual (0, logger.NormalMessageCount, "Unexpected extra messages found"); }
public void TestLazyLoad3 () { string documentString = @" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <UsingTask AssemblyFile='Test/resources/TestTasks.dll' TaskName='Another.SameTask' Condition='false' /> <Target Name='1'> <Another.SameTask /> </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); IEnumerator en = project.UsingTasks.GetEnumerator (); en.MoveNext (); UsingTask ut = (UsingTask) en.Current; Assert.AreEqual ("Test/resources/TestTasks.dll", ut.AssemblyFile, "A1"); Assert.IsNull (ut.AssemblyName, "A2"); Assert.AreEqual ("false", ut.Condition, "A3"); Assert.AreEqual (false, ut.IsImported, "A4"); Assert.AreEqual ("Another.SameTask", ut.TaskName, "A5"); if (project.Build ("1")) { logger.DumpMessages (); Assert.Fail ("Build should've failed"); } }
// Test Item/prop references in conditions public void TestItems11 () { string project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <PropertyGroup> <Prop1>@(Item0)</Prop1> </PropertyGroup> <ItemGroup> <Item0 Include=""Foo""/> <Item1 Include=""@(Item0)""/> <CondItem Condition=""'@(Item1)' == '@(Item0)'"" Include=""Equal to item0""/> <CondItem Condition=""'@(Item1)' == 'Foo'"" Include=""Equal to item0's value""/> <CondItem1 Condition=""'$(Prop1)' == '@(Item0)'"" Include=""Equal to item0""/> <CondItem1 Condition=""'$(Prop1)' == 'Foo'"" Include=""Equal to item0's value""/> </ItemGroup> <Target Name=""1""> <Message Text = ""CondItem: %(CondItem.Identity)""/> <Message Text = ""CondItem1: %(CondItem1.Identity)""/> </Target> </Project> "; Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); proj.LoadXml (project_xml); engine.RegisterLogger (logger); if (!proj.Build ("1")) { logger.DumpMessages (); Assert.Fail ("Build failed"); } logger.CheckLoggedMessageHead ("CondItem: Equal to item0", "A1"); logger.CheckLoggedMessageHead ("CondItem: Equal to item0's value", "A2"); logger.CheckLoggedMessageHead ("CondItem1: Equal to item0", "A3"); logger.CheckLoggedMessageHead ("CondItem1: Equal to item0's value", "A4"); Assert.AreEqual (0, logger.NormalMessageCount, "unexpected messages found"); }
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 item refs in properties public void TestItems13 () { string project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <PropertyGroup> <Prop1>@(Item0)</Prop1> </PropertyGroup> <ItemGroup> <Item0 Include=""Foo""/> <Item1 Include=""A\B.txt;A\C.txt;B\B.zip;B\C.zip"" /> <Item2 Include=""@(Item1->'%(Extension)/$(Prop1)')"" /> </ItemGroup> <Target Name='1'> <Message Text=""Item2: @(Item2)""/> </Target> </Project>"; Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); proj.LoadXml (project_xml); engine.RegisterLogger (logger); if (!proj.Build ("1")) { logger.DumpMessages (); Assert.Fail ("Build failed"); } logger.CheckLoggedMessageHead ("Item2: .txt/@(Item0);.txt/@(Item0);.zip/@(Item0);.zip/@(Item0)", "A1"); Assert.AreEqual (0, logger.NormalMessageCount, "unexpected messages found"); }
void CreateAndCheckGlobalPropertiesTest (string main, string first, string second, BuildPropertyGroup engine_globals, BuildPropertyGroup project_globals, int project_count, int target_count, int task_count, string [] messages) { WriteGlobalPropertiesProjects (main, first, second); Engine engine = new Engine (Consts.BinPath); if (engine_globals != null) engine.GlobalProperties = engine_globals; MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); engine.RegisterLogger (logger); Project project = engine.CreateNewProject (); project.Load (Path.Combine ("Test", Path.Combine ("resources", "main.proj"))); if (project_globals != null) project.GlobalProperties = project_globals; bool result = project.Build (); if (!result) { logger.DumpMessages (); Assert.Fail ("Build failed"); } CheckEventCounts (logger, project_count, target_count, task_count); CheckLoggedMessages (logger, messages, "A1"); }
public void TestSelfRefrentialItems () { string project_xml = @"<Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <PropertyGroup> <Prop1>@(Item1);Val</Prop1> <Prop2>@(Item2)</Prop2> <Prop3>@(Item3)</Prop3> </PropertyGroup> <ItemGroup> <Item1 Include=""Item1OldVal""/> <Item1 Include=""@(Item1);$(Prop1)""/> <Item2 Include=""Item2OldVal""/> <Item2 Include=""@(Item2->'%(Identity)');$(Prop2)""/> <Item3 Include=""Item3OldVal""/> <Item3 Include=""@(Item3, '_');$(Prop3)""/> <Item4 Include=""@(Item4)""/> </ItemGroup> <Target Name=""1""> <Message Text=""Item1: %(Item1.Identity)""/> <Message Text=""Item2: %(Item2.Identity)""/> <Message Text=""Item3: %(Item3.Identity)""/> <Message Text=""%(Item4.Identity)""/> <Message Text=""Item4: %(Item4.Identity)""/> </Target> </Project> "; Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); proj.LoadXml (project_xml); engine.RegisterLogger (logger); if (!proj.Build ("1")) { logger.DumpMessages (); Assert.Fail ("Build failed"); } logger.DumpMessages (); logger.CheckLoggedMessageHead ("Item1: Item1OldVal", "A1"); logger.CheckLoggedMessageHead ("Item1: Val", "A2"); logger.CheckLoggedMessageHead ("Item2: Item2OldVal", "A3"); logger.CheckLoggedMessageHead ("Item3: Item3OldVal", "A4"); logger.CheckLoggedMessageHead ("Item4: ", "A5"); Assert.AreEqual (0, logger.NormalMessageCount, "unexpected messages found"); }
public void TestDuplicate1 () { string documentString = @" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <UsingTask AssemblyFile='Test/resources/TestTasks.dll' TaskName='TrueTestTask' /> <UsingTask AssemblyFile='Test/resources/TestTasks.dll' TaskName='TrueTestTask' /> <Target Name='1'> <TrueTestTask/> </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); if (!project.Build ("1")) { logger.DumpMessages (); Assert.Fail ("Build failed"); } Assert.AreEqual (2, project.UsingTasks.Count, "A0"); foreach (UsingTask ut in project.UsingTasks) { Assert.AreEqual ("Test/resources/TestTasks.dll", ut.AssemblyFile, "A1"); Assert.IsNull (ut.AssemblyName, "A2"); Assert.AreEqual (null, ut.Condition, "A3"); Assert.AreEqual (false, ut.IsImported, "A4"); Assert.AreEqual ("TrueTestTask", ut.TaskName, "A5"); } }
public void TestItemsInTarget1 () { Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); string documentString = @" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <UsingTask TaskName='StringTestTask' AssemblyFile='Test\resources\TestTasks.dll' /> <PropertyGroup> <A>A</A> <B>@(A)g</B> </PropertyGroup> <ItemGroup> <A Include='A;B;C' /> </ItemGroup> <Target Name='1'> <StringTestTask Property='@(A)@(Z)'> <Output TaskParameter='Property' PropertyName='P1' /> </StringTestTask> <StringTestTask Property=""@(A,'')""> <Output TaskParameter='Property' PropertyName='P2' /> </StringTestTask> <StringTestTask Property=""@(A,'@(A)')""> <Output TaskParameter='Property' PropertyName='P3' /> </StringTestTask> <StringTestTask Property=""@(A,'$(A)')""> <Output TaskParameter='Property' PropertyName='P4' /> </StringTestTask> <StringTestTask Property=""@(A,'@(A,'')')""> <Output TaskParameter='Property' PropertyName='P5' /> </StringTestTask> <StringTestTask Property=""@(A,'$(B)')""> <Output TaskParameter='Property' PropertyName='P6' /> </StringTestTask> <StringTestTask Property=""%(A.Filename)""> <Output TaskParameter='Property' ItemName='I1' /> </StringTestTask> <StringTestTask Property=""@(A) %(Filename)""> <Output TaskParameter='Property' ItemName='I2' /> </StringTestTask> </Target> </Project> "; MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); engine.RegisterLogger (logger); proj.LoadXml (documentString); if (!proj.Build ("1")) { logger.DumpMessages (); Assert.Fail ("build failed"); } Assert.AreEqual ("A;B;C", proj.GetEvaluatedProperty ("P1"), "A1"); Assert.AreEqual ("ABC", proj.GetEvaluatedProperty ("P2"), "A2"); Assert.AreEqual ("A@(A)B@(A)C", proj.GetEvaluatedProperty ("P3"), "A3"); Assert.AreEqual ("AABAC", proj.GetEvaluatedProperty ("P4"), "A4"); Assert.AreEqual ("@(A,'ABC')", proj.GetEvaluatedProperty ("P5"), "A5"); Assert.AreEqual ("A@(A)gB@(A)gC", proj.GetEvaluatedProperty ("P6"), "A6"); CheckItems (proj, "I1", "A6", "A", "B", "C"); CheckItems (proj, "I2", "A7", "A A", "B B", "C C"); }
private MonoTests.Microsoft.Build.Tasks.TestMessageLogger ItemGroupInsideATarget() { var engine = new Engine(Consts.BinPath); var project = engine.CreateNewProject(); var projectXml = GetProjectXmlWithItemGroupInsideATarget (); project.LoadXml(projectXml); MonoTests.Microsoft.Build.Tasks.TestMessageLogger logger = new MonoTests.Microsoft.Build.Tasks.TestMessageLogger (); engine.RegisterLogger (logger); bool result = project.Build("Main"); if (!result) { logger.DumpMessages (); Assert.Fail("Build failed"); } return logger; }