public void InvalidUnqualifiedMetadataReference() { Assert.Throws <InvalidProjectFileException>(() => { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); List <string> parameters = new List <string>(); parameters.Add("@(File)"); parameters.Add("%(Culture)"); ItemDictionary <ProjectItemInstance> itemsByType = new ItemDictionary <ProjectItemInstance>(); List <ProjectItemInstance> items = new List <ProjectItemInstance>(); ProjectItemInstance a = new ProjectItemInstance(project, "File", "a.foo", project.FullPath); items.Add(a); ProjectItemInstance b = new ProjectItemInstance(project, "File", "b.foo", project.FullPath); items.Add(b); a.SetMetadata("Culture", "fr-fr"); itemsByType.ImportItems(items); PropertyDictionary <ProjectPropertyInstance> properties = new PropertyDictionary <ProjectPropertyInstance>(); // This is expected to throw because not all items contain a value for metadata "Culture". // Only a.foo has a Culture metadata. b.foo does not. BatchingEngine.PrepareBatchingBuckets(parameters, CreateLookup(itemsByType, properties), MockElementLocation.Instance); } ); }
public void ValidUnqualifiedMetadataReference() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); List <string> parameters = new List <string>(); parameters.Add("@(File)"); parameters.Add("%(Culture)"); ItemDictionary <ProjectItemInstance> itemsByType = new ItemDictionary <ProjectItemInstance>(); List <ProjectItemInstance> items = new List <ProjectItemInstance>(); ProjectItemInstance a = new ProjectItemInstance(project, "File", "a.foo", project.FullPath); ProjectItemInstance b = new ProjectItemInstance(project, "File", "b.foo", project.FullPath); a.SetMetadata("Culture", "fr-fr"); b.SetMetadata("Culture", "en-en"); items.Add(a); items.Add(b); itemsByType.ImportItems(items); PropertyDictionary <ProjectPropertyInstance> properties = new PropertyDictionary <ProjectPropertyInstance>(); List <ItemBucket> buckets = BatchingEngine.PrepareBatchingBuckets(parameters, CreateLookup(itemsByType, properties), null); Assert.Equal(2, buckets.Count); }
public void InputItemThatCorrelatesWithMultipleTransformOutputItems() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); string inputs = "@(Items)"; string outputs = "@(Items->'%(Filename).dll');@(Items->'%(Filename).xml')"; FileWriteInfo[] filesToAnalyze = new FileWriteInfo[] { new FileWriteInfo("a.cs", _yesterday), new FileWriteInfo("a.dll", _today), new FileWriteInfo("a.xml", _today), new FileWriteInfo("b.cs", _yesterday), new FileWriteInfo("b.dll", _twoDaysAgo), new FileWriteInfo("b.xml", _today), new FileWriteInfo("c.cs", _yesterday), new FileWriteInfo("c.dll", _today), new FileWriteInfo("c.xml", _today) }; List <ProjectItemInstance> items = new List <ProjectItemInstance>(); items.Add(new ProjectItemInstance(project, "Items", "a.cs", project.FullPath)); items.Add(new ProjectItemInstance(project, "Items", "b.cs", project.FullPath)); items.Add(new ProjectItemInstance(project, "Items", "c.cs", project.FullPath)); ItemDictionary <ProjectItemInstance> itemsByName = new ItemDictionary <ProjectItemInstance>(); itemsByName.ImportItems(items); DependencyAnalysisResult result = PerformDependencyAnalysisTestHelper(filesToAnalyze, itemsByName, inputs, outputs); Assert.Equal(DependencyAnalysisResult.IncrementalBuild, result); // "Should only build partially." }
public void MultiInputItemsThatCorrelatesWithMultipleTransformOutputItems() { Console.WriteLine("MultiInputItemsThatCorrelatesWithMultipleTransformOutputItems"); ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); string inputs = "@(Items);@(MoreItems)"; string outputs = "@(Items->'%(Filename).dll');@(MoreItems->'%(Filename).xml')"; FileWriteInfo[] filesToAnalyze = new FileWriteInfo[] { new FileWriteInfo("a.cs", _yesterday), new FileWriteInfo("a.txt", _yesterday), new FileWriteInfo("a.dll", _today), new FileWriteInfo("a.xml", _today), new FileWriteInfo("b.cs", _yesterday), new FileWriteInfo("b.txt", _yesterday), new FileWriteInfo("b.dll", _twoDaysAgo), new FileWriteInfo("b.xml", _today), new FileWriteInfo("c.cs", _yesterday), new FileWriteInfo("c.txt", _yesterday), new FileWriteInfo("c.dll", _today), new FileWriteInfo("c.xml", _today) }; List <ProjectItemInstance> items = new List <ProjectItemInstance>(); items.Add(new ProjectItemInstance(project, "Items", "a.cs", project.FullPath)); items.Add(new ProjectItemInstance(project, "Items", "b.cs", project.FullPath)); items.Add(new ProjectItemInstance(project, "Items", "c.cs", project.FullPath)); items.Add(new ProjectItemInstance(project, "MoreItems", "a.txt", project.FullPath)); items.Add(new ProjectItemInstance(project, "MoreItems", "b.txt", project.FullPath)); items.Add(new ProjectItemInstance(project, "MoreItems", "c.txt", project.FullPath)); ItemDictionary <ProjectItemInstance> itemsByName = new ItemDictionary <ProjectItemInstance>(); itemsByName.ImportItems(items); ItemDictionary <ProjectItemInstance> changedTargetInputs = new ItemDictionary <ProjectItemInstance>(); ItemDictionary <ProjectItemInstance> upToDateTargetInputs = new ItemDictionary <ProjectItemInstance>(); DependencyAnalysisResult result = PerformDependencyAnalysisTestHelper(filesToAnalyze, itemsByName, inputs, outputs, out changedTargetInputs, out upToDateTargetInputs); foreach (ProjectItemInstance itemInstance in changedTargetInputs) { Console.WriteLine("Changed: {0}:{1}", itemInstance.ItemType, itemInstance.EvaluatedInclude); } Assert.Equal(DependencyAnalysisResult.IncrementalBuild, result); // "Should only build partially." // Even though they were all up to date, we still expect to see an empty marker // so that lookups can correctly *not* find items of that type Assert.True(changedTargetInputs.HasEmptyMarker("MoreItems")); }
public void Regress_Mutation_DuplicateBatchingBucketsAreFoldedTogether() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); List <string> parameters = new List <string>(); parameters.Add("%(File.Culture)"); ItemDictionary <ProjectItemInstance> itemsByType = new ItemDictionary <ProjectItemInstance>(); List <ProjectItemInstance> items = new List <ProjectItemInstance>(); items.Add(new ProjectItemInstance(project, "File", "a.foo", project.FullPath)); items.Add(new ProjectItemInstance(project, "File", "b.foo", project.FullPath)); // Need at least two items for this test case to ensure multiple buckets might be possible itemsByType.ImportItems(items); PropertyDictionary <ProjectPropertyInstance> properties = new PropertyDictionary <ProjectPropertyInstance>(); List <ItemBucket> buckets = BatchingEngine.PrepareBatchingBuckets(parameters, CreateLookup(itemsByType, properties), null); // If duplicate buckets have been folded correctly, then there will be exactly one bucket here // containing both a.foo and b.foo. Assert.Single(buckets); }
public void GetBuckets() { ProjectInstance project = ProjectHelpers.CreateEmptyProjectInstance(); List <string> parameters = new List <string>(); parameters.Add("@(File);$(unittests)"); parameters.Add("$(obj)\\%(Filename).ext"); parameters.Add("@(File->'%(extension)')"); // attributes in transforms don't affect batching ItemDictionary <ProjectItemInstance> itemsByType = new ItemDictionary <ProjectItemInstance>(); IList <ProjectItemInstance> items = new List <ProjectItemInstance>(); items.Add(new ProjectItemInstance(project, "File", "a.foo", project.FullPath)); items.Add(new ProjectItemInstance(project, "File", "b.foo", project.FullPath)); items.Add(new ProjectItemInstance(project, "File", "c.foo", project.FullPath)); items.Add(new ProjectItemInstance(project, "File", "d.foo", project.FullPath)); items.Add(new ProjectItemInstance(project, "File", "e.foo", project.FullPath)); itemsByType.ImportItems(items); items = new List <ProjectItemInstance>(); items.Add(new ProjectItemInstance(project, "Doc", "a.doc", project.FullPath)); items.Add(new ProjectItemInstance(project, "Doc", "b.doc", project.FullPath)); items.Add(new ProjectItemInstance(project, "Doc", "c.doc", project.FullPath)); items.Add(new ProjectItemInstance(project, "Doc", "d.doc", project.FullPath)); items.Add(new ProjectItemInstance(project, "Doc", "e.doc", project.FullPath)); itemsByType.ImportItems(items); PropertyDictionary <ProjectPropertyInstance> properties = new PropertyDictionary <ProjectPropertyInstance>(); properties.Set(ProjectPropertyInstance.Create("UnitTests", "unittests.foo")); properties.Set(ProjectPropertyInstance.Create("OBJ", "obj")); List <ItemBucket> buckets = BatchingEngine.PrepareBatchingBuckets(parameters, CreateLookup(itemsByType, properties), MockElementLocation.Instance); Assert.Equal(5, buckets.Count); foreach (ItemBucket bucket in buckets) { // non-batching data -- same for all buckets XmlAttribute tempXmlAttribute = (new XmlDocument()).CreateAttribute("attrib"); tempXmlAttribute.Value = "'$(Obj)'=='obj'"; Assert.True(ConditionEvaluator.EvaluateCondition(tempXmlAttribute.Value, ParserOptions.AllowAll, bucket.Expander, ExpanderOptions.ExpandAll, Directory.GetCurrentDirectory(), MockElementLocation.Instance, null, new BuildEventContext(1, 2, 3, 4), FileSystems.Default)); Assert.Equal("a.doc;b.doc;c.doc;d.doc;e.doc", bucket.Expander.ExpandIntoStringAndUnescape("@(doc)", ExpanderOptions.ExpandItems, MockElementLocation.Instance)); Assert.Equal("unittests.foo", bucket.Expander.ExpandIntoStringAndUnescape("$(bogus)$(UNITTESTS)", ExpanderOptions.ExpandPropertiesAndMetadata, MockElementLocation.Instance)); } Assert.Equal("a.foo", buckets[0].Expander.ExpandIntoStringAndUnescape("@(File)", ExpanderOptions.ExpandItems, MockElementLocation.Instance)); Assert.Equal(".foo", buckets[0].Expander.ExpandIntoStringAndUnescape("@(File->'%(Extension)')", ExpanderOptions.ExpandItems, MockElementLocation.Instance)); Assert.Equal("obj\\a.ext", buckets[0].Expander.ExpandIntoStringAndUnescape("$(obj)\\%(Filename).ext", ExpanderOptions.ExpandPropertiesAndMetadata, MockElementLocation.Instance)); // we weren't batching on this attribute, so it has no value Assert.Equal(String.Empty, buckets[0].Expander.ExpandIntoStringAndUnescape("%(Extension)", ExpanderOptions.ExpandAll, MockElementLocation.Instance)); ProjectItemInstanceFactory factory = new ProjectItemInstanceFactory(project, "i"); items = buckets[0].Expander.ExpandIntoItemsLeaveEscaped("@(file)", factory, ExpanderOptions.ExpandItems, MockElementLocation.Instance); Assert.NotNull(items); Assert.Single(items); int invalidProjectFileExceptions = 0; try { // This should throw because we don't allow item lists to be concatenated // with other strings. bool throwAway; items = buckets[0].Expander.ExpandSingleItemVectorExpressionIntoItems("@(file)$(unitests)", factory, ExpanderOptions.ExpandItems, false /* no nulls */, out throwAway, MockElementLocation.Instance); } catch (InvalidProjectFileException ex) { // check we don't lose error codes from IPFE's during build Assert.Equal("MSB4012", ex.ErrorCode); invalidProjectFileExceptions++; } // We do allow separators in item vectors, this results in an item group with a single flattened item items = buckets[0].Expander.ExpandIntoItemsLeaveEscaped("@(file, ',')", factory, ExpanderOptions.ExpandItems, MockElementLocation.Instance); Assert.NotNull(items); Assert.Single(items); Assert.Equal("a.foo", items[0].EvaluatedInclude); Assert.Equal(1, invalidProjectFileExceptions); }