Skip to content

Convert xUnit1004 analyzer to IOperation API - #224

Merged
bradwilson merged 2 commits into
xunit:mainfrom
meziantou:feature/testmethod-ioperation-conversion-8a20fc
Sep 19, 2026
Merged

bradwilson merged 2 commits into
xunit:mainfrom
meziantou:feature/testmethod-ioperation-conversion-8a20fc

Conversation

@meziantou

Copy link
Copy Markdown
Contributor

Converts TestMethodShouldNotBeSkipped (xUnit1004) from a syntax node action to the IOperation API, following the same approach as #222.

What changed

  • Registers an OperationKind.Attribute action instead of a SyntaxKind.Attribute action; the Microsoft.CodeAnalysis.CSharp / .Syntax usings are gone.
  • Named arguments are read from the object initializer's ISimpleAssignmentOperations, matching on the target property name instead of the NameEquals text.
  • The attribute type comes from the IObjectCreationOperation wrapped by IAttributeOperation, rather than a SemanticModel.GetTypeInfo call. The IsAssignableFrom check is kept, so attributes derived from FactAttribute / TheoryAttribute are still covered.
  • Added Constants.AttributeProperties.Skip alongside the existing SkipUnless / SkipWhen constants.

Notes for reviewers

  • Behavior is unchanged: the diagnostic is suppressed when SkipUnless or SkipWhen is set, and is reported on the Skip = ... argument. Each assignment's syntax is the AttributeArgumentSyntax, so diagnostic locations are unchanged and the fixer (which looks for AttributeArgumentSyntax) needs no update.
  • The existing V2_and_V3 test is extended with an attribute derived from FactAttribute (with and without Skip) and a Skip value coming from a const.

Replace the attribute syntax node action with an OperationKind.Attribute
operation action. Named arguments are read from the attribute's object
initializer property assignments instead of the NameEquals text, and the
attribute type comes from the object creation operation rather than a
SemanticModel lookup. Add a derived-attribute and const Skip value
scenario to the existing test.
@meziantou
meziantou marked this pull request as ready for review September 13, 2026 22:14
@bradwilson

Copy link
Copy Markdown
Member

Looks like the tests failed because of the addition of the test cases deriving from FactAttribute, which is not legal in Native AOT.

FactAttribute is sealed in xUnit.net v3 Native AOT, so the derived
attribute scenario failed to compile in the AOT test context. Move it to a
V2_and_V3_NonAot test and keep the const Skip value scenario on Fact.
@meziantou

Copy link
Copy Markdown
Contributor Author

The CI should be green now

@bradwilson
bradwilson merged commit 3c85338 into xunit:main Sep 19, 2026
4 checks passed
@bradwilson

Copy link
Copy Markdown
Member

Thanks!

@bradwilson

Copy link
Copy Markdown
Member

Available in 2.2.0-pre.20 https://xunit.net/docs/using-ci-builds

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants