1- using ConsoleAppFramework ;
1+ using Basic . Reference . Assemblies ;
2+ using ConsoleAppFramework ;
23using Microsoft . CodeAnalysis ;
34using Microsoft . CodeAnalysis . CSharp ;
45using Microsoft . CodeAnalysis . Diagnostics ;
89using System . Runtime . CompilerServices ;
910using System . Runtime . Loader ;
1011
11- public static class CSharpGeneratorRunner
12+ public class CSharpGeneratorRunner
1213{
13- static Compilation baseCompilation = default ! ;
14+ Compilation baseCompilation = default ! ;
1415
15- [ ModuleInitializer ]
16- public static void InitializeCompilation ( )
16+ public CSharpGeneratorRunner ( )
1717 {
1818 var globalUsings = """
1919global using System;
@@ -23,25 +23,15 @@ public static void InitializeCompilation()
2323global using ConsoleAppFramework;
2424""" ;
2525
26- var references = AppDomain . CurrentDomain . GetAssemblies ( )
27- . Where ( x => ! x . IsDynamic && ! string . IsNullOrWhiteSpace ( x . Location ) )
28- . Select ( x => MetadataReference . CreateFromFile ( x . Location ) )
29- . Concat ( [
30- MetadataReference . CreateFromFile ( typeof ( Console ) . Assembly . Location ) , // System.Console.dll
31- MetadataReference . CreateFromFile ( typeof ( IServiceProvider ) . Assembly . Location ) , // System.ComponentModel.dll
32- MetadataReference . CreateFromFile ( typeof ( System . ComponentModel . DataAnnotations . RequiredAttribute ) . Assembly . Location ) , // System.ComponentModel.DataAnnotations
33- MetadataReference . CreateFromFile ( typeof ( System . Text . Json . JsonDocument ) . Assembly . Location ) , // System.Text.Json.dll
34- ] ) ;
35-
3626 var compilation = CSharpCompilation . Create ( "generatortest" ,
37- references : references ,
27+ references : ReferenceAssemblies . Net80 , // .NET 8
3828 syntaxTrees : [ CSharpSyntaxTree . ParseText ( globalUsings , path : "GlobalUsings.cs" ) ] ,
3929 options : new CSharpCompilationOptions ( OutputKind . ConsoleApplication , allowUnsafe : true ) ) ; // .exe
4030
4131 baseCompilation = compilation ;
4232 }
4333
44- public static ( Compilation , ImmutableArray < Diagnostic > ) RunGenerator ( [ StringSyntax ( "C#-test" ) ] string source , string [ ] ? preprocessorSymbols = null , AnalyzerConfigOptionsProvider ? options = null )
34+ public ( Compilation , ImmutableArray < Diagnostic > ) RunGenerator ( [ StringSyntax ( "C#-test" ) ] string source , string [ ] ? preprocessorSymbols = null , AnalyzerConfigOptionsProvider ? options = null )
4535 {
4636 if ( preprocessorSymbols == null )
4737 {
@@ -91,7 +81,7 @@ public static class Environment
9181 return ( newCompilation , diagnostics ) ;
9282 }
9383
94- public static ( Compilation Compilation , ImmutableArray < Diagnostic > Diagnostics , string Stdout , int ExitCode ) CompileAndExecute ( string source , string [ ] args , string [ ] ? preprocessorSymbols = null , AnalyzerConfigOptionsProvider ? options = null )
84+ public ( Compilation Compilation , ImmutableArray < Diagnostic > Diagnostics , string Stdout , int ExitCode ) CompileAndExecute ( string source , string [ ] args , string [ ] ? preprocessorSymbols = null , AnalyzerConfigOptionsProvider ? options = null )
9585 {
9686 var ( compilation , diagnostics ) = RunGenerator ( source , preprocessorSymbols , options ) ;
9787
@@ -121,7 +111,7 @@ public static (Compilation Compilation, ImmutableArray<Diagnostic> Diagnostics,
121111 return ( compilation , diagnostics , stringWriter . ToString ( ) , exitCode ) ;
122112 }
123113
124- public static ( string Key , string Reasons ) [ ] [ ] GetIncrementalGeneratorTrackedStepsReasons ( string keyPrefixFilter , params string [ ] sources )
114+ public ( string Key , string Reasons ) [ ] [ ] GetIncrementalGeneratorTrackedStepsReasons ( string keyPrefixFilter , params string [ ] sources )
125115 {
126116 var parseOptions = new CSharpParseOptions ( LanguageVersion . CSharp13 ) ; // 13
127117 var driver = CSharpGeneratorDriver . Create (
@@ -167,8 +157,13 @@ [new ConsoleAppGenerator().AsSourceGenerator()],
167157 }
168158}
169159
170- public class VerifyHelper ( string idPrefix )
160+ public class VerifyHelper
171161{
162+ readonly string idPrefix = "CAF" ;
163+
164+ [ ClassDataSource < CSharpGeneratorRunner > ( Shared = SharedType . PerTestSession ) ]
165+ public required CSharpGeneratorRunner CSharpGeneratorRunner { get ; init ; }
166+
172167 public async Task Ok ( [ StringSyntax ( "C#-test" ) ] string code , [ CallerArgumentExpression ( "code" ) ] string ? codeExpr = null )
173168 {
174169 Console . WriteLine ( codeExpr ! ) ;
0 commit comments