Skip to content

Commit

Permalink
Revert "A better GetAllGlobs (dotnet#1871)"
Browse files Browse the repository at this point in the history
This reverts commit 1b2c9de.
  • Loading branch information
cdmihai committed Apr 5, 2017
1 parent 11119f6 commit b06a3d0
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 569 deletions.
6 changes: 2 additions & 4 deletions ref/net46/Microsoft.Build/Microsoft.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -500,12 +500,10 @@ namespace Microsoft.Build.Evaluation
{
public partial class GlobResult
{
internal GlobResult() { }
public GlobResult(Microsoft.Build.Construction.ProjectItemElement itemElement, string glob, System.Collections.Generic.IEnumerable<string> excludes) { }
public System.Collections.Generic.IEnumerable<string> Excludes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
public System.Collections.Generic.IEnumerable<string> IncludeGlobs { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
public string Glob { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
public Microsoft.Build.Construction.ProjectItemElement ItemElement { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
public Microsoft.Build.Globbing.IMSBuildGlob MsBuildGlob { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
public System.Collections.Generic.IEnumerable<string> Removes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
}
[System.FlagsAttribute]
public enum NewProjectFileOptions
Expand Down
6 changes: 2 additions & 4 deletions ref/netstandard1.3/Microsoft.Build/Microsoft.Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -488,12 +488,10 @@ namespace Microsoft.Build.Evaluation
{
public partial class GlobResult
{
internal GlobResult() { }
public GlobResult(Microsoft.Build.Construction.ProjectItemElement itemElement, string glob, System.Collections.Generic.IEnumerable<string> excludes) { }
public System.Collections.Generic.IEnumerable<string> Excludes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
public System.Collections.Generic.IEnumerable<string> IncludeGlobs { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
public string Glob { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
public Microsoft.Build.Construction.ProjectItemElement ItemElement { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
public Microsoft.Build.Globbing.IMSBuildGlob MsBuildGlob { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
public System.Collections.Generic.IEnumerable<string> Removes { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } [System.Runtime.CompilerServices.CompilerGeneratedAttribute]set { } }
}
[System.FlagsAttribute]
public enum NewProjectFileOptions
Expand Down
148 changes: 34 additions & 114 deletions src/Build.OM.UnitTests/Definition/Project_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
using Microsoft.Build.Evaluation;
using Microsoft.Build.Execution;
using Microsoft.Build.Framework;
using Microsoft.Build.Globbing;
using Microsoft.Build.Shared;

using Task = System.Threading.Tasks.Task;
// can't use an actual ProvenanceResult because it points to a ProjectItemElement which is hard to mock.
using ProvenanceResultTupleList = System.Collections.Generic.List<System.Tuple<string, Microsoft.Build.Evaluation.Operation, Microsoft.Build.Evaluation.Provenance, int>>;
using GlobResultList = System.Collections.Generic.List<System.Tuple<string, string[], System.Collections.Immutable.ImmutableHashSet<string>, System.Collections.Immutable.ImmutableHashSet<string>>>;
using GlobResultList = System.Collections.Generic.List<System.Tuple<string, string, System.Collections.Immutable.ImmutableHashSet<string>>>;
using InvalidProjectFileException = Microsoft.Build.Exceptions.InvalidProjectFileException;
using ToolLocationHelper = Microsoft.Build.Utilities.ToolLocationHelper;
using TargetDotNetFrameworkVersion = Microsoft.Build.Utilities.TargetDotNetFrameworkVersion;
Expand Down Expand Up @@ -3569,21 +3568,6 @@ public void GetItemProvenanceShouldBeSensitiveToGlobbingCone(string includeGlob,
}
}

[Fact]
public void GetAllGlobsShouldNotFindGlobsIfThereAreNoItemElements()
{
var project =
@"<Project ToolsVersion='msbuilddefaulttoolsversion' DefaultTargets='Build' xmlns='msbuildnamespace'>
<ItemGroup>
</ItemGroup>
</Project>
";

var expected = new GlobResultList();

AssertGlobResult(expected, project);
}

[Fact]
public void GetAllGlobsShouldNotFindGlobsIfThereAreNone()
{
Expand Down Expand Up @@ -3621,112 +3605,55 @@ public void GetAllGlobsShouldNotFindGlobsIfInvokedWithEmptyOrNullArguments()
}

[Fact]
public void GetAllGlobsShouldFindDirectlyReferencedGlobs()
public void GetAllGlobsResultsShouldBeInItemElementOrder()
{
var itemElements = Environment.ProcessorCount * 5;
var expected = new GlobResultList();

var project =
@"<Project ToolsVersion='msbuilddefaulttoolsversion' DefaultTargets='Build' xmlns='msbuildnamespace'>
@"<Project ToolsVersion='msbuilddefaulttoolsversion' DefaultTargets='Build' xmlns='msbuildnamespace'>
<ItemGroup>
<A Include=`*.a;1;*;2;**;?a` Exclude=`1;*;3`/>
<B Include=`a;b;c` Exclude=`**`/>
{0}
</ItemGroup>
</Project>
";
";

var expectedIncludes = new[] { "*.a", "*", "**", "?a" };
var expectedExcludes = new[] { "1", "*", "3" }.ToImmutableHashSet();
var expected = new GlobResultList
var sb = new StringBuilder();
for (int i = 0; i < itemElements; i++)
{
Tuple.Create("A", expectedIncludes, expectedExcludes, ImmutableHashSet.Create<string>())
};
sb.AppendLine($"<i_{i} Include=\"*\"/>");
expected.Add(Tuple.Create($"i_{i}", "*", ImmutableHashSet<string>.Empty));
}

project = string.Format(project, sb);

AssertGlobResult(expected, project);
}

[Fact]
public void GetAllGlobsShouldFindAllExcludesAndRemoves()
public void GetAllGlobsShouldFindDirectlyReferencedGlobs()
{
var project =
@"<Project ToolsVersion='msbuilddefaulttoolsversion' DefaultTargets='Build' xmlns='msbuildnamespace'>
<ItemGroup>
<A Include=`*` Exclude=`e*`/>
<A Remove=`a`/>
<A Remove=`b`/>
<A Include=`**` Exclude=`e**`/>
<A Remove=`c`/>
<A Include=`*.a;1;*;2;**;?a` Exclude=`1;*;3`/>
<B Include=`a;b;c` Exclude=`**`/>
</ItemGroup>
</Project>
";

var expectedExcludes = new[] { "1", "*", "3" }.ToImmutableHashSet();
var expected = new GlobResultList
{
Tuple.Create("A", new []{"**"}, new [] {"e**"}.ToImmutableHashSet(), new [] {"c"}.ToImmutableHashSet()),
Tuple.Create("A", new []{"*"}, new [] {"e*"}.ToImmutableHashSet(), new [] {"c", "b", "a"}.ToImmutableHashSet()),
Tuple.Create("A", "*.a", expectedExcludes),
Tuple.Create("A", "*", expectedExcludes),
Tuple.Create("A", "**", expectedExcludes),
Tuple.Create("A", "?a", expectedExcludes)
};

AssertGlobResult(expected, project);
}

[Theory]
// [InlineData(
// @"
//<A Include=`a;b*;c*;d*;e*;f*` Exclude=`c*;d*`/>
//<A Remove=`e*;f*`/>
//",
// new[] {"ba"},
// new[] {"a", "ca", "da", "ea", "fa"}
// )]
// [InlineData(
// @"
//<A Include=`a;b*;c*;d*;e*;f*` Exclude=`c*;d*`/>
//",
// new[] {"ba", "ea", "fa"},
// new[] {"a", "ca", "da"}
// )]
// [InlineData(
// @"
//<A Include=`a;b*;c*;d*;e*;f*`/>
//",
// new[] {"ba", "ca", "da", "ea", "fa"},
// new[] {"a"}
// )]
[InlineData(
@"
<E Include=`b`/>
<R Include=`c`/>
<A Include=`a*;b*;c*` Exclude=`@(E)`/>
<A Remove=`@(R)`/>
",
new[] {"aa", "bb", "cc"},
new[] {"b", "c"}
)]
public void GetAllGlobsShouldProduceGlobThatMatches(string itemContents, string[] stringsThatShouldMatch, string[] stringsThatShouldNotMatch)
{
var projectTemplate =
@"<Project ToolsVersion='msbuilddefaulttoolsversion' DefaultTargets='Build' xmlns='msbuildnamespace'>
<ItemGroup>
{0}
</ItemGroup>
</Project>
";

var projectContents = string.Format(projectTemplate, itemContents);

var getAllGlobsResult = ObjectModelHelpers.CreateInMemoryProject(projectContents).GetAllGlobs();

var uberGlob = new CompositeGlob(getAllGlobsResult.Select(r => r.MsBuildGlob).ToImmutableArray());

foreach (var matchingString in stringsThatShouldMatch)
{
Assert.True(uberGlob.IsMatch(matchingString));
}

foreach (var nonMatchingString in stringsThatShouldNotMatch)
{
Assert.False(uberGlob.IsMatch(nonMatchingString));
}
}

[Fact]
public void GetAllGlobsShouldFindGlobsByItemType()
{
Expand All @@ -3739,15 +3666,16 @@ public void GetAllGlobsShouldFindGlobsByItemType()
</Project>
";

var expectedIncludes = new[] { "*.a", "*", "**" };
var expectedExcludes = new[] { "1", "*", "3" }.ToImmutableHashSet();
var expected = new GlobResultList
{
Tuple.Create("A", expectedIncludes, expectedExcludes, ImmutableHashSet<string>.Empty)
Tuple.Create("A", "*.a", expectedExcludes),
Tuple.Create("A", "*", expectedExcludes),
Tuple.Create("A", "**", expectedExcludes)
};

AssertGlobResult(expected, project, "A");
AssertGlobResult(new GlobResultList(), project, "NotExistent");
AssertGlobResult(new GlobResultList(), project, "NotExistant");
}

[Fact]
Expand All @@ -3766,7 +3694,7 @@ public void GetAllGlobsShouldFindIndirectlyReferencedGlobsFromProperties()

var expected = new GlobResultList
{
Tuple.Create("A", new []{"*"}, new[] {"*"}.ToImmutableHashSet(), ImmutableHashSet<string>.Empty),
Tuple.Create("A", "*", new[] {"*"}.ToImmutableHashSet()),
};

AssertGlobResult(expected, project);
Expand All @@ -3781,24 +3709,17 @@ public void GetAllGlobsShouldNotFindIndirectlyReferencedGlobsFromItems()
<A Include=`*`/>
<B Include=`@(A)`/>
<C Include=`**` Exclude=`@(A)`/>
<C Remove=`@(A)` />
</ItemGroup>
</Project>
";

using (var testFiles = new Helpers.TestProjectWithFiles(project, new[] { "a", "b" }))
using (var projectCollection = new ProjectCollection())
var expected = new GlobResultList
{
var globResult = new Project(testFiles.ProjectFile, null, MSBuildConstants.CurrentToolsVersion, projectCollection).GetAllGlobs();

var expected = new GlobResultList
{
Tuple.Create("C", new []{"**"}, new [] {"build.proj", "a", "b"}.ToImmutableHashSet(), new [] {"build.proj", "a", "b"}.ToImmutableHashSet()),
Tuple.Create("A", new []{"*"}, ImmutableHashSet<string>.Empty, ImmutableHashSet<string>.Empty)
};
Tuple.Create("A", "*", ImmutableHashSet<string>.Empty),
Tuple.Create("C", "**", ImmutableHashSet<string>.Empty),
};

AssertGlobResultsEqual(expected, globResult);
}
AssertGlobResult(expected, project);
}

private static void AssertGlobResult(GlobResultList expected, string project)
Expand All @@ -3820,9 +3741,8 @@ private static void AssertGlobResultsEqual(GlobResultList expected, List<GlobRes
for (var i = 0; i < expected.Count; i++)
{
Assert.Equal(expected[i].Item1, globs[i].ItemElement.ItemType);
Assert.Equal(expected[i].Item2, globs[i].IncludeGlobs);
Assert.Equal(expected[i].Item2, globs[i].Glob);
Assert.Equal(expected[i].Item3, globs[i].Excludes);
Assert.Equal(expected[i].Item4, globs[i].Removes);
}
}

Expand Down
82 changes: 0 additions & 82 deletions src/Build.UnitTests/Evaluation/ItemSpec_Tests.cs

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@
<Compile Include="Evaluation\ImportFromMSBuildExtensionsPath_Tests.cs" />
<Compile Include="Evaluation\Preprocessor_Tests.cs" />
<Compile Include="Evaluation\ProjectRootElementCache_Tests.cs" />
<Compile Include="Evaluation\ItemSpec_Tests.cs" />
<Compile Include="Evaluation\ProjectStringCache_Tests.cs" />
<Compile Include="EventArgsFormatting_Tests.cs" />
<Compile Include="ExpressionTreeExpression_Tests.cs" />
Expand Down
Loading

0 comments on commit b06a3d0

Please sign in to comment.