[AA] Allow specifying REx file contents in testdata.

Tests can now specify the code generated by a resolve extension from
within the test's testdata. Module-level directives control whether
resolve extensions are enabled for that module, as well as package names
and source shadowing regexes. File-level directives allow a `// FILE:`
block within the testdata to be converted into a KtResolveExtensionFile
and removed from the module as a whole. (This requires a new
`ModuleStructureTransformer`, because we need to be able to entirely
remove the files in question.)

Any test can add support for these directives by calling
`KtResolveExtensionTestSupport.configure` from within their
`configureTest` stanza. This allows this functionality to be used in
conjuction with any test base class.

^KT-59329
This commit is contained in:
Justin Paupore
2023-06-14 23:49:03 -07:00
committed by Ilya Kirillov
parent 7a69f13fd6
commit 734b87b97e
41 changed files with 666 additions and 565 deletions
@@ -32,7 +32,7 @@ class TestConfigurationBuilder {
private val preAnalysisHandlers: MutableList<Constructor<PreAnalysisHandler>> = mutableListOf()
private val additionalSourceProviders: MutableList<Constructor<AdditionalSourceProvider>> = mutableListOf()
private val moduleStructureTransformers: MutableList<ModuleStructureTransformer> = mutableListOf()
private val moduleStructureTransformers: MutableList<Constructor<ModuleStructureTransformer>> = mutableListOf()
private val metaTestConfigurators: MutableList<Constructor<MetaTestConfigurator>> = mutableListOf()
private val afterAnalysisCheckers: MutableList<Constructor<AfterAnalysisChecker>> = mutableListOf()
@@ -180,6 +180,13 @@ class TestConfigurationBuilder {
@TestInfrastructureInternals
fun useModuleStructureTransformers(vararg transformers: ModuleStructureTransformer) {
for (transformer in transformers) {
moduleStructureTransformers += { _ -> transformer }
}
}
@TestInfrastructureInternals
fun useModuleStructureTransformers(vararg transformers: Constructor<ModuleStructureTransformer>) {
moduleStructureTransformers += transformers
}
@@ -265,7 +272,7 @@ class TestConfigurationBuilder {
get() = builder.preAnalysisHandlers
val additionalSourceProviders: List<Constructor<AdditionalSourceProvider>>
get() = builder.additionalSourceProviders
val moduleStructureTransformers: List<ModuleStructureTransformer>
val moduleStructureTransformers: List<Constructor<ModuleStructureTransformer>>
get() = builder.moduleStructureTransformers
val metaTestConfigurators: List<Constructor<MetaTestConfigurator>>
get() = builder.metaTestConfigurators
@@ -34,7 +34,7 @@ class TestConfigurationImpl(
additionalSourceProviders: List<Constructor<AdditionalSourceProvider>>,
preAnalysisHandlers: List<Constructor<PreAnalysisHandler>>,
moduleStructureTransformers: List<ModuleStructureTransformer>,
moduleStructureTransformers: List<Constructor<ModuleStructureTransformer>>,
metaTestConfigurators: List<Constructor<MetaTestConfigurator>>,
afterAnalysisCheckers: List<Constructor<AfterAnalysisChecker>>,
@@ -83,7 +83,7 @@ class TestConfigurationImpl(
additionalSourceProviders
.map { it.invoke(testServices) }
.also { it.registerDirectivesAndServices() },
moduleStructureTransformers,
moduleStructureTransformers.map { it(testServices) },
this.environmentConfigurators
)