[AA] Add KtTestModule.moduleKind
- `TestModule.explicitTestModuleKind` requires a directive to be present to get the `TestModuleKind`. But we still want to find out the test module kind for test modules without a directive. Hence, we have to add this property to `KtTestModule` during its construction. ^KT-65960
This commit is contained in:
committed by
Space Team
parent
dc0f498b15
commit
7baaa38b8a
+2
-1
@@ -36,7 +36,8 @@ object AnalysisApiFe10TestConfiguratorFactory : AnalysisApiTestConfiguratorFacto
|
||||
TestModuleKind.ScriptSource,
|
||||
TestModuleKind.LibraryBinary,
|
||||
TestModuleKind.LibrarySource,
|
||||
TestModuleKind.CodeFragment -> {
|
||||
TestModuleKind.CodeFragment,
|
||||
TestModuleKind.NotUnderContentRoot -> {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
+4
@@ -41,6 +41,8 @@ object AnalysisApiFirTestConfiguratorFactory : AnalysisApiTestConfiguratorFactor
|
||||
AnalysisSessionMode.Normal -> AnalysisApiFirCodeFragmentTestConfigurator(analyseInDependentSession = false)
|
||||
AnalysisSessionMode.Dependent -> AnalysisApiFirCodeFragmentTestConfigurator(analyseInDependentSession = true)
|
||||
}
|
||||
|
||||
else -> unsupportedModeError(data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,6 +61,8 @@ object AnalysisApiFirTestConfiguratorFactory : AnalysisApiTestConfiguratorFactor
|
||||
TestModuleKind.CodeFragment -> {
|
||||
data.analysisSessionMode == AnalysisSessionMode.Normal
|
||||
}
|
||||
|
||||
TestModuleKind.NotUnderContentRoot -> false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-1
@@ -41,7 +41,8 @@ object AnalysisApiFirStandaloneModeTestConfiguratorFactory : AnalysisApiTestConf
|
||||
}
|
||||
|
||||
TestModuleKind.ScriptSource,
|
||||
TestModuleKind.LibrarySource -> {
|
||||
TestModuleKind.LibrarySource,
|
||||
TestModuleKind.NotUnderContentRoot -> {
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -9,6 +9,7 @@ import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.analysis.project.structure.DanglingFileResolutionMode
|
||||
import org.jetbrains.kotlin.analysis.project.structure.impl.KtDanglingFileModuleImpl
|
||||
import org.jetbrains.kotlin.analysis.test.framework.services.expressionMarkerProvider
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind
|
||||
import org.jetbrains.kotlin.psi.KtBlockCodeFragment
|
||||
import org.jetbrains.kotlin.psi.KtCodeFragment
|
||||
import org.jetbrains.kotlin.psi.KtElement
|
||||
@@ -24,6 +25,9 @@ import org.jetbrains.kotlin.test.services.TestServices
|
||||
import org.jetbrains.kotlin.test.services.sourceFileProvider
|
||||
import java.nio.file.Path
|
||||
|
||||
/**
|
||||
* @see TestModuleKind.CodeFragment
|
||||
*/
|
||||
object KtCodeFragmentModuleFactory : KtModuleFactory {
|
||||
override fun createModule(
|
||||
testModule: TestModule,
|
||||
@@ -68,7 +72,7 @@ object KtCodeFragmentModuleFactory : KtModuleFactory {
|
||||
DanglingFileResolutionMode.PREFER_SELF
|
||||
)
|
||||
|
||||
return KtTestModule(testModule, module, listOf(codeFragment))
|
||||
return KtTestModule(TestModuleKind.CodeFragment, testModule, module, listOf(codeFragment))
|
||||
}
|
||||
|
||||
private fun findContextElement(file: KtFile, testServices: TestServices): KtElement? {
|
||||
|
||||
+3
-1
@@ -10,12 +10,13 @@ import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.Stand
|
||||
import org.jetbrains.kotlin.analysis.test.framework.services.environmentManager
|
||||
import org.jetbrains.kotlin.analysis.test.framework.services.libraries.compiledLibraryProvider
|
||||
import org.jetbrains.kotlin.analysis.test.framework.services.libraries.testModuleDecompiler
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
import java.nio.file.Path
|
||||
|
||||
/**
|
||||
* @see org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind.LibraryBinary
|
||||
* @see TestModuleKind.LibraryBinary
|
||||
*/
|
||||
object KtLibraryBinaryModuleFactory : KtModuleFactory {
|
||||
override fun createModule(
|
||||
@@ -29,6 +30,7 @@ object KtLibraryBinaryModuleFactory : KtModuleFactory {
|
||||
val decompiledFiles = testServices.testModuleDecompiler.getAllPsiFilesFromLibrary(library, project)
|
||||
|
||||
return KtTestModule(
|
||||
TestModuleKind.LibraryBinary,
|
||||
testModule,
|
||||
KtLibraryModuleImpl(
|
||||
testModule.name,
|
||||
|
||||
+3
-2
@@ -11,6 +11,7 @@ import org.jetbrains.kotlin.analysis.api.impl.base.util.LibraryUtils
|
||||
import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.StandaloneProjectFactory
|
||||
import org.jetbrains.kotlin.analysis.test.framework.services.environmentManager
|
||||
import org.jetbrains.kotlin.analysis.test.framework.services.libraries.compiledLibraryProvider
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
import org.jetbrains.kotlin.platform.isMultiPlatform
|
||||
@@ -18,7 +19,7 @@ import org.junit.Assume
|
||||
import java.nio.file.Path
|
||||
|
||||
/**
|
||||
* @see org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind.LibrarySource
|
||||
* @see TestModuleKind.LibrarySource
|
||||
*/
|
||||
object KtLibrarySourceModuleFactory : KtModuleFactory {
|
||||
override fun createModule(
|
||||
@@ -73,5 +74,5 @@ fun createKtLibrarySourceModule(
|
||||
)
|
||||
|
||||
libraryKtModule.librarySources = librarySourceKtModule
|
||||
return KtTestModule(testModule, librarySourceKtModule, decompiledPsiFilesFromSourceJar)
|
||||
return KtTestModule(TestModuleKind.LibrarySource, testModule, librarySourceKtModule, decompiledPsiFilesFromSourceJar)
|
||||
}
|
||||
|
||||
+3
-2
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.analysis.test.framework.project.structure
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.moduleKind
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.explicitTestModuleKind
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.TestService
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
@@ -46,11 +46,12 @@ private val TestServices.ktModuleFactory: KtModuleFactory by TestServices.testSe
|
||||
*
|
||||
* @see org.jetbrains.kotlin.analysis.test.framework.services.DependencyKindModuleStructureTransformer
|
||||
*/
|
||||
fun TestServices.getKtModuleFactoryForTestModule(testModule: TestModule): KtModuleFactory = when (testModule.moduleKind) {
|
||||
fun TestServices.getKtModuleFactoryForTestModule(testModule: TestModule): KtModuleFactory = when (testModule.explicitTestModuleKind) {
|
||||
TestModuleKind.Source -> KtSourceModuleFactory
|
||||
TestModuleKind.LibraryBinary -> KtLibraryBinaryModuleFactory
|
||||
TestModuleKind.LibrarySource -> KtLibrarySourceModuleFactory
|
||||
TestModuleKind.ScriptSource -> KtScriptModuleFactory
|
||||
TestModuleKind.CodeFragment -> KtCodeFragmentModuleFactory
|
||||
TestModuleKind.NotUnderContentRoot -> error("Unsupported test module kind: ${TestModuleKind.NotUnderContentRoot}")
|
||||
else -> ktModuleFactory
|
||||
}
|
||||
|
||||
+3
-2
@@ -6,13 +6,14 @@
|
||||
package org.jetbrains.kotlin.analysis.test.framework.project.structure
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
import java.nio.file.Path
|
||||
|
||||
/**
|
||||
* @see org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind.ScriptSource
|
||||
* @see TestModuleKind.ScriptSource
|
||||
*/
|
||||
object KtScriptModuleFactory : KtModuleFactory {
|
||||
override fun createModule(
|
||||
@@ -30,6 +31,6 @@ object KtScriptModuleFactory : KtModuleFactory {
|
||||
project,
|
||||
)
|
||||
|
||||
return KtTestModule(testModule, module, listOf(ktFile))
|
||||
return KtTestModule(TestModuleKind.ScriptSource, testModule, module, listOf(ktFile))
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -7,12 +7,13 @@ package org.jetbrains.kotlin.analysis.test.framework.project.structure
|
||||
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.psi.search.GlobalSearchScope
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
import java.nio.file.Path
|
||||
|
||||
/**
|
||||
* @see org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind.Source
|
||||
* @see TestModuleKind.Source
|
||||
*/
|
||||
object KtSourceModuleFactory : KtModuleFactory {
|
||||
override fun createModule(
|
||||
@@ -32,6 +33,6 @@ object KtSourceModuleFactory : KtModuleFactory {
|
||||
GlobalSearchScope.filesScope(project, psiFiles.mapTo(mutableSetOf()) { it.virtualFile }),
|
||||
)
|
||||
|
||||
return KtTestModule(testModule, module, psiFiles)
|
||||
return KtTestModule(TestModuleKind.Source, testModule, module, psiFiles)
|
||||
}
|
||||
}
|
||||
|
||||
+2
@@ -11,6 +11,7 @@ import com.intellij.psi.PsiJavaFile
|
||||
import org.jetbrains.kotlin.analysis.api.standalone.base.project.structure.StandaloneProjectFactory.findJvmRootsForJavaFiles
|
||||
import org.jetbrains.kotlin.analysis.project.structure.KtBinaryModule
|
||||
import org.jetbrains.kotlin.analysis.project.structure.KtModule
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import kotlin.collections.addAll
|
||||
import kotlin.collections.filterIsInstance
|
||||
@@ -22,6 +23,7 @@ import kotlin.collections.mapTo
|
||||
* the module structure configured by Analysis API tests.
|
||||
*/
|
||||
class KtTestModule(
|
||||
val moduleKind: TestModuleKind,
|
||||
val testModule: TestModule,
|
||||
val ktModule: KtModule,
|
||||
val files: List<PsiFile>,
|
||||
|
||||
+4
-2
@@ -7,7 +7,7 @@ package org.jetbrains.kotlin.analysis.test.framework.services
|
||||
|
||||
import org.jetbrains.kotlin.analysis.test.framework.AnalysisApiTestDirectives
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.moduleKind
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.explicitTestModuleKind
|
||||
import org.jetbrains.kotlin.test.TestInfrastructureInternals
|
||||
import org.jetbrains.kotlin.test.model.DependencyDescription
|
||||
import org.jetbrains.kotlin.test.model.DependencyKind
|
||||
@@ -46,7 +46,7 @@ object DependencyKindModuleStructureTransformer : ModuleStructureTransformer() {
|
||||
moduleMapping: Map<String, TestModule>,
|
||||
): DependencyDescription {
|
||||
val dependencyModule = moduleMapping.getValue(dependency.moduleName)
|
||||
val newKind = when (dependencyModule.moduleKind) {
|
||||
val newKind = when (dependencyModule.explicitTestModuleKind) {
|
||||
TestModuleKind.Source,
|
||||
TestModuleKind.LibrarySource,
|
||||
TestModuleKind.ScriptSource,
|
||||
@@ -58,6 +58,8 @@ object DependencyKindModuleStructureTransformer : ModuleStructureTransformer() {
|
||||
DependencyKind.Binary
|
||||
}
|
||||
|
||||
TestModuleKind.NotUnderContentRoot -> error("A not-under-content-root module cannot be a dependency.")
|
||||
|
||||
null -> {
|
||||
// There is no explicit module kind, so the dependency already has the right kind
|
||||
return dependency
|
||||
|
||||
+7
-2
@@ -42,8 +42,13 @@ enum class TestModuleKind(val suffix: String) {
|
||||
/**
|
||||
* @see org.jetbrains.kotlin.analysis.test.framework.project.structure.KtCodeFragmentModuleFactory
|
||||
*/
|
||||
CodeFragment("CodeFragment")
|
||||
CodeFragment("CodeFragment"),
|
||||
|
||||
/**
|
||||
* This is currently only used in LL FIR tests and not supported by a test framework module factory.
|
||||
*/
|
||||
NotUnderContentRoot("NotUnderContentRoot"),
|
||||
}
|
||||
|
||||
val TestModule.moduleKind: TestModuleKind?
|
||||
val TestModule.explicitTestModuleKind: TestModuleKind?
|
||||
get() = directives.singleOrZeroValue(AnalysisApiTestDirectives.MODULE_KIND)
|
||||
|
||||
+12
-4
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.analysis.test.framework.services.configuration.Analy
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiTestConfigurator
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.AnalysisApiTestServiceRegistrar
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.FrontendKind
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
|
||||
import org.jetbrains.kotlin.test.services.TestModuleStructure
|
||||
@@ -52,13 +53,20 @@ object FirLowLevelCompilerBasedTestConfigurator : AnalysisApiTestConfigurator()
|
||||
val mainModules = moduleStructure.modules.map { testModule ->
|
||||
val files = TestModuleStructureFactory.createSourcePsiFiles(testModule, testServices, project)
|
||||
val scriptFile = files.singleOrNull() as? KtFile
|
||||
val ktModule = if (scriptFile?.isScript() == true) {
|
||||
KtScriptModuleByCompilerConfiguration(project, testModule, scriptFile, testServices)
|
||||
|
||||
val (ktModule, testModuleKind) = if (scriptFile?.isScript() == true) {
|
||||
Pair(
|
||||
KtScriptModuleByCompilerConfiguration(project, testModule, scriptFile, testServices),
|
||||
TestModuleKind.ScriptSource,
|
||||
)
|
||||
} else {
|
||||
KtSourceModuleByCompilerConfiguration(project, testModule, files, testServices)
|
||||
Pair(
|
||||
KtSourceModuleByCompilerConfiguration(project, testModule, files, testServices),
|
||||
TestModuleKind.Source,
|
||||
)
|
||||
}
|
||||
|
||||
KtTestModule(testModule, ktModule, files)
|
||||
KtTestModule(testModuleKind, testModule, ktModule, files)
|
||||
}
|
||||
|
||||
return KtTestModuleProjectStructure(
|
||||
|
||||
+2
-1
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.analysis.test.framework.project.structure.KtModuleFa
|
||||
import org.jetbrains.kotlin.analysis.test.framework.project.structure.KtTestModuleProjectStructure
|
||||
import org.jetbrains.kotlin.analysis.test.framework.project.structure.KtTestModule
|
||||
import org.jetbrains.kotlin.analysis.test.framework.project.structure.TestModuleStructureFactory
|
||||
import org.jetbrains.kotlin.analysis.test.framework.test.configurators.TestModuleKind
|
||||
import org.jetbrains.kotlin.analysis.test.framework.utils.SkipTestException
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.resolve.PlatformDependentAnalyzerServices
|
||||
@@ -74,7 +75,7 @@ private object KtOutOfContentRootModuleFactory : KtModuleFactory {
|
||||
val psiFiles = TestModuleStructureFactory.createSourcePsiFiles(testModule, testServices, project)
|
||||
val platform = testModule.targetPlatform
|
||||
val ktModule = KtNotUnderContentRootModuleForTest(testModule.name, psiFiles.first(), platform)
|
||||
return KtTestModule(testModule, ktModule, psiFiles)
|
||||
return KtTestModule(TestModuleKind.NotUnderContentRoot, testModule, ktModule, psiFiles)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user