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-generator snapshot harness parses fixtures with an old language version, so collection-expression attribute arguments are silently dropped #7162
tests/TUnit.Core.SourceGenerator.Tests/TestsBase.cs parses each fixture with CSharpSyntaxTree.ParseText(source). That uses the default CSharpParseOptions of the referenced Roslyn, not LanguageVersion.Preview/latest. Newer syntax used throughout tests/TUnit.TestProject therefore fails to bind in the snapshot compilation. Examples are collection expressions and primary constructors (CS8652 "feature is currently in Preview"). The harness checks only generator diagnostics, not compilation diagnostics, so these failures are silent. The snapshot then records what the generator does with broken input instead of what a real build produces.
Concrete case: [MethodDataSource(nameof(AsyncDataMethodWithArgs), Arguments = [5])] in tests/TUnit.TestProject/AsyncMethodDataSourceDrivenTests.cs. In the harness, Arguments = [5] reports CS8652 and CS0182, so the named argument is dropped. The verified snapshot (AsyncMethodDataSourceDrivenTests.Test.verified.txt) shows a factory calling AsyncDataMethodWithArgs() with no argument and no Arguments = ... line. A real build passes the argument. This came up on #7143, where two review bots flagged a snapshot as "expecting the wrong call" for the same reason.
How to reproduce
Temporarily add this before await assertions(generatedFiles); in TestsBase.RunTest, then run any snapshot test (e.g. Tests7108):
You will see CS8652 for collection literals and primary constructors, and CS0182 for attribute collection expressions. Other errors also appear, such as missing AutoFixture and Assert references.
Expected
The harness should parse with new CSharpParseOptions(LanguageVersion.Preview), as AotConverterScanTests, AttributeInitializerCacheTests and CrossCompilationAttributeTests already do. Snapshots would then reflect real-build generator output. Ideally the harness would also fail, or at least report, on syntax-level compilation errors in the input. Expect a one-time sweep of snapshot updates.
Activity
test(sourcegen): parse snapshot fixtures as a real build does (thomhu…