public void SaveCompactedWriteTlog() { Console.WriteLine("Test: SaveCompactedWriteTlog"); TaskItem fooItem = new TaskItem("foo"); ITaskItem[] sources = new TaskItem[] { new TaskItem(Path.GetFullPath("TestFiles\\one.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\two.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\three.cpp"))}; string rootMarker = FileTracker.FormatRootingMarker(sources); // Prepare files Thread.Sleep(sleepTimeMilliseconds); // need to wait since the timestamp check needs some time to register File.WriteAllLines("TestFiles\\one.tlog", new string[] { "#Command some-command", "^" + rootMarker, Path.GetFullPath("TestFiles\\oNe.obj"), "^" + fooItem.GetMetadata("Fullpath"), Path.GetFullPath("TestFiles\\foo1.bar"), Path.GetFullPath("TestFiles\\bar1.baz"), }); File.WriteAllLines("TestFiles\\two.tlog", new string[] { "#Command some-command", "^" + rootMarker, Path.GetFullPath("TestFiles\\two.obj"), Path.GetFullPath("TestFiles\\three.obj"), "^" + fooItem.GetMetadata("Fullpath"), Path.GetFullPath("TestFiles\\foo2.bar"), Path.GetFullPath("TestFiles\\bar2.baz"), }); ITaskItem[] tlogs = { new TaskItem("TestFiles\\one.tlog"), new TaskItem("TestFiles\\two.tlog") }; Thread.Sleep(sleepTimeMilliseconds); // need to wait since the timestamp check needs some time to register CanonicalTrackedOutputFiles d = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask, tlogs); ITaskItem[] outputs = d.OutputsForSource(sources); Assert.Equal(3, outputs.Length); Assert.Equal(outputs[0].ItemSpec, Path.GetFullPath("TestFiles\\oNe.obj")); Assert.Equal(outputs[1].ItemSpec, Path.GetFullPath("TestFiles\\two.obj")); Assert.Equal(outputs[2].ItemSpec, Path.GetFullPath("TestFiles\\three.obj")); outputs = d.OutputsForSource(fooItem); Assert.Equal(4, outputs.Length); Assert.Equal(outputs[0].ItemSpec, Path.GetFullPath("TestFiles\\foo1.bar")); Assert.Equal(outputs[1].ItemSpec, Path.GetFullPath("TestFiles\\bar1.baz")); Assert.Equal(outputs[2].ItemSpec, Path.GetFullPath("TestFiles\\foo2.bar")); Assert.Equal(outputs[3].ItemSpec, Path.GetFullPath("TestFiles\\bar2.baz")); // Compact the tlog removing all entries for "foo" leaving the other entries intact d.RemoveEntriesForSource(fooItem); d.SaveTlog(); // All the tlogs need to still be there even after compaction // It's OK for them to be empty, but their absence might mean a partial clean // A missing tlog would mean a clean build Assert.True(Microsoft.Build.Utilities.TrackedDependencies.ItemsExist(tlogs)); // All log information should now be in the tlog[0] ITaskItem[] tlogs2 = { tlogs[0] }; CanonicalTrackedOutputFiles d2 = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask, tlogs2); outputs = d2.OutputsForSource(fooItem); Assert.Equal(0, outputs.Length); outputs = d2.OutputsForSource(sources); Assert.Equal(3, outputs.Length); Assert.Equal(outputs[0].ItemSpec, Path.GetFullPath("TestFiles\\oNe.obj")); Assert.Equal(outputs[1].ItemSpec, Path.GetFullPath("TestFiles\\two.obj")); Assert.Equal(outputs[2].ItemSpec, Path.GetFullPath("TestFiles\\three.obj")); // There should be no difference even if we send in all the original tlogs CanonicalTrackedOutputFiles d3 = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask, tlogs); outputs = d3.OutputsForSource(fooItem); Assert.Equal(0, outputs.Length); outputs = d3.OutputsForSource(sources); Assert.Equal(3, outputs.Length); Assert.Equal(outputs[0].ItemSpec, Path.GetFullPath("TestFiles\\oNe.obj")); Assert.Equal(outputs[1].ItemSpec, Path.GetFullPath("TestFiles\\two.obj")); Assert.Equal(outputs[2].ItemSpec, Path.GetFullPath("TestFiles\\three.obj")); }
public void OutputNonExistentTlog() { Console.WriteLine("Test: NonExistentTlog"); // Just to be sure, delete the test tlog. File.Delete("TestFiles\\one.tlog"); CanonicalTrackedOutputFiles d = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask, DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.tlog"))); ITaskItem[] outputs = d.OutputsForSource(new TaskItem(Path.GetFullPath("TestFiles\\one.cpp"))); Assert.Null(outputs); }
public void OutputSingleCanonicalCLAcrossTlogs() { Console.WriteLine("Test: OutputSingleCanonicalCLAcrossTlogs"); // Prepare files Thread.Sleep(sleepTimeMilliseconds); // need to wait since the timestamp check needs some time to register File.WriteAllLines("TestFiles\\one.tlog", new string[] { "#Command some-command", "^" + Path.GetFullPath("TestFiles\\one.cpp"), Path.GetFullPath("TestFiles\\oNe.obj"), }); File.WriteAllLines("TestFiles\\two.tlog", new string[] { "#Command some-command", "^" + Path.GetFullPath("TestFiles\\one.cpp"), Path.GetFullPath("TestFiles\\one.pch"), }); ITaskItem[] tlogs = { new TaskItem("TestFiles\\one.tlog"), new TaskItem("TestFiles\\two.tlog") }; CanonicalTrackedOutputFiles d = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask, tlogs); ITaskItem[] outputs = d.OutputsForSource(new TaskItem(Path.GetFullPath("TestFiles\\one.cpp"))); Assert.Equal(2, outputs.Length); Assert.Equal(outputs[0].ItemSpec, Path.GetFullPath("TestFiles\\oNe.obj")); Assert.Equal(outputs[1].ItemSpec, Path.GetFullPath("TestFiles\\one.pch")); }
public void OutputMultipleUnrecognisedRootCanonicalCL() { Console.WriteLine("Test: OutputMultipleUnrecognisedRootCanonicalCL"); // Prepare files Thread.Sleep(sleepTimeMilliseconds); // need to wait since the timestamp check needs some time to register File.WriteAllLines("TestFiles\\one.tlog", new string[] { "#Command some-command", "^" + Path.GetFullPath("TestFiles\\one.cpp") + "|" + Path.GetFullPath("TestFiles\\two.cpp") + "|" + Path.GetFullPath("TestFiles\\three.cpp"), Path.GetFullPath("TestFiles\\oNe.obj"), Path.GetFullPath("TestFiles\\two.obj"), Path.GetFullPath("TestFiles\\three.obj"), }); CanonicalTrackedOutputFiles d = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask, DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.tlog"))); ITaskItem[] outputs = d.OutputsForSource(new TaskItem(Path.GetFullPath("TestFiles\\four.cpp"))); Assert.Equal(0, outputs.Length); }
public void OutputMultipleCanonicalCLSubrootMisMatch() { Console.WriteLine("Test: OutputMultipleCanonicalCLSubrootMisMatch"); // sources is NOT a subset of source ITaskItem[] sources = new TaskItem[] { new TaskItem(Path.GetFullPath("TestFiles\\one.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\two.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\three.cpp"))}; ITaskItem[] sources2 = new TaskItem[] { new TaskItem(Path.GetFullPath("TestFiles\\one.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\two.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\four.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\five.cpp"))}; ITaskItem[] sources2Match = new TaskItem[] { new TaskItem(Path.GetFullPath("TestFiles\\one.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\four.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\two.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\five.cpp"))}; ITaskItem[] sourcesPlusOne = new TaskItem[] { new TaskItem(Path.GetFullPath("TestFiles\\one.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\two.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\eight.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\three.cpp"))}; // Do note sources2Match and source2 is missing three.cpp. It is to test if the RootContainsAllSubRootComponents can handle the case. // Prepare files Thread.Sleep(sleepTimeMilliseconds); // need to wait since the timestamp check needs some time to register File.WriteAllLines("TestFiles\\one.tlog", new string[] { "#Command some-command", "^" + FileTracker.FormatRootingMarker(sources), Path.GetFullPath("TestFiles\\oNe.obj"), Path.GetFullPath("TestFiles\\two.obj"), Path.GetFullPath("TestFiles\\three.obj"), "^" + FileTracker.FormatRootingMarker(sources2), Path.GetFullPath("TestFiles\\fOUr.obj"), Path.GetFullPath("TestFiles\\fIve.obj"), Path.GetFullPath("TestFiles\\sIx.obj"), Path.GetFullPath("TestFiles\\sEvEn.obj"), Path.GetFullPath("TestFiles\\EIght.obj"), }); CanonicalTrackedOutputFiles d = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask, DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.tlog"))); ITaskItem[] outputs = d.OutputsForSource(sources2Match, /*searchForSubRootsInCompositeRootingMarkers*/ false); Assert.Equal(5, outputs.Length); Assert.Equal(outputs[0].ItemSpec, Path.GetFullPath("TestFiles\\fOUr.obj")); Assert.Equal(outputs[1].ItemSpec, Path.GetFullPath("TestFiles\\fIve.obj")); Assert.Equal(outputs[2].ItemSpec, Path.GetFullPath("TestFiles\\sIx.obj")); Assert.Equal(outputs[3].ItemSpec, Path.GetFullPath("TestFiles\\sEvEn.obj")); Assert.Equal(outputs[4].ItemSpec, Path.GetFullPath("TestFiles\\EIght.obj")); ITaskItem[] outputs2 = d.OutputsForSource(sources2Match, /*searchForSubRootsInCompositeRootingMarkers*/ true); Assert.Equal(5, outputs2.Length); Assert.Equal(outputs2[0].ItemSpec, Path.GetFullPath("TestFiles\\fOUr.obj")); Assert.Equal(outputs2[1].ItemSpec, Path.GetFullPath("TestFiles\\fIve.obj")); Assert.Equal(outputs2[2].ItemSpec, Path.GetFullPath("TestFiles\\sIx.obj")); Assert.Equal(outputs2[3].ItemSpec, Path.GetFullPath("TestFiles\\sEvEn.obj")); Assert.Equal(outputs2[4].ItemSpec, Path.GetFullPath("TestFiles\\EIght.obj")); ITaskItem[] outputs3 = d.OutputsForSource(sourcesPlusOne, /*searchForSubRootsInCompositeRootingMarkers*/ true); Assert.Equal(3, outputs3.Length); Assert.Equal(outputs3[0].ItemSpec, Path.GetFullPath("TestFiles\\oNe.obj")); Assert.Equal(outputs3[1].ItemSpec, Path.GetFullPath("TestFiles\\two.obj")); Assert.Equal(outputs3[2].ItemSpec, Path.GetFullPath("TestFiles\\three.obj")); ITaskItem[] outputs4 = d.OutputsForSource(sourcesPlusOne, /*searchForSubRootsInCompositeRootingMarkers*/ false); Assert.Equal(0, outputs4.Length); }
public void OutputMultipleCanonicalCLLongTempPath() { Console.WriteLine("Test: OutputMultipleCanonicalCLLongTempPath"); ITaskItem[] sources = new TaskItem[] { new TaskItem(Path.GetFullPath("TestFiles\\one.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\two.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\three.cpp"))}; string oldTempPath = Environment.GetEnvironmentVariable("TEMP"); string oldTmpPath = Environment.GetEnvironmentVariable("TMP"); string newTempPath = Path.GetFullPath("TestFiles\\ThisIsAReallyVeryLongTemporaryPlace\\ThatIsLongerThanTheSourcePaths"); Directory.CreateDirectory(newTempPath); Environment.SetEnvironmentVariable("TEMP", newTempPath); Environment.SetEnvironmentVariable("TMP", newTempPath); Console.WriteLine("Test: OutputMultipleCanonicalCL"); // Prepare files Thread.Sleep(sleepTimeMilliseconds); // need to wait since the timestamp check needs some time to register File.WriteAllLines("TestFiles\\one.tlog", new string[] { "#Command some-command", "^" + FileTracker.FormatRootingMarker(sources), Path.GetFullPath("TestFiles\\oNe.obj"), Path.GetFullPath("TestFiles\\two.obj"), Path.GetFullPath("TestFiles\\three.obj"), }); CanonicalTrackedOutputFiles d = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask, DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.tlog"))); ITaskItem[] outputs = d.OutputsForSource(sources); Environment.SetEnvironmentVariable("TEMP", oldTempPath); Environment.SetEnvironmentVariable("TMP", oldTmpPath); Assert.Equal(3, outputs.Length); Assert.Equal(outputs[0].ItemSpec, Path.GetFullPath("TestFiles\\oNe.obj")); Assert.Equal(outputs[1].ItemSpec, Path.GetFullPath("TestFiles\\two.obj")); Assert.Equal(outputs[2].ItemSpec, Path.GetFullPath("TestFiles\\three.obj")); }
public void OutputMultipleSingleSubRootCanonicalCL() { Console.WriteLine("Test: OutputMultipleSingleSubRootCanonicalCL"); ITaskItem[] sources = new TaskItem[] { new TaskItem(Path.GetFullPath("TestFiles\\one.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\two.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\three.cpp"))}; // Prepare files Thread.Sleep(sleepTimeMilliseconds); // need to wait since the timestamp check needs some time to register File.WriteAllLines("TestFiles\\one.tlog", new string[] { "#Command some-command", "^" + FileTracker.FormatRootingMarker(sources), Path.GetFullPath("TestFiles\\oNe.obj"), Path.GetFullPath("TestFiles\\two.obj"), Path.GetFullPath("TestFiles\\three.obj"), }); CanonicalTrackedOutputFiles d = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask, DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.tlog"))); ITaskItem[] outputs = d.OutputsForSource(new TaskItem(Path.GetFullPath("TestFiles\\two.cpp"))); Assert.IsTrue(outputs.Length == 3); Assert.IsTrue(outputs[0].ItemSpec == Path.GetFullPath("TestFiles\\oNe.obj")); Assert.IsTrue(outputs[1].ItemSpec == Path.GetFullPath("TestFiles\\two.obj")); Assert.IsTrue(outputs[2].ItemSpec == Path.GetFullPath("TestFiles\\three.obj")); }
public void OutputMultipleCanonicalCLSubrootMatch() { Console.WriteLine("Test: OutputMultipleCanonicalCLSubrootMatch"); // sources is a subset of source2 ITaskItem[] sources = new TaskItem[] { new TaskItem(Path.GetFullPath("TestFiles\\one.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\two.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\three.cpp"))}; ITaskItem[] sources2 = new TaskItem[] { new TaskItem(Path.GetFullPath("TestFiles\\one.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\two.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\three.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\four.cpp")), new TaskItem(Path.GetFullPath("TestFiles\\five.cpp"))}; // Prepare files Thread.Sleep(sleepTimeMilliseconds); // need to wait since the timestamp check needs some time to register File.WriteAllLines("TestFiles\\one.tlog", new string[] { "#Command some-command", "^" + FileTracker.FormatRootingMarker(sources), Path.GetFullPath("TestFiles\\oNe.obj"), Path.GetFullPath("TestFiles\\two.obj"), Path.GetFullPath("TestFiles\\three.obj"), "^" + FileTracker.FormatRootingMarker(sources2), Path.GetFullPath("TestFiles\\fOUr.obj"), Path.GetFullPath("TestFiles\\fIve.obj"), Path.GetFullPath("TestFiles\\sIx.obj"), Path.GetFullPath("TestFiles\\sEvEn.obj"), Path.GetFullPath("TestFiles\\EIght.obj"), }); CanonicalTrackedOutputFiles d = new CanonicalTrackedOutputFiles(DependencyTestHelper.MockTask, DependencyTestHelper.ItemArray(new TaskItem("TestFiles\\one.tlog"))); ITaskItem[] outputs = d.OutputsForSource(sources2, /*searchForSubRootsInCompositeRootingMarkers*/ false); Assert.IsTrue(outputs.Length == 5); Assert.IsTrue(outputs[0].ItemSpec == Path.GetFullPath("TestFiles\\fOUr.obj")); Assert.IsTrue(outputs[1].ItemSpec == Path.GetFullPath("TestFiles\\fIve.obj")); Assert.IsTrue(outputs[2].ItemSpec == Path.GetFullPath("TestFiles\\sIx.obj")); Assert.IsTrue(outputs[3].ItemSpec == Path.GetFullPath("TestFiles\\sEvEn.obj")); Assert.IsTrue(outputs[4].ItemSpec == Path.GetFullPath("TestFiles\\EIght.obj")); ITaskItem[] outputs2 = d.OutputsForSource(sources2, /*searchForSubRootsInCompositeRootingMarkers*/ true); Assert.IsTrue(outputs2.Length == 8); Assert.IsTrue(outputs2[0].ItemSpec == Path.GetFullPath("TestFiles\\oNe.obj")); Assert.IsTrue(outputs2[1].ItemSpec == Path.GetFullPath("TestFiles\\two.obj")); Assert.IsTrue(outputs2[2].ItemSpec == Path.GetFullPath("TestFiles\\three.obj")); Assert.IsTrue(outputs2[3].ItemSpec == Path.GetFullPath("TestFiles\\fOUr.obj")); Assert.IsTrue(outputs2[4].ItemSpec == Path.GetFullPath("TestFiles\\fIve.obj")); Assert.IsTrue(outputs2[5].ItemSpec == Path.GetFullPath("TestFiles\\sIx.obj")); Assert.IsTrue(outputs2[6].ItemSpec == Path.GetFullPath("TestFiles\\sEvEn.obj")); Assert.IsTrue(outputs2[7].ItemSpec == Path.GetFullPath("TestFiles\\EIght.obj")); // Test if sources can find the superset. ITaskItem[] outputs3 = d.OutputsForSource(sources, /*searchForSubRootsInCompositeRootingMarkers*/ true); Assert.IsTrue(outputs3.Length == 8); Assert.IsTrue(outputs3[0].ItemSpec == Path.GetFullPath("TestFiles\\oNe.obj")); Assert.IsTrue(outputs3[1].ItemSpec == Path.GetFullPath("TestFiles\\two.obj")); Assert.IsTrue(outputs3[2].ItemSpec == Path.GetFullPath("TestFiles\\three.obj")); Assert.IsTrue(outputs3[3].ItemSpec == Path.GetFullPath("TestFiles\\fOUr.obj")); Assert.IsTrue(outputs3[4].ItemSpec == Path.GetFullPath("TestFiles\\fIve.obj")); Assert.IsTrue(outputs3[5].ItemSpec == Path.GetFullPath("TestFiles\\sIx.obj")); Assert.IsTrue(outputs3[6].ItemSpec == Path.GetFullPath("TestFiles\\sEvEn.obj")); Assert.IsTrue(outputs3[7].ItemSpec == Path.GetFullPath("TestFiles\\EIght.obj")); ITaskItem[] outputs4 = d.OutputsForSource(sources, /*searchForSubRootsInCompositeRootingMarkers*/ false); Assert.IsTrue(outputs4.Length == 3); Assert.IsTrue(outputs4[0].ItemSpec == Path.GetFullPath("TestFiles\\oNe.obj")); Assert.IsTrue(outputs4[1].ItemSpec == Path.GetFullPath("TestFiles\\two.obj")); Assert.IsTrue(outputs4[2].ItemSpec == Path.GetFullPath("TestFiles\\three.obj")); }