Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable xunit1024 #34512

Merged
merged 68 commits into from
Apr 8, 2020
Merged

Enable xunit1024 #34512

merged 68 commits into from
Apr 8, 2020

Conversation

alexvy86
Copy link
Contributor

@alexvy86 alexvy86 commented Apr 3, 2020

There's a couple of recurring patterns in this PR:

  • A simple rename of a test method (e.g. add a suffix; If there are conventions around that that I'm not aware of, I'm happy to adjust the renames).
  • Replace a Fact that does nothing but call a helper method with different parameter values, with a Theory that uses InlineData (or just "inline" the redundant method, if there was only one call).
  • Replace a helper method with the same name as a Fact/Theory method, with a local function.

I'll make particular notes about changes that do not fall in one of the above patterns, or other comments, for easier review:

  • src/libraries/System.Text.Json/tests/Serialization/Value.ReadTests.GenericCollections.cs
    • Removed ReadKeyValuePairOfKeyValuePair Fact since the Theory right after it already covers that case. The code is identical, and the inline data for the Theory already includes the value that the Fact used.
  • src/libraries/System.Private.Xml/tests/XmlSerialize/XmlSerializerTests.RuntimeOnly.cs
    • Xml_GuidAsRoot_Helper and Xml_ListGenericRoot_Helper were just renames, but I noticed that they don't use their only parameter so maybe there's a problem there. To be handled in a separate issue if they actually are.
  • src/libraries/System.Diagnostics.StackTrace/tests/StackTraceTests.cs
    • Ctor_ThrownException_GetFramesReturnsExpected might be redundant? Depending on the default value that fNeedFileInfo gets when instantiating a StackTrace, but I couldn't easily find where to check that.

Will fix #34503

alexvy86 added 3 commits April 3, 2020 12:39
The very next method is a Theory with inline data that tests this
exact scenario.
@dnfclas
Copy link

dnfclas commented Apr 3, 2020

CLA assistant check
All CLA requirements met.

@danmoseley
Copy link
Member

Looks like there are some more instances to fix, in different configurations.

@stephentoub
Copy link
Member

This is only fixing occurrences in System.Text.Json. Presumably there are others in many other test projects? Or is Json really the only one?

@alexvy86
Copy link
Contributor Author

alexvy86 commented Apr 3, 2020

Looks like there are some more instances to fix, in different configurations.

Right, I've only looked at netcoreapp, I'll address net472 hopefully during the weekend.

This is only fixing occurrences in System.Text.Json. Presumably there are others in many other test projects? Or is Json really the only one?

I was expecting to find more, and my intention with the PR was to fix them all... but I just rebuilt all of the libraries subcategory after fixing System.Text.Json and it apparently succeeded, so maybe there was much less work to do than I thought.

@alexvy86
Copy link
Contributor Author

alexvy86 commented Apr 3, 2020

but I just rebuilt all of the libraries subcategory after fixing System.Text.Json and it apparently succeeded, so maybe there was much less work to do than I thought.

Nvm, I built the libraries themselves, not their test projects, which are the ones with issues; now I'm seeing more errors. So yeah, I'll keep working on the rest of the test projects.

@@ -662,7 +662,7 @@ public static IEnumerable<object[]> RoundtripCompressDecompressOuterData
}

[Fact]
public async Task CompressDecompress_RoundTrip()
public async Task CompressDecompress_RoundTrip_BaseTests()
Copy link
Member

Choose a reason for hiding this comment

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

I'd prefer to see this test's name left as-is, and the method it delegates to instead be renamed to something like CompressDecompress_RoundTrip_OuterLoop. Same goes for the other similar cases here. My reason is "BaseTests" doesn't really speak to what the test is doing, plus this is the test that runs 99% of the time, and the one it delegates to is relegated to only running when we run "OuterLoop".

@@ -1666,7 +1666,7 @@ public static void MakeSureNoSequenceEqualChecksGoOutOfRange_Char()
[InlineData("Hello", "llo" + SoftHyphen, StringComparison.OrdinalIgnoreCase, false)]
[InlineData("", "", StringComparison.OrdinalIgnoreCase, true)]
[InlineData("", "a", StringComparison.OrdinalIgnoreCase, false)]
public static void EndsWith(string s, string value, StringComparison comparisonType, bool expected)
public static void EndsWith_ExplicitComparisonType(string s, string value, StringComparison comparisonType, bool expected)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public static void EndsWith_ExplicitComparisonType(string s, string value, StringComparison comparisonType, bool expected)
public static void EndsWith_StringComparison(string s, string value, StringComparison comparisonType, bool expected)

@@ -4639,7 +4639,7 @@ public void Replace_EmptyOldValue_ThrowsArgumentException()
[InlineData("Hello", SoftHyphen + "Hel", StringComparison.OrdinalIgnoreCase, false)]
[InlineData("", "", StringComparison.OrdinalIgnoreCase, true)]
[InlineData("", "hello", StringComparison.OrdinalIgnoreCase, false)]
public static void StartsWith(string s, string value, StringComparison comparisonType, bool expected)
public static void StartsWith_WithExplicitComparisonType(string s, string value, StringComparison comparisonType, bool expected)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public static void StartsWith_WithExplicitComparisonType(string s, string value, StringComparison comparisonType, bool expected)
public static void StartsWith_StringComparison(string s, string value, StringComparison comparisonType, bool expected)

@@ -5222,7 +5222,7 @@ public static void LengthMismatchToLower()
}

[Fact]
public static void ToLower()
public static void ToLower_2()
Copy link
Member

Choose a reason for hiding this comment

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

What is the other ToLower test this is conflicting with? "ToLower_2" isn't descriptive about what makes this test different from a presumed "ToLower_1", so we should either pick descriptive names or combine the tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's this one, using strings + Span instead of char[] + Span throughout. How about naming them ToLower_String and ToLower_CharArray?

Copy link
Member

Choose a reason for hiding this comment

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

How about naming them ToLower_String and ToLower_CharArray?

Sounds fine. Thanks.

@@ -5434,7 +5434,7 @@ public static void LengthMismatchToUpper()
}

[Fact]
public static void ToUpper()
public static void ToUpper_2()
Copy link
Member

Choose a reason for hiding this comment

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

Ditto

@@ -838,7 +838,7 @@ public static IEnumerable<object[]> EnumeratorTraversalNullData()

[Theory]
[MemberData(nameof(EqualsData))]
public void Equals(ImmutableArray<int> first, ImmutableArray<int> second, bool expected)
public void EqualsBaseTest(ImmutableArray<int> first, ImmutableArray<int> second, bool expected)
Copy link
Member

Choose a reason for hiding this comment

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

Elsewhere you used EqualsTest. Why EqualsBaseTest here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought it had been because of some class that inherited from this and had its own EqualsTest, but apparently it's not the case here, I'll simplify to EqualsTest.

@@ -107,6 +107,7 @@ public void Ctor_LargeSkipFramesFNeedFileInfo_GetFramesReturnsEmpty(bool fNeedFi
[Fact]
public void Ctor_ThrownException_GetFramesReturnsExpected()
{
// TODO: is this test redundant? See Ctor_ThrownException_GetFramesReturnsExpected_2 below
Copy link
Member

Choose a reason for hiding this comment

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

It's not redundant, it's testing a different StackTrace constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point, I'll remove the comment

@@ -124,7 +125,7 @@ public void Ctor_EmptyException_GetFramesReturnsEmpty()
[Theory]
[InlineData(true)]
[InlineData(false)]
public void Ctor_ThrownException_GetFramesReturnsExpected(bool fNeedFileInfo)
public void Ctor_ThrownException_GetFramesReturnsExpected_2(bool fNeedFileInfo)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public void Ctor_ThrownException_GetFramesReturnsExpected_2(bool fNeedFileInfo)
public void Ctor_Bool_ThrownException_GetFramesReturnsExpected(bool fNeedFileInfo)

@@ -279,7 +279,7 @@ public static IEnumerable<object[]> MemberData_FileStreamAsyncWriting()
}

[Fact]
public Task ManyConcurrentWriteAsyncs()
public Task ManyConcurrentWriteAsyncs_BaseTest()
Copy link
Member

Choose a reason for hiding this comment

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

Same feedback as in a previous similar case... let's leave this one as ManyConcurrentWriteAsyncs, and change the one below to ManyConcurrentWriteAsyncs_OuterLoop.

@@ -59,7 +59,7 @@ public static IEnumerable<object[]> TestData()

[Theory]
[MemberData(nameof(TestData))]
public void Any(IEnumerable<int> source, bool expected)
public void AnyTest(IEnumerable<int> source, bool expected)
Copy link
Member

Choose a reason for hiding this comment

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

This should stay Any, and the test below should be changed to be Any_Predicate, or something like that.

@@ -200,7 +200,7 @@ public static void Contains(string s, char value, bool expected)
[InlineData("Hello", 'e', StringComparison.OrdinalIgnoreCase, true)]
[InlineData("Hello", 'E', StringComparison.OrdinalIgnoreCase, true)]
[InlineData("", 'H', StringComparison.OrdinalIgnoreCase, false)]
public static void Contains(string s, char value, StringComparison comparisionType, bool expected)
public static void Contains_Char_ExplicitComparisonType(string s, char value, StringComparison comparisionType, bool expected)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public static void Contains_Char_ExplicitComparisonType(string s, char value, StringComparison comparisionType, bool expected)
public static void Contains_Char_StringComparison(string s, char value, StringComparison comparisionType, bool expected)

@@ -272,7 +272,7 @@ public static void Contains(string s, char value, StringComparison comparisionTy
[InlineData("Hello", "", StringComparison.OrdinalIgnoreCase, true)]
[InlineData("Hello", "ell" + SoftHyphen, StringComparison.OrdinalIgnoreCase, false)]
[InlineData("Hello", "Ell" + SoftHyphen, StringComparison.OrdinalIgnoreCase, false)]
public static void Contains(string s, string value, StringComparison comparisonType, bool expected)
public static void Contains_String_ExplicitComparisonType(string s, string value, StringComparison comparisonType, bool expected)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
public static void Contains_String_ExplicitComparisonType(string s, string value, StringComparison comparisonType, bool expected)
public static void Contains_String_StringComparison(string s, string value, StringComparison comparisonType, bool expected)

@@ -19,38 +19,38 @@ public class RijndaelTests
[Fact]
public static void VerifyDefaults()
{
static void verifyDefaults(Rijndael alg)
Copy link
Member

Choose a reason for hiding this comment

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

In situations like this, where the test method differs from the local function by the casing of a single letter, it'd be really easy to accidentally get a stack overflow or an infinite loop by calling the wrong thing. Could you rename such local functions to something a little more different?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I actually started using test for the local function at some point, I missed updating some of the ones I did earlier.

@@ -1413,9 +1413,12 @@ static void CheckErratum(SignedXml signed, KeyedHashAlgorithm hmac, string messa
}
}

private void HmacMustBeMultipleOfEightBits(int bits)
[Fact(Skip = "https://github.com/dotnet/runtime/issues/20429")]
Copy link
Member

Choose a reason for hiding this comment

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

Nit: as long as you're changing this, can you make it instead be:

[ActiveIssue("https://github.com/dotnet/runtime/issues/20429")]
[Fact]

?

@@ -997,16 +997,6 @@ public static void ReadKeyValuePairOfList()
Assert.Equal(3, input.Value[2]);
}

[Fact]
public static void ReadKeyValuePairOfKeyValuePair()
Copy link
Member

Choose a reason for hiding this comment

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

Was this a dup? Wondering why it's being deleted.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, see the first bullet point of the second set in the description, there's a Theory testing the exact same thing, and the data that this method uses is already part of the InlineData of the Theory.

Copy link
Member

@stephentoub stephentoub left a comment

Choose a reason for hiding this comment

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

Thanks for cleaning all this up!

@alexvy86
Copy link
Contributor Author

alexvy86 commented Apr 8, 2020

The check failures don't seem related to the changes, right? Is it possible to retrigger only the failed builds?

@stephentoub
Copy link
Member

Thanks!

@stephentoub stephentoub merged commit 61733e2 into dotnet:master Apr 8, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 9, 2020
@alexvy86 alexvy86 deleted the enable-xunit1024 branch April 20, 2024 23:22
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Enable xUnit1024 analyzer rule
6 participants