66using System . Diagnostics . CodeAnalysis ;
77using System . Runtime . CompilerServices ;
88using System . Runtime . Loader ;
9- using Xunit . Abstractions ;
109
1110public static class CSharpGeneratorRunner
1211{
@@ -25,7 +24,13 @@ public static void InitializeCompilation()
2524
2625 var references = AppDomain . CurrentDomain . GetAssemblies ( )
2726 . Where ( x => ! x . IsDynamic && ! string . IsNullOrWhiteSpace ( x . Location ) )
28- . Select ( x => MetadataReference . CreateFromFile ( x . Location ) ) ;
27+ . Select ( x => MetadataReference . CreateFromFile ( x . Location ) )
28+ . Concat ( [
29+ MetadataReference . CreateFromFile ( typeof ( Console ) . Assembly . Location ) , // System.Console.dll
30+ MetadataReference . CreateFromFile ( typeof ( IServiceProvider ) . Assembly . Location ) , // System.ComponentModel.dll
31+ MetadataReference . CreateFromFile ( typeof ( System . ComponentModel . DataAnnotations . RequiredAttribute ) . Assembly . Location ) , // System.ComponentModel.DataAnnotations
32+ MetadataReference . CreateFromFile ( typeof ( System . Text . Json . JsonDocument ) . Assembly . Location ) , // System.Text.Json.dll
33+ ] ) ;
2934
3035 var compilation = CSharpCompilation . Create ( "generatortest" ,
3136 references : references ,
@@ -144,7 +149,7 @@ public class VerifyHelper(ITestOutputHelper output, string idPrefix)
144149
145150 public void Ok ( [ StringSyntax ( "C#-test" ) ] string code , [ CallerArgumentExpression ( "code" ) ] string ? codeExpr = null )
146151 {
147- output . WriteLine ( codeExpr ) ;
152+ output . WriteLine ( codeExpr ! ) ;
148153
149154 var ( compilation , diagnostics ) = CSharpGeneratorRunner . RunGenerator ( code ) ;
150155 foreach ( var item in diagnostics )
@@ -158,7 +163,7 @@ public void Ok([StringSyntax("C#-test")] string code, [CallerArgumentExpression(
158163
159164 public void Verify ( int id , [ StringSyntax ( "C#-test" ) ] string code , string diagnosticsCodeSpan , [ CallerArgumentExpression ( "code" ) ] string ? codeExpr = null )
160165 {
161- output . WriteLine ( codeExpr ) ;
166+ output . WriteLine ( codeExpr ! ) ;
162167
163168 var ( compilation , diagnostics ) = CSharpGeneratorRunner . RunGenerator ( code ) ;
164169 foreach ( var item in diagnostics )
@@ -176,7 +181,7 @@ public void Verify(int id, [StringSyntax("C#-test")] string code, string diagnos
176181
177182 public ( string , string ) [ ] Verify ( [ StringSyntax ( "C#-test" ) ] string code , [ CallerArgumentExpression ( "code" ) ] string ? codeExpr = null )
178183 {
179- output . WriteLine ( codeExpr ) ;
184+ output . WriteLine ( codeExpr ! ) ;
180185
181186 var ( compilation , diagnostics ) = CSharpGeneratorRunner . RunGenerator ( code ) ;
182187 OutputGeneratedCode ( compilation ) ;
@@ -187,7 +192,7 @@ public void Verify(int id, [StringSyntax("C#-test")] string code, string diagnos
187192
188193 public void Execute ( [ StringSyntax ( "C#-test" ) ] string code , string args , string expected , [ CallerArgumentExpression ( "code" ) ] string ? codeExpr = null )
189194 {
190- output . WriteLine ( codeExpr ) ;
195+ output . WriteLine ( codeExpr ! ) ;
191196
192197 var ( compilation , diagnostics , stdout ) = CSharpGeneratorRunner . CompileAndExecute ( code , args == "" ? [ ] : args . Split ( ' ' ) ) ;
193198 foreach ( var item in diagnostics )
@@ -201,7 +206,7 @@ public void Execute([StringSyntax("C#-test")] string code, string args, string e
201206
202207 public string Error ( [ StringSyntax ( "C#-test" ) ] string code , string args , [ CallerArgumentExpression ( "code" ) ] string ? codeExpr = null )
203208 {
204- output . WriteLine ( codeExpr ) ;
209+ output . WriteLine ( codeExpr ! ) ;
205210
206211 var ( compilation , diagnostics , stdout ) = CSharpGeneratorRunner . CompileAndExecute ( code , args == "" ? [ ] : args . Split ( ' ' ) ) ;
207212 foreach ( var item in diagnostics )
0 commit comments