Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion eng/CodeAnalysis.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
<Rule Id="CA2231" Action="None" /> <!-- Overload operator equals on overriding value type Equals -->
<Rule Id="CA2234" Action="None" /> <!-- Pass system uri objects instead of strings -->
<Rule Id="CA2235" Action="None" /> <!-- Mark all non-serializable fields -->
<Rule Id="CA2241" Action="Info" /> <!-- Provide correct arguments to formatting methods -->
<Rule Id="CA2241" Action="Warning" /> <!-- Provide correct arguments to formatting methods -->
<Rule Id="CA2242" Action="Warning" /> <!-- Test for NaN correctly -->
<Rule Id="CA2243" Action="None" /> <!-- Attribute string literals should parse correctly -->
<Rule Id="CA2244" Action="None" /> <!-- Do not duplicate indexed element initializations -->
Expand Down
42 changes: 12 additions & 30 deletions src/Build.UnitTests/FileUtilitiesRegex_Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -525,64 +525,46 @@ public void MatchLengthStartWithUncPatternNoShare()
[Fact]
public void UncPatternEmptyString_LegacyRegex()
{
string winDirectory = string.Format("", _directoryStart);
string unixDirectory = string.Format("", _altDirectoryStart);

UncPattern.IsMatch(winDirectory).ShouldBe(false);
UncPattern.IsMatch(unixDirectory).ShouldBe(false);
UncPattern.IsMatch(string.Empty).ShouldBe(false);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at all these tests, they don't really feel substantively different from each other, and many check the same thing twice. Maybe condense into one test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How are those changes?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Forgind I disagree pretty strongly with this recommendation, because it violates the test principle that a test should fail for only one reason. Here the new test could fail if one of the implementations fails but it wouldn't be super clear from the failure which one.

@elachlan don't bother reverting though; this isn't a huge deal and you already did the unification.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fair. I was borderline on suggesting just removing the legacy tests entirely—they test Regex, which isn't even in MSBuild. FileUtilitiesRegex.IsUncPattern and FileUtilitiesRegex.StartsWithUncPattern both just call FileUtilitiesRegex.StartsWithUncPatternMatchLength, so it all felt like one test to me. It's possible that won't be true in the future, though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Up to the team, I don't mind either way. Just let me know what you want me to do. If there isn't any changes then is this okay to merge?

UncPattern.IsMatch(string.Empty).ShouldBe(false);
}

[Fact]
public void UncPatternEmptyString()
{
string winDirectory = string.Format("", _directoryStart);
string unixDirectory = string.Format("", _altDirectoryStart);

FileUtilitiesRegex.IsUncPattern(winDirectory).ShouldBe(false);
FileUtilitiesRegex.IsUncPattern(unixDirectory).ShouldBe(false);
FileUtilitiesRegex.IsUncPattern(string.Empty).ShouldBe(false);
FileUtilitiesRegex.IsUncPattern(string.Empty).ShouldBe(false);
}

[Fact]
public void StartWithUncPatternEmptyString_LegacyRegex()
{
string winDirectory = string.Format("", _directoryStart);
string unixDirectory = string.Format("", _altDirectoryStart);

StartsWithUncPattern.IsMatch(winDirectory).ShouldBe(false);
StartsWithUncPattern.IsMatch(unixDirectory).ShouldBe(false);
StartsWithUncPattern.IsMatch(string.Empty).ShouldBe(false);
StartsWithUncPattern.IsMatch(string.Empty).ShouldBe(false);
}

[Fact]
public void StartsWithUncPatternEmptyString()
{
string winDirectory = string.Format("", _directoryStart);
string unixDirectory = string.Format("", _altDirectoryStart);

FileUtilitiesRegex.StartsWithUncPattern(winDirectory).ShouldBe(false);
FileUtilitiesRegex.StartsWithUncPattern(unixDirectory).ShouldBe(false);
FileUtilitiesRegex.StartsWithUncPattern(string.Empty).ShouldBe(false);
FileUtilitiesRegex.StartsWithUncPattern(string.Empty).ShouldBe(false);
}

[Fact]
public void MatchLengthStartWithUncPatternEmptyString_LegacyRegex()
{
string winDirectory = string.Format("", _directoryStart);
string unixDirectory = string.Format("", _altDirectoryStart);

var match = StartsWithUncPattern.Match(winDirectory);
var match = StartsWithUncPattern.Match(string.Empty);
match.Success.ShouldBeFalse();

match = StartsWithUncPattern.Match(unixDirectory);
match = StartsWithUncPattern.Match(string.Empty);
match.Success.ShouldBeFalse();
}

[Fact]
public void MatchLengthStartWithUncPatternEmptyString()
{
string winDirectory = string.Format("", _directoryStart);
string unixDirectory = string.Format("", _altDirectoryStart);

FileUtilitiesRegex.StartsWithUncPatternMatchLength(winDirectory).ShouldBe(-1);
FileUtilitiesRegex.StartsWithUncPatternMatchLength(unixDirectory).ShouldBe(-1);
FileUtilitiesRegex.StartsWithUncPatternMatchLength(string.Empty).ShouldBe(-1);
FileUtilitiesRegex.StartsWithUncPatternMatchLength(string.Empty).ShouldBe(-1);
}
}
}