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.openapi.vfs.LocalFileSystem
|
||||||
import com.intellij.testFramework.PlatformTestCase
|
import com.intellij.testFramework.PlatformTestCase
|
||||||
import junit.framework.TestCase
|
import junit.framework.TestCase
|
||||||
|
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
|
||||||
import org.jetbrains.kotlin.config.JvmTarget
|
import org.jetbrains.kotlin.config.JvmTarget
|
||||||
import org.jetbrains.kotlin.config.TargetPlatformKind
|
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.AbstractMultiModuleTest
|
||||||
import org.jetbrains.kotlin.idea.stubs.createFacet
|
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
|
import java.io.File
|
||||||
|
|
||||||
// allows to configure a test mpp project
|
// allows to configure a test mpp project
|
||||||
@@ -34,7 +40,21 @@ fun AbstractMultiModuleTest.setupMppProjectFromDirStructure(testRoot: File) {
|
|||||||
infosByModuleId.entries.forEach { (id, rootInfos) ->
|
infosByModuleId.entries.forEach { (id, rootInfos) ->
|
||||||
val module = modulesById[id]!!
|
val module = modulesById[id]!!
|
||||||
rootInfos.flatMap { it.dependencies }.forEach {
|
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)
|
TestCase.assertNotNull(root)
|
||||||
object : WriteCommandAction.Simple<Unit>(module.project) {
|
object : WriteCommandAction.Simple<Unit>(module.project) {
|
||||||
@Throws(Throwable::class)
|
@Throws(Throwable::class)
|
||||||
protected override fun run() {
|
override fun run() {
|
||||||
root!!.refresh(false, true)
|
root!!.refresh(false, true)
|
||||||
}
|
}
|
||||||
}.execute().throwException()
|
}.execute().throwException()
|
||||||
@@ -97,9 +117,11 @@ private fun AbstractMultiModuleTest.createModule(name: String): Module {
|
|||||||
|
|
||||||
private val testSuffixes = setOf("test", "tests")
|
private val testSuffixes = setOf("test", "tests")
|
||||||
private val platformNames = mapOf(
|
private val platformNames = mapOf(
|
||||||
TargetPlatformKind.Common to listOf("header", "common", "expect"),
|
listOf("header", "common", "expect") to TargetPlatformKind.Common,
|
||||||
TargetPlatformKind.Jvm[JvmTarget.DEFAULT] to listOf("java", "jvm"),
|
listOf("java", "jvm") to TargetPlatformKind.Jvm[JvmTarget.DEFAULT],
|
||||||
TargetPlatformKind.JavaScript to listOf("js", "javascript")
|
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 {
|
private fun parseDirName(dir: File): RootInfo {
|
||||||
@@ -109,20 +131,29 @@ private fun parseDirName(dir: File): RootInfo {
|
|||||||
|
|
||||||
private fun parseDependencies(parts: List<String>) =
|
private fun parseDependencies(parts: List<String>) =
|
||||||
parts.filter { it.startsWith("dep(") && it.endsWith(")") }.map {
|
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 {
|
private fun parseModuleId(parts: List<String>): ModuleId {
|
||||||
val platform = parsePlatform(parts).key
|
val platform = parsePlatform(parts)
|
||||||
val name = parseModuleName(parts)
|
val name = parseModuleName(parts)
|
||||||
val moduleId = ModuleId(name, platform)
|
return ModuleId(name, platform)
|
||||||
return moduleId
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun parsePlatform(parts: List<String>) =
|
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) } }
|
names.any { name -> parts.any { part -> part.equals(name, ignoreCase = true) } }
|
||||||
}
|
}.value
|
||||||
|
|
||||||
private fun parseModuleName(parts: List<String>) = when {
|
private fun parseModuleName(parts: List<String>) = when {
|
||||||
parts.size > 1 -> parts.first()
|
parts.size > 1 -> parts.first()
|
||||||
@@ -150,5 +181,10 @@ private data class RootInfo(
|
|||||||
val moduleId: ModuleId,
|
val moduleId: ModuleId,
|
||||||
val isTestRoot: Boolean,
|
val isTestRoot: Boolean,
|
||||||
val moduleRoot: File,
|
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
|
exported: Boolean = false
|
||||||
): Module = this.apply { ModuleRootModificationUtil.addDependency(this, other, dependencyScope, exported) }
|
): Module = this.apply { ModuleRootModificationUtil.addDependency(this, other, dependencyScope, exported) }
|
||||||
|
|
||||||
protected fun Module.addLibrary(jar: File,
|
fun Module.addLibrary(
|
||||||
name: String = KotlinJdkAndLibraryProjectDescriptor.LIBRARY_NAME,
|
jar: File,
|
||||||
kind: PersistentLibraryKind<*>? = null) {
|
name: String = KotlinJdkAndLibraryProjectDescriptor.LIBRARY_NAME,
|
||||||
|
kind: PersistentLibraryKind<*>? = null
|
||||||
|
) {
|
||||||
ConfigLibraryUtil.addLibrary(NewLibraryEditor().apply {
|
ConfigLibraryUtil.addLibrary(NewLibraryEditor().apply {
|
||||||
this.name = name
|
this.name = name
|
||||||
addRoot(VfsUtil.getUrlForLibraryRoot(jar), OrderRootType.CLASSES)
|
addRoot(VfsUtil.getUrlForLibraryRoot(jar), OrderRootType.CLASSES)
|
||||||
|
|||||||
Reference in New Issue
Block a user