6
6
using System . Diagnostics . CodeAnalysis ;
7
7
using System . Runtime . CompilerServices ;
8
8
using System . Runtime . Loader ;
9
- using Xunit . Abstractions ;
10
9
11
10
public static class CSharpGeneratorRunner
12
11
{
@@ -25,7 +24,13 @@ public static void InitializeCompilation()
25
24
26
25
var references = AppDomain . CurrentDomain . GetAssemblies ( )
27
26
. 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
+ ] ) ;
29
34
30
35
var compilation = CSharpCompilation . Create ( "generatortest" ,
31
36
references : references ,
@@ -144,7 +149,7 @@ public class VerifyHelper(ITestOutputHelper output, string idPrefix)
144
149
145
150
public void Ok ( [ StringSyntax ( "C#-test" ) ] string code , [ CallerArgumentExpression ( "code" ) ] string ? codeExpr = null )
146
151
{
147
- output . WriteLine ( codeExpr ) ;
152
+ output . WriteLine ( codeExpr ! ) ;
148
153
149
154
var ( compilation , diagnostics ) = CSharpGeneratorRunner . RunGenerator ( code ) ;
150
155
foreach ( var item in diagnostics )
@@ -158,7 +163,7 @@ public void Ok([StringSyntax("C#-test")] string code, [CallerArgumentExpression(
158
163
159
164
public void Verify ( int id , [ StringSyntax ( "C#-test" ) ] string code , string diagnosticsCodeSpan , [ CallerArgumentExpression ( "code" ) ] string ? codeExpr = null )
160
165
{
161
- output . WriteLine ( codeExpr ) ;
166
+ output . WriteLine ( codeExpr ! ) ;
162
167
163
168
var ( compilation , diagnostics ) = CSharpGeneratorRunner . RunGenerator ( code ) ;
164
169
foreach ( var item in diagnostics )
@@ -176,7 +181,7 @@ public void Verify(int id, [StringSyntax("C#-test")] string code, string diagnos
176
181
177
182
public ( string , string ) [ ] Verify ( [ StringSyntax ( "C#-test" ) ] string code , [ CallerArgumentExpression ( "code" ) ] string ? codeExpr = null )
178
183
{
179
- output . WriteLine ( codeExpr ) ;
184
+ output . WriteLine ( codeExpr ! ) ;
180
185
181
186
var ( compilation , diagnostics ) = CSharpGeneratorRunner . RunGenerator ( code ) ;
182
187
OutputGeneratedCode ( compilation ) ;
@@ -187,7 +192,7 @@ public void Verify(int id, [StringSyntax("C#-test")] string code, string diagnos
187
192
188
193
public void Execute ( [ StringSyntax ( "C#-test" ) ] string code , string args , string expected , [ CallerArgumentExpression ( "code" ) ] string ? codeExpr = null )
189
194
{
190
- output . WriteLine ( codeExpr ) ;
195
+ output . WriteLine ( codeExpr ! ) ;
191
196
192
197
var ( compilation , diagnostics , stdout ) = CSharpGeneratorRunner . CompileAndExecute ( code , args == "" ? [ ] : args . Split ( ' ' ) ) ;
193
198
foreach ( var item in diagnostics )
@@ -201,7 +206,7 @@ public void Execute([StringSyntax("C#-test")] string code, string args, string e
201
206
202
207
public string Error ( [ StringSyntax ( "C#-test" ) ] string code , string args , [ CallerArgumentExpression ( "code" ) ] string ? codeExpr = null )
203
208
{
204
- output . WriteLine ( codeExpr ) ;
209
+ output . WriteLine ( codeExpr ! ) ;
205
210
206
211
var ( compilation , diagnostics , stdout ) = CSharpGeneratorRunner . CompileAndExecute ( code , args == "" ? [ ] : args . Split ( ' ' ) ) ;
207
212
foreach ( var item in diagnostics )
0 commit comments