Repository navigation
fix(sourcegen): pair each GenerateGenericTest type only with its typed ClassDataSource<T> - #7188
Conversation
…d ClassDataSource<T> AreSameAttribute compared attribute classes by name, so ClassDataSource<A> and ClassDataSource<B> (same name, no constructor arguments) matched each other and every instantiation ran every typed data source. Compare the constructed attribute class instead. Fixes #7158
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 34 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
[Medium impact] This PR appears safe to merge. Summary
Reviews (1) · Last reviewed commit: "fix(sourcegen): pair each GenerateGeneri..." · Reviewed by Greptile |
Review: PR 7188 (typed ClassDataSource scoping)Verdict: looks good. I found no blocking issues.
Reflection mode is untouched and was already correct, so both modes now agree. Approving. |
Summary
A generic test method with several
[GenerateGenericTest]types and one typedClassDataSource<T>per type now produces the same tests in both modes.Run<GenA>with aGenB, andRun<GenB>with aGenA) failed withInvalidCastException. Reflection mode built 2 passing tests.Run<GenA>runs onlyClassDataSource<GenA>, andRun<GenB>runs onlyClassDataSource<GenB>.Cause
Both modes already scope a typed data source to the instantiation it infers.
CollectConcreteInstantiationscreates theGenAandGenBinstantiations from the two typed sources, and each stores its source asSpecificArgumentsAttribute. The[GenerateGenericTest]types are duplicates and are dropped.The emitted data sources are then filtered with
IsSpecificMethodDataSource, which callsAreSameAttribute. That method compared onlyAttributeClass.Nameand the constructor arguments.ClassDataSource<GenA>andClassDataSource<GenB>have the same name and no constructor arguments, so each instantiation's filter accepted both sources.Fix
AreSameAttributenow compares the constructed attribute class withSymbolEqualityComparer.Defaultinstead of comparing names. This is a single change inTestMetadataGenerator.cs. Reflection mode was already correct and is unchanged. No other generator snapshot changed.Tests
tests/TUnit.TestProject/Bugs/_7158/GenerateGenericTestTypedClassDataSourceTests.cs(the issue's repro).Tests7158: each entry'stestDataSourcesholds only its own type's source. Before the fix both entries held both sources.Issue7158Testsengine test (reflection, plus AOT/source-gen in CI): 2 total, 2 passed.TUnit.Core.SourceGenerator.Testson net10.0: 193 passed, 1 skipped, no snapshot changes.Tests7158also passes on net472._7158filter: source-gen 2/2 passed,--reflection2/2 passed.Fixes #7158