Skip to content

Commit 90aa1d4

Browse files
committed
Fix xunit analyzers to run on library test projects
We don't want most analyzers running over our test code currently (some rules could be enabled with varying degrees of effort), but we do want the xunit analyzers running, and they haven't been. Fix that by creating a new ruleset specific to library tests, and switching over to use it when building library test projects.
1 parent 8c48ae8 commit 90aa1d4

File tree

7 files changed

+1045
-473
lines changed

7 files changed

+1045
-473
lines changed

eng/CodeAnalysis.ruleset

Lines changed: 489 additions & 469 deletions
Large diffs are not rendered by default.

eng/CodeAnalysis.test.ruleset

Lines changed: 546 additions & 0 deletions
Large diffs are not rendered by default.

src/libraries/Directory.Build.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,8 @@
225225
<CheckForOverflowUnderflow>false</CheckForOverflowUnderflow>
226226
<GenFacadesIgnoreBuildAndRevisionMismatch>true</GenFacadesIgnoreBuildAndRevisionMismatch>
227227
<!-- Disable analyzers for tests and unsupported projects -->
228-
<RunAnalyzers Condition="'$(IsSourceProject)' != 'true' or '$(MSBuildProjectExtension)' == '.ilproj'">false</RunAnalyzers>
228+
<RunAnalyzers Condition="'$(IsTestProject)' != 'true' and '$(IsSourceProject)' != 'true'">false</RunAnalyzers>
229+
<CodeAnalysisRuleset Condition="'$(IsTestProject)' == 'true'">$(RepositoryEngineeringDir)CodeAnalysis.test.ruleset</CodeAnalysisRuleset>
229230
</PropertyGroup>
230231

231232
<!-- Set up common paths -->

src/libraries/Microsoft.Extensions.Configuration.Binder/tests/ConfigurationBinderTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ public void CanBindByteArrayWhenValueIsNull()
845845
var config = configurationBuilder.Build();
846846

847847
var options = config.Get<ByteArrayOptions>();
848-
Assert.Equal(null, options.MyByteArray);
848+
Assert.Null(options.MyByteArray);
849849
}
850850

851851
[Fact]

src/libraries/Microsoft.Extensions.DependencyInjection/tests/DI.Tests/ServiceProviderContainerTests.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,8 @@ public void ScopeDispose_PreventsServiceResolution()
265265
Assert.NotNull(provider.CreateScope());
266266
}
267267

268-
[Theory(Skip = "https://github.com/dotnet/runtime/issues/42160 - We don't support value task services currently")]
268+
[ActiveIssue("https://github.com/dotnet/runtime/issues/42160")] // We don't support value task services currently
269+
[Theory]
269270
[InlineData(ServiceLifetime.Transient)]
270271
[InlineData(ServiceLifetime.Scoped)]
271272
[InlineData(ServiceLifetime.Singleton)]

src/libraries/System.Security.Cryptography.Csp/tests/CspParametersTests.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ namespace System.Security.Cryptography.Csp.Tests
77
{
88
public static class CspParametersTests
99
{
10+
public static bool ManualTestsEnabled => !string.IsNullOrEmpty(Environment.GetEnvironmentVariable("MANUAL_TESTS"));
11+
1012
const int PROV_RSA_FULL = 1;
1113
const int PROV_RSA_AES = 24;
1214

@@ -45,7 +47,7 @@ public static void KeyPassword_SetGet()
4547
}
4648
}
4749

48-
[Theory(Skip = "Manual test - requires Smart Card - read instructions")]
50+
[ConditionalTheory(nameof(ManualTestsEnabled))] // requires Smart Card - read instructions
4951
[InlineData(true)]
5052
[InlineData(false)]
5153
public static void KeyPassword_SmartCard_Manual_Test(bool correctPassword)

src/libraries/System.Text.Json/tests/Serialization/NumberHandlingTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,9 +817,11 @@ static void PerformFloatingPointSerialization(string testString)
817817
[InlineData("NaNa")]
818818
[InlineData("Infinitya")]
819819
[InlineData("-Infinitya")]
820+
#pragma warning disable xUnit1025 // Theory method 'FloatingPointConstants_Fail' on test class 'NumberHandlingTests' has InlineData duplicate(s)
820821
[InlineData("\u006EaN")] // "naN"
821822
[InlineData("\u0020Inf\u0069ni\u0074y")] // " Infinity"
822823
[InlineData("\u002BInf\u0069nity")] // "+Infinity"
824+
#pragma warning restore xUnit1025
823825
public static void FloatingPointConstants_Fail(string testString)
824826
{
825827
string testStringAsJson = $@"""{testString}""";

0 commit comments

Comments
 (0)