You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Source-gen: generic test class does not infer its type arguments from a class-level [MethodDataSource]; reflection does #7333
A generic test class whose only type information is a class-level [MethodDataSource] runs in reflection mode, but source-gen mode emits no test for it. Nothing is reported: the test is missing from the run.
A class-level [MethodDataSource] whose declared rows name the class's own type parameter (IEnumerable<T> Values()), with nothing else that supplies T, also emits nothing in source-gen. Reflection reports a failed test that explains the problem.
Where
TestMetadataGenerator infers a generic class's type arguments from class-level [Arguments] rows and typed class data sources (InferTypesFromTypedDataSourceForClass), but not from a class-level [MethodDataSource]. Reflection (ReflectionTestDataCollector.GroupClassRowsByTypeArgumentsAsync) reads the source's rows and groups them by the type of their values.
Expected
Both modes behave the same. For example, source-gen infers the class type arguments from the declared row type of the class-level [MethodDataSource] member, as it already does for method-level [MethodDataSource] members. If it cannot infer them, it reports a diagnostic or a failed test instead of silently emitting nothing.
Another case of this gap, found while fixing #7336. A [GenerateGenericTest] instantiation that class [Arguments] rows also infer, with method rows that infer the class type:
Source-gen runs one test, with value = 1. The Values() row (5) never runs. Reflection runs two, with values 1 and 5, after #7336. The repro is tests/TUnit.TestProject/Bugs/_7208/OwnClassTypeParameterMethodDataSourceWithArgumentsAndGenerateGenericTest. Issue7208Tests asserts each mode's count, so a fix here must update that test's source-gen expectation to 2.
Update: #7336 (bc1b447) fixes the [GenerateGenericTest] + class [Arguments] + method rows case I added to this issue earlier. Source-gen now reads the own-class member on that instantiation, as reflection does. What remains here is what the body describes: source-gen doesn't infer a generic class's type arguments from a class-level [MethodDataSource], so a class whose types only that source supplies emits no test.
A related case came up while fixing a Codex finding on #7336. When class [Arguments] rows already supply the types, source-gen still drops the rows of a class-level [MethodDataSource]:
Reflection groups both rows into C<int> and runs 2 tests. In source-gen, a concrete own-class member joins the C<int> instantiation only when a class-level [GenerateGenericTest(typeof(int))] also names it, through GetOwnClassMethodDataSourcesForInstantiation in TestMetadataGenerator (#7336). Without that attribute, only the [Arguments] row runs, according to the generator code; I haven't run this exact class. Fixing #7333 should cover this case as well.
Validation while implementing #7443 on main at 07a554f: the existing _7208 fixtures run 43 tests in both modes. Source-generated discovery has 39 passes and four type-inference failures; reflection has 42 passes and one intentional discovery failure. The three additional generated-mode failures remain within this issue’s class-level MethodDataSource inference scope.
Activity
thomhurst commentedon Nov 1, 2026
Another case of this gap, found while fixing #7336. A
[GenerateGenericTest]instantiation that class[Arguments]rows also infer, with method rows that infer the class type:Source-gen runs one test, with
value = 1. TheValues()row (5) never runs. Reflection runs two, with values 1 and 5, after #7336. The repro istests/TUnit.TestProject/Bugs/_7208/OwnClassTypeParameterMethodDataSourceWithArgumentsAndGenerateGenericTest.Issue7208Testsasserts each mode's count, so a fix here must update that test's source-gen expectation to 2.thomhurst commentedon Nov 1, 2026
Update: #7336 (bc1b447) fixes the
[GenerateGenericTest]+ class[Arguments]+ method rows case I added to this issue earlier. Source-gen now reads the own-class member on that instantiation, as reflection does. What remains here is what the body describes: source-gen doesn't infer a generic class's type arguments from a class-level[MethodDataSource], so a class whose types only that source supplies emits no test.thomhurst commentedon Nov 1, 2026
A related case came up while fixing a Codex finding on #7336. When class
[Arguments]rows already supply the types, source-gen still drops the rows of a class-level[MethodDataSource]:Reflection groups both rows into
C<int>and runs 2 tests. In source-gen, a concrete own-class member joins theC<int>instantiation only when a class-level[GenerateGenericTest(typeof(int))]also names it, throughGetOwnClassMethodDataSourcesForInstantiationinTestMetadataGenerator(#7336). Without that attribute, only the[Arguments]row runs, according to the generator code; I haven't run this exact class. Fixing #7333 should cover this case as well.fix(generator): omit unmatched class method source instantiations (#7333
fix(generator): preserve method rows and polymorphic class partitioni…
fix(generator): preserve array and nullable class source inference (#…
fix(discovery): infer nullable array constructor rows consistently (#…
fix(discovery): retain null row filtering and typed construction (#7333)
fix(discovery): guard only columns that infer class types (#7333)
fix(discovery): preserve class source factories and constructors (#7333)
7 remaining items
fix(generator): retain grouped explicit class-row filtering (#7333)
fix(generator): retain explicit null-only class rows (#7333)
fix: preserve actual generic class row groups for #7333
Fix filtering of inferred sources outside runtime partitions (#7333)
fix(generator): preserve unmatched class Arguments fallback (#7333)
fix(generator): preserve inferred constructors for grouped rows (#7333)
fix: group explicit class rows with method data sources (#7333)
fix: report class source constraints only for actual rows (#7333)
fix: retain invalid external tuple row shape (#7333)
Fix inferred empty class source skip placeholders (#7333)
Correct successful TRX summary expectations (#7333)
thomhurst commentedon Nov 3, 2026
Validation while implementing #7443 on main at 07a554f: the existing
_7208fixtures run 43 tests in both modes. Source-generated discovery has 39 passes and four type-inference failures; reflection has 42 passes and one intentional discovery failure. The three additional generated-mode failures remain within this issue’s class-level MethodDataSource inference scope.