@@ -21,6 +21,12 @@ public enum TestOptions
2121 DoNotFailOnDiagnostics = 2 ,
2222}
2323
24+ public record NativeMethodsJsonOptions (
25+ bool ? AllowMarshaling = null ,
26+ bool ? EmitSingleFile = null ,
27+ bool ? Public = null ,
28+ string ? ClassName = null ) ;
29+
2430public partial class CsWin32GeneratorTestsBase : GeneratorTestBase
2531{
2632 protected bool fullGeneration ;
@@ -35,6 +41,7 @@ public partial class CsWin32GeneratorTestsBase : GeneratorTestBase
3541 protected int expectedExitCode = 0 ;
3642 protected string ? tfm ;
3743 protected string [ ] ? win32winmdPaths ;
44+ protected NativeMethodsJsonOptions ? nativeMethodsJsonOptions ;
3845
3946 public CsWin32GeneratorTestsBase ( ITestOutputHelper logger )
4047 : base ( logger )
@@ -99,6 +106,16 @@ protected async Task InvokeGenerator(string outputPath, string testCase, TestOpt
99106 File . WriteAllLines ( nativeMethodsTxtPath , this . nativeMethods ) ;
100107 }
101108
109+ if ( this . nativeMethodsJsonOptions is NativeMethodsJsonOptions generatorOptions )
110+ {
111+ string nativeMethodsJsonPath = Path . Combine ( this . GetTestCaseOutputDirectory ( testCase ) , "NativeMethods.json" ) ;
112+ var jsonOptions = new System . Text . Json . JsonSerializerOptions { WriteIndented = true } ;
113+ jsonOptions . DefaultIgnoreCondition = System . Text . Json . Serialization . JsonIgnoreCondition . WhenWritingDefault ;
114+ string jsonContent = System . Text . Json . JsonSerializer . Serialize ( generatorOptions , jsonOptions ) ;
115+ File . WriteAllText ( nativeMethodsJsonPath , jsonContent ) ;
116+ this . nativeMethodsJson = Path . GetFileName ( nativeMethodsJsonPath ) ;
117+ }
118+
102119 Directory . CreateDirectory ( outputPath ) ;
103120
104121 this . Logger . WriteLine ( $ "OutputPath: { outputPath } ") ;
0 commit comments