Add xUnit1070/xUnit1071: cultured tests cannot have null or duplicate cultures - #236
Merged
bradwilson merged 3 commits intoSep 19, 2026
Merged
Conversation
…ures Cultured tests with a null culture fail at runtime, and duplicate cultures run the same test twice. The checks live in the same analyzer as xUnit1060, which is renamed to CulturedTestCultureValidation since it now covers three rules.
[CulturedFact(null)] fails at runtime with the same 'did not provide any cultures' error as an empty array.
meziantou
marked this pull request as ready for review
September 19, 2026 01:36
Member
|
Thanks! |
Member
|
Available in |
bradwilson
added a commit
to xunit/xunit.integration
that referenced
this pull request
Sep 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes xunit/xunit#3632.
Adds two rules for
[CulturedFact]and[CulturedTheory]:null,default,default(string), or a nullconst stringCulture '{0}' is duplicated.)A null culture breaks the test at runtime. A duplicate only runs the same test twice, so it's a warning.
What changed
CulturedTestMustHaveAtLeastOneCulturetoCulturedTestCultureValidationbecause it now covers three rules. This followsConditionalSkipPropertyValidation(xUnit1054/1055).new[] { ... }) and collection expressions ([...]). Each bad element is reported at its own location. For duplicates, the second and later occurrences are reported.Notes for reviewers
"en-US"and"en-us"are the same culture).""(invariant culture) is allowed."xx-BOGUS". Whether a name is valid depends on the OS culture data (ICU), so the analyzer can't check it reliably.[CulturedFact(null)],default,(string[])null) is now reported as xUnit1060. At runtime it fails with the same "did not provide any cultures" error as an empty array.V3_onlytest. Because the analyzer now reports more than one ID, the X1060 test markup names its ID ({|xUnit1060:...|}).