public void TestBatchingWithUnqualifiedMetadataReference() { string projectString = projectHeader + @" <ItemGroup> <Item1 Include=""One""><Md>1</Md></Item1> <Item1 Include=""Two""><Md>2</Md></Item1> <Item1Ref Include=""@(Item1)"" /> <Item2 Include=""Three""><Md>3</Md></Item2> <Item2 Include=""Four""><Md>4</Md></Item2> <Item2Ref Include=""@(Item2)"" /> </ItemGroup> <PropertyGroup> <Prop1>@(Item1)</Prop1> <Prop1Ref>@(Item1Ref)</Prop1Ref> <Prop2>@(Item2)</Prop2> <Prop2Ref>@(Item2Ref)</Prop2Ref> </PropertyGroup> <Target Name='1'> <Message Text=""For md: %(Md) Item1: @(Item1) Item1Ref: @(Item1Ref) Item2: @(Item2) Item2Ref: @(Item2Ref) " + @" Prop1: $(Prop1) Prop1Ref: $(Prop1Ref) Prop2: $(Prop2) Prop2Ref: $(Prop2Ref)""/> </Target> </Project>"; Engine engine = new Engine(Consts.BinPath); Project project = engine.CreateNewProject(); TestMessageLogger testLogger = new TestMessageLogger(); engine.RegisterLogger(testLogger); project.LoadXml(projectString); if (!project.Build("1")) { testLogger.DumpMessages(); Assert.Fail("Build failed"); } try { testLogger.CheckLoggedAny("For md: 3 Item1: Item1Ref: Item2: Three Item2Ref: Three Prop1: Prop1Ref: Prop2: Three Prop2Ref: Three", MessageImportance.Normal, "A1"); testLogger.CheckLoggedAny("For md: 4 Item1: Item1Ref: Item2: Four Item2Ref: Four Prop1: Prop1Ref: Prop2: Four Prop2Ref: Four", MessageImportance.Normal, "A2"); testLogger.CheckLoggedAny("For md: 1 Item1: One Item1Ref: One Item2: Item2Ref: Prop1: One Prop1Ref: One Prop2: Prop2Ref: ", MessageImportance.Normal, "A3"); testLogger.CheckLoggedAny("For md: 2 Item1: Two Item1Ref: Two Item2: Item2Ref: Prop1: Two Prop1Ref: Two Prop2: Prop2Ref: ", MessageImportance.Normal, "A4"); Assert.AreEqual(0, testLogger.NormalMessageCount, "Unexpected extra messages found"); } catch (AssertionException) { testLogger.DumpMessages(); throw; } }
public void TestCopy_Retries() { Engine engine; Project project; string file_path = Path.Combine(source_path, "copyretries.txt"); string target_file = Path.Combine(target_path, "copyretries.txt"); using (File.CreateText(file_path)) { } using (File.CreateText(target_file)) { } File.SetAttributes(target_file, FileAttributes.ReadOnly); Assert.AreEqual(FileAttributes.ReadOnly, File.GetAttributes(target_file), "A1"); string documentString = @" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <PropertyGroup><DestFile>" + target_file + @"</DestFile></PropertyGroup> <ItemGroup> <SFiles Include='" + file_path + @"'><Md>1</Md></SFiles> <DFiles Include='$(DestFile)'><Mde>2</Mde></DFiles> </ItemGroup> <Target Name='1'> <Copy SourceFiles='@(SFiles)' DestinationFiles='@(DFiles)' Retries='3' RetryDelayMilliseconds='2000'> <Output TaskParameter='CopiedFiles' ItemName='I0'/> <Output TaskParameter='DestinationFiles' ItemName='I1'/> </Copy> <Message Text=""I0 : @(I0), I1: @(I1)""/> </Target> </Project> " ; engine = new Engine(Consts.BinPath); project = engine.CreateNewProject(); TestMessageLogger testLogger = new TestMessageLogger(); engine.RegisterLogger(testLogger); project.LoadXml(documentString); // remove the read-only flag from the file after a few secs, // so copying works after retries new Thread(() => { Thread.Sleep(3000); File.SetAttributes(target_file, FileAttributes.Normal); }).Start(); if (!project.Build("1")) { var sb = new StringBuilder(); testLogger.DumpMessages(sb); Assert.Fail("Build failed " + sb.ToString()); } testLogger.CheckLoggedAny("Copying failed. Retries left: 3.", MessageImportance.Normal, "A2"); }
public void TestItemsWithWildcards() { Engine engine = new Engine(Consts.BinPath); Project proj = engine.CreateNewProject(); TestMessageLogger logger = new TestMessageLogger(); engine.RegisterLogger(logger); // Setup string projectdir = Path.Combine("Test", "resources"); string basedir = "dir"; string aaa = PathCombine(basedir, "a", "aa", "aaa"); string bb = PathCombine(basedir, "b", "bb"); string c = PathCombine(basedir, "c"); string[] dirs = { aaa, bb, c }; string[] files = { PathCombine(aaa, "foo.dll"), PathCombine(bb, "bar.dll"), PathCombine(bb, "sample.txt"), Path.Combine(basedir, "xyz.dll") }; string documentString = @" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" " + Consts.ToolsVersionString + @"> <Target Name='Main'> <CreateItem Include='dir\**'> <Output TaskParameter='Include' ItemName='CI1' /> </CreateItem> <Message Text=""CI1: @(CI1)""/> </Target> </Project>" ; try { CreateDirectoriesAndFiles(projectdir, dirs, files); File.WriteAllText(Path.Combine(projectdir, "wild1.proj"), documentString); proj.Load(Path.Combine(projectdir, "wild1.proj")); if (!proj.Build("Main")) { Assert.Fail("Build failed"); } string full_base_dir = Path.GetFullPath(basedir); logger.CheckLoggedAny("CI1: " + String.Join(";", files), MessageImportance.Normal, "A1"); } catch (AssertionException) { logger.DumpMessages(); throw; } finally { Directory.Delete(Path.Combine(projectdir, basedir), true); } }
public void TestItemsWithWildcards2() { Engine engine = new Engine(Consts.BinPath); Project proj = engine.CreateNewProject(); TestMessageLogger logger = new 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(aaa, "foo.dll"), PathCombine(bb, "bar.dll"), PathCombine(bb, "sample.txt"), PathCombine("xyz.dll") }; string documentString = @" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" " + Consts.ToolsVersionString + @"> <PropertyGroup> <WC>dir\**\*.dll</WC> <ExWC>*\x*.dll</ExWC> </PropertyGroup> <Target Name='Main'> <Copy SourceFiles='dir\xyz.dll' DestinationFiles='dir\abc.dll'/> <CreateItem Include='dir\**\*.dll' Exclude='*\x*.dll'> <Output TaskParameter='Include' ItemName='CI1' /> </CreateItem> <Message Text=""CI1: %(CI1.FullPath)""/> <CreateItem Include='$(WC)' Exclude='$(ExWC)'> <Output TaskParameter='Include' ItemName='CI2' /> </CreateItem> <Message Text=""CI2: %(CI2.FullPath)""/> </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")) { Assert.Fail("Build failed"); } string full_base_dir = Path.GetFullPath(basedir); foreach (string prefix in new string[] { "CI1: ", "CI2: " }) { logger.CheckLoggedAny(prefix + PathCombine(full_base_dir, aaa, "foo.dll"), MessageImportance.Normal, "A1"); logger.CheckLoggedAny(prefix + PathCombine(full_base_dir, bb, "bar.dll"), MessageImportance.Normal, "A2"); logger.CheckLoggedAny(prefix + PathCombine(full_base_dir, "abc.dll"), MessageImportance.Normal, "A3"); } } catch (AssertionException) { logger.DumpMessages(); throw; } finally { Directory.Delete(basedir, true); } }
public void TestCopy_Retries () { Engine engine; Project project; string file_path = Path.Combine (source_path, "copyretries.txt"); string target_file = Path.Combine (target_path, "copyretries.txt"); using (File.CreateText (file_path)) { } using (File.CreateText (target_file)) { } File.SetAttributes (target_file, FileAttributes.ReadOnly); Assert.AreEqual (FileAttributes.ReadOnly, File.GetAttributes (target_file), "A1"); string documentString = @" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003""> <PropertyGroup><DestFile>" + target_file + @"</DestFile></PropertyGroup> <ItemGroup> <SFiles Include='" + file_path + @"'><Md>1</Md></SFiles> <DFiles Include='$(DestFile)'><Mde>2</Mde></DFiles> </ItemGroup> <Target Name='1'> <Copy SourceFiles='@(SFiles)' DestinationFiles='@(DFiles)' Retries='3' RetryDelayMilliseconds='2000'> <Output TaskParameter='CopiedFiles' ItemName='I0'/> <Output TaskParameter='DestinationFiles' ItemName='I1'/> </Copy> <Message Text=""I0 : @(I0), I1: @(I1)""/> </Target> </Project> "; engine = new Engine (Consts.BinPath); project = engine.CreateNewProject (); TestMessageLogger testLogger = new TestMessageLogger (); engine.RegisterLogger (testLogger); project.LoadXml (documentString); // remove the read-only flag from the file after a few secs, // so copying works after retries new Thread ( () => { Thread.Sleep (3000); File.SetAttributes (target_file, FileAttributes.Normal); }).Start (); if (!project.Build ("1")) { var sb = new StringBuilder (); testLogger.DumpMessages (sb); Assert.Fail ("Build failed " + sb.ToString ()); } testLogger.CheckLoggedAny ("Copying failed. Retries left: 3.", MessageImportance.Normal, "A2"); }
public void TestBatchingWithUnqualifiedMetadataReference () { string projectString = projectHeader + @" <ItemGroup> <Item1 Include=""One""><Md>1</Md></Item1> <Item1 Include=""Two""><Md>2</Md></Item1> <Item1Ref Include=""@(Item1)"" /> <Item2 Include=""Three""><Md>3</Md></Item2> <Item2 Include=""Four""><Md>4</Md></Item2> <Item2Ref Include=""@(Item2)"" /> </ItemGroup> <PropertyGroup> <Prop1>@(Item1)</Prop1> <Prop1Ref>@(Item1Ref)</Prop1Ref> <Prop2>@(Item2)</Prop2> <Prop2Ref>@(Item2Ref)</Prop2Ref> </PropertyGroup> <Target Name='1'> <Message Text=""For md: %(Md) Item1: @(Item1) Item1Ref: @(Item1Ref) Item2: @(Item2) Item2Ref: @(Item2Ref) " + @" Prop1: $(Prop1) Prop1Ref: $(Prop1Ref) Prop2: $(Prop2) Prop2Ref: $(Prop2Ref)""/> </Target> </Project>"; Engine engine = new Engine (Consts.BinPath); Project project = engine.CreateNewProject (); TestMessageLogger testLogger = new TestMessageLogger (); engine.RegisterLogger (testLogger); project.LoadXml (projectString); if (!project.Build ("1")) { testLogger.DumpMessages (); Assert.Fail ("Build failed"); } try { testLogger.CheckLoggedAny ("For md: 3 Item1: Item1Ref: Item2: Three Item2Ref: Three Prop1: Prop1Ref: Prop2: Three Prop2Ref: Three", MessageImportance.Normal, "A1"); testLogger.CheckLoggedAny ("For md: 4 Item1: Item1Ref: Item2: Four Item2Ref: Four Prop1: Prop1Ref: Prop2: Four Prop2Ref: Four", MessageImportance.Normal, "A2"); testLogger.CheckLoggedAny ("For md: 1 Item1: One Item1Ref: One Item2: Item2Ref: Prop1: One Prop1Ref: One Prop2: Prop2Ref: ", MessageImportance.Normal, "A3"); testLogger.CheckLoggedAny ("For md: 2 Item1: Two Item1Ref: Two Item2: Item2Ref: Prop1: Two Prop1Ref: Two Prop2: Prop2Ref: ", MessageImportance.Normal, "A4"); Assert.AreEqual (0, testLogger.NormalMessageCount, "Unexpected extra messages found"); } catch (AssertionException) { testLogger.DumpMessages (); throw; } }
public void TestItemsWithWildcards () { Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); TestMessageLogger logger = new 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"" ToolsVersion=""3.5""> <PropertyGroup> <WC>dir\**\*.dll</WC> <ExWC>*\x*.dll</ExWC> </PropertyGroup> <Target Name='Main'> <Copy SourceFiles='dir\xyz.dll' DestinationFiles='dir\abc.dll'/> <CreateItem Include='dir\**\*.dll' Exclude='*\x*.dll'> <Output TaskParameter='Include' ItemName='CI1' /> </CreateItem> <Message Text=""CI1: %(CI1.FullPath)""/> <CreateItem Include='$(WC)' Exclude='$(ExWC)'> <Output TaskParameter='Include' ItemName='CI2' /> </CreateItem> <Message Text=""CI2: %(CI2.FullPath)""/> </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")) Assert.Fail ("Build failed"); string full_base_dir = Path.GetFullPath (basedir); foreach (string prefix in new string[] { "CI1: ", "CI2: " }) { logger.CheckLoggedAny (prefix + PathCombine (full_base_dir, aaa, "foo.dll"), MessageImportance.Normal, "A1"); logger.CheckLoggedAny (prefix + PathCombine (full_base_dir, bb, "bar.dll"), MessageImportance.Normal, "A2"); logger.CheckLoggedAny (prefix + PathCombine (full_base_dir, "abc.dll"), MessageImportance.Normal, "A3"); } } catch (AssertionException) { logger.DumpMessages (); throw; } finally { Directory.Delete (basedir, true); } }
public void TestItemsWithWildcards () { Engine engine = new Engine (Consts.BinPath); Project proj = engine.CreateNewProject (); TestMessageLogger logger = new TestMessageLogger (); engine.RegisterLogger (logger); // Setup string projectdir = Path.Combine ("Test", "resources"); string basedir = "dir"; string aaa = PathCombine (basedir, "a", "aa", "aaa"); string bb = Path.Combine (basedir, "b", "bb"); string c = Path.Combine (basedir, "c"); string[] dirs = { aaa, bb, c }; string[] files = { PathCombine (aaa, "foo.dll"), PathCombine (bb, "bar.dll"), PathCombine (bb, "sample.txt"), Path.Combine (basedir, "xyz.dll") }; string documentString = @" <Project xmlns=""http://schemas.microsoft.com/developer/msbuild/2003"" " + Consts.ToolsVersionString + @"> <Target Name='Main'> <CreateItem Include='dir\**'> <Output TaskParameter='Include' ItemName='CI1' /> </CreateItem> <Message Text=""CI1: @(CI1)""/> </Target> </Project>"; try { CreateDirectoriesAndFiles (projectdir, dirs, files); File.WriteAllText (Path.Combine (projectdir, "wild1.proj"), documentString); proj.Load (Path.Combine (projectdir, "wild1.proj")); if (!proj.Build ("Main")) Assert.Fail ("Build failed"); string full_base_dir = Path.GetFullPath (basedir); logger.CheckLoggedAny ("CI1: " + String.Join (";", files), MessageImportance.Normal, "A1"); } catch (AssertionException) { logger.DumpMessages (); throw; } finally { Directory.Delete (Path.Combine (projectdir, basedir), true); } }