Skip to content

Commit

Permalink
Marking xUnit3002 as Hidden because there are strange false positives…
Browse files Browse the repository at this point in the history
… I can't track down
  • Loading branch information
bradwilson committed Jul 22, 2024
1 parent c1c69d6 commit ed09407
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ public async Task AcceptanceTest()
{
var code = /* lang=c#-test */ """
using Xunit;
using Xunit.Sdk;
using System.Collections.Generic;
using System.Linq;

[JsonTypeID("MyMessage")]
public class MyMessage { };
public static class MessageFactory {
public static MyMessage Create(int propertyValue = 42) =>
new() {
PropertyValue = propertyValue,
};
}

public class TheClass {
public void TheMethod() {
Expand All @@ -38,6 +41,10 @@ public void TheMethod() {
Assert.IsNotAssignableFrom(typeof(string), message);
Assert.IsNotAssignableFrom<string>(message);

// Construction should not be prohibited
_ = new MyMessage { PropertyValue = 2112 };
_ = MessageFactory.Create(2600);

// Testing against a serializable type
Assert.True([|message is MyMessage|]);
Assert.True([|message is not MyMessage|]);
Expand All @@ -55,7 +62,18 @@ public void TheMethod() {
}
}
""";
var messagePartial1 = /* lang=c#-test */ """
using Xunit.Sdk;

[JsonTypeID("MyMessage")]
sealed partial class MyMessage { }
""";
var messagePartial2 = /* lang=c#-test */ """
public partial class MyMessage {
public int PropertyValue { get; set; }
};
""";

await Verify.VerifyAnalyzerV3(LanguageVersion.CSharp9, code);
await Verify.VerifyAnalyzerV3(LanguageVersion.CSharp9, [messagePartial1, messagePartial2, code]);
}
}
2 changes: 1 addition & 1 deletion src/xunit.analyzers/Utility/Descriptors.xUnit3xxx.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static partial class Descriptors
"xUnit3002",
"Classes which are JSON serializable should not be tested for their concrete type",
Extensibility,
Warning,
Hidden,
"Class {0} is JSON serializable and should not be tested for its concrete type. Test for its primary interface instead."
);

Expand Down

0 comments on commit ed09407

Please sign in to comment.