Test netmodules containing module initializers#44228
Test netmodules containing module initializers#44228RikkiGibson merged 4 commits intodotnet:features/module-initializersfrom
Conversation
| namespace System.Runtime.CompilerServices { public class ModuleInitializerAttribute : System.Attribute { } }"; | ||
| var comp1 = CreateCompilation(s1, options: TestOptions.ReleaseModule.WithModuleName("A"), parseOptions: s_parseOptions); | ||
| comp1.VerifyDiagnostics(); | ||
| var ref1 = comp1.EmitToImageReference(); |
There was a problem hiding this comment.
var ref1 = comp1.EmitToImageReference(); [](start = 12, length = 40)
I think for each compilation we want to verify whether we emit the <Module>..cctor #Closed
| var comp6 = CreateCompilation(s6, options: TestOptions.ReleaseExe.WithModuleName("C"), parseOptions: s_parseOptions, references: new[] { ref1, ref2 }); | ||
| comp6.VerifyDiagnostics(); | ||
| CompileAndVerify(comp6, expectedOutput: "13"); | ||
| } |
There was a problem hiding this comment.
} [](start = 8, length = 1)
I think it would be good to cover scenarios when the main module of the assembly also has an initializer. #Closed
|
Done with review pass (iteration 1) #Closed |
| [ModuleInitializer] | ||
| public static void Init() | ||
| { | ||
| Console.Write(1); |
There was a problem hiding this comment.
1 [](start = 22, length = 1)
Does this number conflict with the one printed by ref1? Please use unique numbers to avoid any confusion. #Closed
| void validateNoModuleInitializer(ModuleSymbol module) | ||
| { | ||
| var moduleType = module.ContainingAssembly.GetTypeByMetadataName("<Module>"); | ||
| Assert.Null(moduleType.GetMember<MethodSymbol>(".cctor")); |
There was a problem hiding this comment.
Assert.Null(moduleType.GetMember(".cctor")); [](start = 16, length = 58)
Please add Assert.Equal(MetadataImportOptions.All, ((PEModuleSymbol)module).ImportOptions); as we do in other similar validators. #Closed
AlekseyTs
left a comment
There was a problem hiding this comment.
LGTM (iteration 2), with a couple of suggestions for the test.
…yn into mi-netmodules
Related to #40500.
Test based on
CompilationEmitTests.MultipleNetmodulesWithAnonymousTypes.Will think on whether there are more netmodule scenarios we need to test.