Mpp test utils: allow to setup dependencies on stdlib and fulljdk
Allow to specify jjvm8 as platform
This commit is contained in:
@@ -13,10 +13,16 @@ import com.intellij.openapi.roots.ModuleRootModificationUtil
|
||||
import com.intellij.openapi.vfs.LocalFileSystem
|
||||
import com.intellij.testFramework.PlatformTestCase
|
||||
import junit.framework.TestCase
|
||||
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||
import org.jetbrains.kotlin.config.JvmTarget
|
||||
import org.jetbrains.kotlin.config.TargetPlatformKind
|
||||
import org.jetbrains.kotlin.idea.framework.CommonLibraryKind
|
||||
import org.jetbrains.kotlin.idea.framework.JSLibraryKind
|
||||
import org.jetbrains.kotlin.idea.stubs.AbstractMultiModuleTest
|
||||
import org.jetbrains.kotlin.idea.stubs.createFacet
|
||||
import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil
|
||||
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
|
||||
import org.jetbrains.kotlin.test.TestJdkKind
|
||||
import java.io.File
|
||||
|
||||
// allows to configure a test mpp project
|
||||
@@ -34,7 +40,21 @@ fun AbstractMultiModuleTest.setupMppProjectFromDirStructure(testRoot: File) {
|
||||
infosByModuleId.entries.forEach { (id, rootInfos) ->
|
||||
val module = modulesById[id]!!
|
||||
rootInfos.flatMap { it.dependencies }.forEach {
|
||||
module.addDependency(modulesById[it]!!)
|
||||
when (it) {
|
||||
is ModuleDependency -> module.addDependency(modulesById[it.moduleId]!!)
|
||||
is StdlibDependency -> when (id.platform) {
|
||||
is TargetPlatformKind.Common -> module.addLibrary(
|
||||
ForTestCompileRuntime.stdlibCommonForTests(), kind = CommonLibraryKind
|
||||
)
|
||||
is TargetPlatformKind.Jvm -> module.addLibrary(ForTestCompileRuntime.runtimeJarForTests())
|
||||
is TargetPlatformKind.JavaScript -> module.addLibrary(ForTestCompileRuntime.stdlibJsForTests(), kind = JSLibraryKind)
|
||||
}
|
||||
is FullJdkDependency -> {
|
||||
ConfigLibraryUtil.configureSdk(module, PluginTestCaseBase.addJdk(testRootDisposable) {
|
||||
PluginTestCaseBase.jdk(TestJdkKind.FULL_JDK)
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,7 +108,7 @@ private fun AbstractMultiModuleTest.createModule(name: String): Module {
|
||||
TestCase.assertNotNull(root)
|
||||
object : WriteCommandAction.Simple<Unit>(module.project) {
|
||||
@Throws(Throwable::class)
|
||||
protected override fun run() {
|
||||
override fun run() {
|
||||
root!!.refresh(false, true)
|
||||
}
|
||||
}.execute().throwException()
|
||||
@@ -97,9 +117,11 @@ private fun AbstractMultiModuleTest.createModule(name: String): Module {
|
||||
|
||||
private val testSuffixes = setOf("test", "tests")
|
||||
private val platformNames = mapOf(
|
||||
TargetPlatformKind.Common to listOf("header", "common", "expect"),
|
||||
TargetPlatformKind.Jvm[JvmTarget.DEFAULT] to listOf("java", "jvm"),
|
||||
TargetPlatformKind.JavaScript to listOf("js", "javascript")
|
||||
listOf("header", "common", "expect") to TargetPlatformKind.Common,
|
||||
listOf("java", "jvm") to TargetPlatformKind.Jvm[JvmTarget.DEFAULT],
|
||||
listOf("java8", "jvm8") to TargetPlatformKind.Jvm[JvmTarget.JVM_1_8],
|
||||
listOf("java6", "jvm6") to TargetPlatformKind.Jvm[JvmTarget.JVM_1_6],
|
||||
listOf("js", "javascript") to TargetPlatformKind.JavaScript
|
||||
)
|
||||
|
||||
private fun parseDirName(dir: File): RootInfo {
|
||||
@@ -109,20 +131,29 @@ private fun parseDirName(dir: File): RootInfo {
|
||||
|
||||
private fun parseDependencies(parts: List<String>) =
|
||||
parts.filter { it.startsWith("dep(") && it.endsWith(")") }.map {
|
||||
parseModuleId(it.removePrefix("dep(").removeSuffix(")").split("-"))
|
||||
parseDependency(it)
|
||||
}
|
||||
|
||||
private fun parseDependency(it: String): Dependency {
|
||||
val dependencyString = it.removePrefix("dep(").removeSuffix(")")
|
||||
|
||||
return when {
|
||||
dependencyString.equals("stdlib", ignoreCase = true) -> StdlibDependency
|
||||
dependencyString.equals("fulljdk", ignoreCase = true) -> FullJdkDependency
|
||||
else -> ModuleDependency(parseModuleId(dependencyString.split("-")))
|
||||
}
|
||||
}
|
||||
|
||||
private fun parseModuleId(parts: List<String>): ModuleId {
|
||||
val platform = parsePlatform(parts).key
|
||||
val platform = parsePlatform(parts)
|
||||
val name = parseModuleName(parts)
|
||||
val moduleId = ModuleId(name, platform)
|
||||
return moduleId
|
||||
return ModuleId(name, platform)
|
||||
}
|
||||
|
||||
private fun parsePlatform(parts: List<String>) =
|
||||
platformNames.entries.single { (_, names) ->
|
||||
platformNames.entries.single { (names, _) ->
|
||||
names.any { name -> parts.any { part -> part.equals(name, ignoreCase = true) } }
|
||||
}
|
||||
}.value
|
||||
|
||||
private fun parseModuleName(parts: List<String>) = when {
|
||||
parts.size > 1 -> parts.first()
|
||||
@@ -150,5 +181,10 @@ private data class RootInfo(
|
||||
val moduleId: ModuleId,
|
||||
val isTestRoot: Boolean,
|
||||
val moduleRoot: File,
|
||||
val dependencies: List<ModuleId>
|
||||
)
|
||||
val dependencies: List<Dependency>
|
||||
)
|
||||
|
||||
private sealed class Dependency
|
||||
private class ModuleDependency(val moduleId: ModuleId) : Dependency()
|
||||
private object StdlibDependency : Dependency()
|
||||
private object FullJdkDependency : Dependency()
|
||||
@@ -83,9 +83,11 @@ abstract class AbstractMultiModuleTest : DaemonAnalyzerTestCase() {
|
||||
exported: Boolean = false
|
||||
): Module = this.apply { ModuleRootModificationUtil.addDependency(this, other, dependencyScope, exported) }
|
||||
|
||||
protected fun Module.addLibrary(jar: File,
|
||||
name: String = KotlinJdkAndLibraryProjectDescriptor.LIBRARY_NAME,
|
||||
kind: PersistentLibraryKind<*>? = null) {
|
||||
fun Module.addLibrary(
|
||||
jar: File,
|
||||
name: String = KotlinJdkAndLibraryProjectDescriptor.LIBRARY_NAME,
|
||||
kind: PersistentLibraryKind<*>? = null
|
||||
) {
|
||||
ConfigLibraryUtil.addLibrary(NewLibraryEditor().apply {
|
||||
this.name = name
|
||||
addRoot(VfsUtil.getUrlForLibraryRoot(jar), OrderRootType.CLASSES)
|
||||
|
||||
Reference in New Issue
Block a user