Skip to content

Commit 3624f29

Browse files
authored
Make IsTraversal property determination case-insensitive. (#47)
`String.Contains()` is case sensitive and has no overload so switch to `String.IndexOf(String, StringComparison)` instead. Also added unit tests Fixes #46
1 parent 6d7c59e commit 3624f29

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/Traversal.UnitTests/TraversalTests.cs

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,40 @@ namespace Microsoft.Build.Traversal.UnitTests
1616
{
1717
public class TraversalTests : MSBuildSdkTestBase
1818
{
19+
[Theory]
20+
[InlineData("dirs.proj")]
21+
[InlineData("Dirs.proj")]
22+
[InlineData("Dirs.Proj")]
23+
[InlineData("DiRs.PrOj")]
24+
public void IsTraversalPropertyCaseInsensitive(string projectName)
25+
{
26+
ProjectCreator
27+
.Templates
28+
.TraversalProject(
29+
new string[0],
30+
path: GetTempFile(projectName))
31+
.Save()
32+
.TryGetPropertyValue("IsTraversal", out string isTraversal);
33+
34+
isTraversal.ShouldBe("true", StringCompareShould.IgnoreCase);
35+
}
36+
37+
[Theory]
38+
[InlineData("dirs.proj", "true")]
39+
[InlineData("asdf.proj", "")]
40+
public void IsTraversalPropertySetCorrectly(string projectName, string expectedValue)
41+
{
42+
ProjectCreator
43+
.Templates
44+
.TraversalProject(
45+
new string[0],
46+
path: GetTempFile(projectName))
47+
.Save()
48+
.TryGetPropertyValue("IsTraversal", out string isTraversal);
49+
50+
isTraversal.ShouldBe(expectedValue, StringCompareShould.IgnoreCase);
51+
}
52+
1953
[Fact]
2054
public void SkipsNonExistentTargets()
2155
{

src/Traversal/Sdk/Sdk.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<TraversalProjectNames Condition=" '$(TraversalProjectNames)' == '' ">dirs.proj</TraversalProjectNames>
2020

2121
<IsTraversal Condition=" '$(IsTraversal)' != '' ">$([System.Convert]::ToBoolean($(IsTraversal)))</IsTraversal>
22-
<IsTraversal Condition=" '$(IsTraversal)' == '' And $(TraversalProjectNames.Contains($(MSBuildProjectFile))) ">true</IsTraversal>
22+
<IsTraversal Condition=" '$(IsTraversal)' == '' And $(TraversalProjectNames.IndexOf($(MSBuildProjectFile), System.StringComparison.OrdinalIgnoreCase)) >= 0 ">true</IsTraversal>
2323
</PropertyGroup>
2424

2525
<ItemDefinitionGroup Condition=" '$(TraversalDoNotReferenceOutputAssemblies)' != 'false' ">

0 commit comments

Comments
 (0)