@@ -26,19 +26,19 @@ public static class GeneratorSnapshotTests
2626
2727 record struct StepOutput ( string Key , IncrementalStepRunReason Reason , object Value ) ;
2828
29- class Fixture
29+ private class Fixture
3030 {
3131 private readonly string projectDir ;
32- private readonly CSharpCompilation sampleCompilation ;
32+ public CSharpCompilation SampleCompilation { get ; }
33+ public CSharpParseOptions ParseOptions { get ; }
3334
3435 public Fixture ( string projectDir , CSharpCompilation sampleCompilation )
3536 {
3637 this . projectDir = projectDir ;
37- this . sampleCompilation = sampleCompilation ;
38+ SampleCompilation = sampleCompilation ;
39+ ParseOptions = ( CSharpParseOptions ) sampleCompilation . SyntaxTrees . First ( ) . Options ;
3840 }
3941
40- public CSharpCompilation SampleCompilation => sampleCompilation ;
41-
4242 public static async Task < Fixture > Compile ( string name )
4343 {
4444 var projectDir = Path . Combine ( GetProjectDir ( ) , "fixtures" , name ) ;
@@ -53,7 +53,7 @@ public Task Verify(string fileName, object target) =>
5353
5454 private static CSharpGeneratorDriver CreateDriver (
5555 IIncrementalGenerator generator ,
56- LanguageVersion languageVersion
56+ CSharpParseOptions parseOptions
5757 )
5858 {
5959 return CSharpGeneratorDriver . Create (
@@ -62,39 +62,39 @@ LanguageVersion languageVersion
6262 disabledOutputs : IncrementalGeneratorOutputKind . None ,
6363 trackIncrementalGeneratorSteps : true
6464 ) ,
65- // Make sure that generated files are parsed with the same language version.
66- parseOptions : new ( languageVersion )
65+ // Make sure generated files are parsed with the same language version and feature flags .
66+ parseOptions : parseOptions
6767 ) ;
6868 }
6969
7070 private async Task < IEnumerable < SyntaxTree > > RunAndCheckGenerator (
7171 IIncrementalGenerator generator
7272 )
7373 {
74- var driver = CreateDriver ( generator , sampleCompilation . LanguageVersion ) ;
74+ var driver = CreateDriver ( generator , ParseOptions ) ;
7575
7676 // Store the new driver instance - it contains the results and the cache.
77- var driverAfterGen = driver . RunGenerators ( sampleCompilation ) ;
77+ var driverAfterGen = driver . RunGenerators ( SampleCompilation ) ;
7878 var genResult = driverAfterGen . GetRunResult ( ) ;
7979
8080 // Verify the generated code against the snapshots.
8181 await Verify ( generator . GetType ( ) . Name , genResult ) ;
8282
83- CheckCacheWorking ( sampleCompilation , driverAfterGen ) ;
83+ CheckCacheWorking ( SampleCompilation , driverAfterGen ) ;
8484
8585 return genResult . GeneratedTrees ;
8686 }
8787
8888 public GeneratorDriverRunResult RunGeneratorAndGetResult ( IIncrementalGenerator generator )
8989 {
90- var driver = CreateDriver ( generator , sampleCompilation . LanguageVersion ) ;
91- return driver . RunGenerators ( sampleCompilation ) . GetRunResult ( ) ;
90+ var driver = CreateDriver ( generator , ParseOptions ) ;
91+ return driver . RunGenerators ( SampleCompilation ) . GetRunResult ( ) ;
9292 }
9393
9494 public async Task < CSharpCompilation > RunAndCheckGenerators (
9595 params IIncrementalGenerator [ ] generators
9696 ) =>
97- sampleCompilation . AddSyntaxTrees (
97+ SampleCompilation . AddSyntaxTrees (
9898 ( await Task . WhenAll ( generators . Select ( RunAndCheckGenerator ) ) ) . SelectMany ( output =>
9999 output
100100 )
@@ -241,10 +241,7 @@ public static async Task TypeAndModuleGeneratorsOnServer()
241241 // make sure a downstream "user" file that references SpacetimeDB.Local doesn't trigger CS0436.
242242 var userCode =
243243 "namespace User; public sealed class UseLocal { public SpacetimeDB.Local Db; }" ;
244- var userTree = CSharpSyntaxTree . ParseText (
245- userCode ,
246- new CSharpParseOptions ( compilationAfterGen . LanguageVersion )
247- ) ;
244+ var userTree = CSharpSyntaxTree . ParseText ( userCode , fixture . ParseOptions ) ;
248245 var compilationWithUserCode = compilationAfterGen . AddSyntaxTrees ( userTree ) ;
249246 AssertNoCs0436Diagnostics ( compilationWithUserCode ) ;
250247 }
@@ -332,8 +329,11 @@ public static void @params(ProcedureContext ctx)
332329 }
333330 """ ;
334331
335- var parseOptions = new CSharpParseOptions ( fixture . SampleCompilation . LanguageVersion ) ;
336- var tree = CSharpSyntaxTree . ParseText ( source , parseOptions , path : "KeywordNames.cs" ) ;
332+ var tree = CSharpSyntaxTree . ParseText (
333+ source ,
334+ fixture . ParseOptions ,
335+ path : "KeywordNames.cs"
336+ ) ;
337337 var compilation = fixture . SampleCompilation . AddSyntaxTrees ( tree ) ;
338338
339339 var driver = CSharpGeneratorDriver . Create (
@@ -345,7 +345,7 @@ public static void @params(ProcedureContext ctx)
345345 disabledOutputs : IncrementalGeneratorOutputKind . None ,
346346 trackIncrementalGeneratorSteps : true
347347 ) ,
348- parseOptions : parseOptions
348+ parseOptions : fixture . ParseOptions
349349 ) ;
350350
351351 var runResult = driver . RunGenerators ( compilation ) . GetRunResult ( ) ;
0 commit comments