Repository navigation
fix(generic): infer method type arguments from [Arguments<T>] rows in both modes - #7343
Conversation
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Source-generated row inference src/TUnit.Core.SourceGenerator/Extensions/TypedDataSourceInference.cs, src/TUnit.Core.SourceGenerator/Generators/TestMetadataGenerator.cs |
Source generation infers method type arguments from typed row shapes and method parameters. Matching handles tuples, scalar rows, nested generic types, optional parameters, and row wrappers. Typed array rows are excluded from non-generic argument-array detection. |
Reflection inference and row collection src/TUnit.Engine/Discovery/ReflectionTestDataCollector.cs |
Reflection discovery infers method type arguments from typed rows and method parameters. Compatible typed argument rows join existing instantiations without duplicates, in declaration order. |
Typed-row regression coverage tests/TUnit.TestProject/Bugs/_7214/TypedArgumentsRowOnGenericMethodTests.cs, tests/TUnit.Engine.Tests/Issue7214Tests.cs |
Tests cover mixed typed and untyped rows, generic classes, row and parameter shapes, and differences between reflection and source-generated modes. |
Estimated code review effort: 4 (Complex) | ~45 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related issues
- thomhurst/TUnit#7372: The issue concerns source-generated invocation of a typed
TestDataRow<Tuple<int>[]>after generic inference, which continues the typed-row behavior changed here.
Possibly related PRs
- thomhurst/TUnit#7322: It changes generated type information for nullable generic parameters, which overlaps with this PR’s nullable-parameter inference cases.
- thomhurst/TUnit#7341: It changes runtime tuple-row binding rules, which overlap with this PR’s tuple inference and parameter-shape cases.
Suggested reviewers: kenny-ish
Merge Risk: 
Minimal · up to e0738
-
No actionable merge-blocking risk remains from the reviewed changes.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Linked Issues check
-
Explanation
Directly linked issue
#7214requires source-generated mode to run a typed[Arguments<T>]row on a generic test method when the row infers the same method type arguments as another row. Reflection mode already does this. The whole-PR changes keep that behavior:TypedDataSourceInference.InferMethodTypeArgumentsFromRowTypeinfers method type arguments from typed rows, andTestMetadataGeneratorroutes typed-row bases to it. The_7214regression corpus andIssue7214Tests.cscover the#7214shape in both modes. The incremental change since the previous reviewed head (327d20b) moves theITuplerow check into a helper,IsITuple, inReflectionTestDataCollector.cs. OnNETtargets the helper performs the sameITuple.IsAssignableFromcheck as before. On non-NETtargets it matches the type by full name, becauseITupleis not referenced there. This does not change matching onNETtargets, so the earlier conclusion still holds.
Full details: Out of Scope Changes check
-
Explanation
The incremental change only refactors the
ITuplecheck inReflectionTestDataCollector.csinto theIsITuplehelper with anetstandard2.0-compatible fallback. This supports the typed-row inference that#7214requires, so it stays in scope. The whole-PR changes remain limited to typed-row inference in the generator, analyzer, and reflection collector, plus the_7214regression tests andIssue7214Tests.cs. No unrelated feature or behavior change is evident in the reviewed diffs. Repository inspection did not cover the full source tree beyond these diffs, so this verdict rests on the reviewed diff and the prior review.
-
Full details: Docstring Coverage
-
Explanation
Docstring coverage is 54.55% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 33 functions across 5 files.
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
-
Finishing Touches
-
Generate docstrings
-
- Commit to this branch
- Create a new PR
Generate unit tests (beta)
-
- Commit to this branch
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
A rabbit checks each typed row,
Tuples hop where parameters go.
Generic types settle in place,
Rows join their matching case.
The tests run through the burrow tonight.
All values land just right.
|
@codex review |
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. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 1e103c12bb
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
ReviewReviewed the diff. I didn't build it or run the tests myself. The fix is small and targeted.
Minor, non-blocking suggestions:
Overall the change looks correct and well tested. |
[Medium impact] The changes appear safe to merge; no new actionable issue was found. SummaryThe PR lets typed argument rows infer generic method types in source-generated and reflection modes.
Reviews (17) · Last reviewed commit: "fix(engine): leave ITuple rows to runtim..." · Reviewed by Greptile |
1e103c1 to
8de7688
Compare
Review: PR 7343The fix is sound and focused. Points to consider (non-blocking):
Overall this looks good to merge, and the |
Review of #7343I read the source diff. I did not build the PR or run its tests. The change is well scoped and handles the case in #7214. The generator and analyzer share Suggestions (non-blocking):
No blocking issues found. Looks good to merge once CI is green. |
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
|
@codex review |
Review of #7343 (typed
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 53f95fe233
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
@codex review |
Review of #7343Overall this is a solid, well-tested fix. It closes the gap where I didn't run the tests. I read the diff only. Observations (non-blocking)
No blocking issues found. Good work. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: dd8e774346
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
…types (#7214) A typed row binds to the data parameters, so its declared type is matched against them instead of being taken whole as the type argument. [Arguments<int[]>] on Run<T>(IEnumerable<T>) no longer adds a Run<int[]> instantiation that cannot take the row. Same rules in the generator, analyzer TUnit0001 and reflection mode.
…eters (#7214) A scalar [Arguments<T>] row binds to the first data parameter when the rest are optional, a tuple row may omit trailing optional parameters, and a T? parameter takes a row of its underlying type. Applied in both the generator and reflection mode.
…typed-row inference (#7214) A typed source of TestDataRow<T> rows inferred Run<TestDataRow<T>> in both modes, but the row is unwrapped before invocation, so the T value could not bind. Both modes now match the row's T. Reflection counted an omitted C# 13 params collection as required, so a scalar typed row was rejected there while the generator (Roslyn IsParams) accepted it.
dd8e774 to
0c47039
Compare
Review of #7343 (typed
|
Summary
On a generic test method, a typed
[Arguments<T>]row was not used to infer type arguments in source-generated mode. Neither the[Arguments]row inference (HasArgumentsArrayis false forArguments<T>) nor the typed-source inference (it recognised onlyDataSourceGeneratorAttribute/AsyncDataSourceGeneratorAttributebases, andArgumentsAttribute<T>derives fromTypedDataSourceAttribute<T>) handled it. On currentmainthe row was reported as "Could not infer the type arguments" (since #7163); earlier it was silently dropped. Reflection mode ran it.Changes:
TUnit.Core.TypedDataSourceAttribute<T>with noDataSourceGeneratorAttribute/AsyncDataSourceGeneratorAttributebase, such as[Arguments<T>]) now infers the method type arguments by matchingTagainst the data parameters, excluding anyCancellationToken. The whole row binds to a single data parameter; otherwise each tuple element binds to one data parameter, with generic type arguments nested in the parameter types matched as well. Every type parameter must be inferred, each to exactly one type.[Arguments<int[]>]onRun<T>(IEnumerable<T>)therefore infers nothing, rather than an uncallableRun<int[]>. A tuple row (a one-elementValueTupleincluded) always spreads over the data parameters, asToObjectArrayspreads it before invocation; anobject[],System.Tupleor otherITuplerow (whichDataSourceHelpers.IsTuplespreads without declaring element types) infers nothing. Omitted trailing optional parameters (params arrays and params collections included) are allowed, aFunc<T>,TestDataRow<T>(or a type deriving from it) orTestDataRow<Func<T>>row binds as itsTbecause it is invoked and unwrapped before invocation (a reference-type arrayTthere is spread byUnwrapArray, so its element binds; anobjectelement type infers nothing), and aT?parameter takes a row of its underlying type. A nullable tuple row infers nothing in either mode: a non-null value boxes to the tuple and spreads, but a null one binds whole, soRun<int>would turn it into0. Reflection mode infers each such row from its value; source-generated mode reports the Source-gen silently drops a generic test method when its type arguments cannot be inferred from the data source #7163 cannot-infer failure. A typed[Arguments<T[]>]row is never read as an untyped[Arguments]params array.TypedDataSourceInference.InferMethodTypeArgumentsFromRowType.TestMetadataGenerator.InferTypesFromDataSourceAttributecalls it on generic classes too. The class-only inference path (a non-generic method of a generic class) and the generator-base rules are unchanged.InferTypesFromTypedDataSourceapplies the same rules throughInferTypesFromTypedRow. This covers both the[GenerateGenericTest]path and the declared-type path without it (Typed data source whose declared type differs from its values: source-gen closes the generic method over the declared type, reflection over the run-time type #7206), so[Arguments<object>(1)]runsRun<object>in both modes.[GenerateGenericTest], an[Arguments<T>]row whose types another source already instantiated now joins that instantiation in reflection mode, in declaration order. The generator already joined it, because its name matchesArgumentsAttribute, so both modes now run the row instead of reflection dropping it.Tests
tests/TUnit.TestProject/Bugs/_7214cases andtests/TUnit.Engine.Tests/Issue7214Tests.cs(both modes):[Arguments]with[Arguments<int>]in either order, two[Arguments<int>]rows, a generic class closed by[GenerateGenericTest], and method[GenerateGenericTest]variants, including a typed row of a different type, a declaredobjectrow onRun<T>(T), an[Arguments<int[]>]row on anIEnumerable<T>parameter, a row with a trailing optional parameter, a row on aT?parameter, a row with an omitted C# 13paramscollection, a typed source ofTestDataRow<int>rows (unwrapped toT, as at invocation), a typed source of rows of a record deriving fromTestDataRow<int>(unwrapped the same way), and typed sources ofFunc<int>andTestDataRow<Func<int>>rows (invoked toint), a typed source ofValueTuple<int>rows (spread toint), a typed source ofValueTuple<TestDataRow<int>>rows (spread, then unwrapped toint), a typed source ofTestDataRow<string[]>rows (spread tostring), a null[Arguments<string[]>]row (onlyRun<string[]>, no untypedRun<object>), and a typed source ofITuplerows (not closed asRun<ITuple>: reflection infersRun<int>from the value, and source-generated mode reports the Source-gen silently drops a generic test method when its type arguments cannot be inferred from the data source #7163 cannot-infer failure, so the class has no[EngineTest]attribute), and a typed source of non-null and nullValueTuple<int>?rows (reflection runsRun<int>(1)andRun<object>(null); source-generated mode reports cannot-infer)._7214tests in source-gen and reflection modes (30 tests: reflection 30/30; source-gen 27/27 plus the expected cannot-infer failures ofTypedITupleRowSourceand the twoTypedNullableTupleRowSourcerows), theTUnit.Core.SourceGenerator.Testssnapshots (no changes), andTUnit.Analyzers.Tests.TUnit.Engine.Testsbuilds; its run is left to CI, per AGENTS.md.Closes #7214
Summary by CodeRabbit
paramsparameters, and typed data sources.