Refactoring: merge doTest in AbstractMultiModuleHighlightingTest

This commit is contained in:
Mikhail Glukhikh
2017-04-18 12:28:44 +03:00
parent 266d36f289
commit 99653b9afc
4 changed files with 43 additions and 62 deletions
@@ -16,6 +16,9 @@
package org.jetbrains.kotlin.idea.caches.resolve
import com.intellij.openapi.module.Module
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
import org.jetbrains.kotlin.config.TargetPlatformKind
import org.jetbrains.kotlin.idea.project.PluginJetFilesProvider
import org.jetbrains.kotlin.idea.stubs.AbstractMultiHighlightingTest
import org.jetbrains.kotlin.idea.test.PluginTestCaseBase
@@ -25,6 +28,34 @@ abstract class AbstractMultiModuleHighlightingTest : AbstractMultiHighlightingTe
override val testPath = PluginTestCaseBase.getTestDataPathBase() + "/multiModuleHighlighting/"
protected fun doMultiPlatformTest(
vararg platforms: TargetPlatformKind<*>,
withStdlibCommon: Boolean = false,
configureModule: (Module, TargetPlatformKind<*>) -> Unit = { _, _ -> },
useFullJdk: Boolean = false
) {
val commonModule = module("common", useFullJdk = useFullJdk)
commonModule.createFacet(TargetPlatformKind.Common)
if (withStdlibCommon) {
commonModule.addLibrary(ForTestCompileRuntime.stdlibCommonForTests())
}
for (platform in platforms) {
val path = when (platform) {
is TargetPlatformKind.Jvm -> "jvm"
is TargetPlatformKind.JavaScript -> "js"
else -> error("Unsupported platform: $platform")
}
val platformModule = module(path, useFullJdk = useFullJdk)
platformModule.createFacet(platform)
platformModule.enableMultiPlatform()
platformModule.addDependency(commonModule)
configureModule(platformModule, platform)
}
checkHighlightingInAllFiles()
}
protected fun checkHighlightingInAllFiles() {
var atLeastOneFile = false
PluginJetFilesProvider.allFilesInProject(myProject!!).forEach { file ->
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.idea.caches.resolve
import com.intellij.openapi.module.Module
import com.intellij.openapi.roots.DependencyScope
import org.jetbrains.kotlin.codegen.forTestCompile.ForTestCompileRuntime
import org.jetbrains.kotlin.config.JvmTarget
@@ -66,65 +65,37 @@ class MultiModuleHighlightingTest : AbstractMultiModuleHighlightingTest() {
class MultiPlatform : AbstractMultiModuleHighlightingTest() {
override val testPath get() = super.testPath + "multiplatform/"
private fun doTest(
vararg platforms: TargetPlatformKind<*>,
withStdlibCommon: Boolean = false,
configureModule: (Module, TargetPlatformKind<*>) -> Unit = { _, _ -> },
useFullJdk: Boolean = false
) {
val commonModule = module("common", useFullJdk = useFullJdk)
commonModule.createFacet(TargetPlatformKind.Common)
if (withStdlibCommon) {
commonModule.addLibrary(ForTestCompileRuntime.stdlibCommonForTests())
}
for (platform in platforms) {
val path = when (platform) {
is TargetPlatformKind.Jvm -> "jvm"
is TargetPlatformKind.JavaScript -> "js"
else -> error("Unsupported platform: $platform")
}
val platformModule = module(path, useFullJdk = useFullJdk)
platformModule.createFacet(platform)
platformModule.enableMultiPlatform()
platformModule.addDependency(commonModule)
configureModule(platformModule, platform)
}
checkHighlightingInAllFiles()
}
fun testBasic() {
doTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6])
doMultiPlatformTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6])
}
fun testHeaderClass() {
doTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6])
doMultiPlatformTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6])
}
fun testHeaderWithoutImplForBoth() {
doTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], TargetPlatformKind.JavaScript)
doMultiPlatformTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], TargetPlatformKind.JavaScript)
}
fun testHeaderPartiallyImplemented() {
doTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6])
doMultiPlatformTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6])
}
fun testHeaderFunctionProperty() {
doTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6])
doMultiPlatformTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6])
}
fun testSuppressHeaderWithoutImpl() {
doTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6])
doMultiPlatformTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6])
}
fun testCatchHeaderExceptionInPlatformModule() {
doTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], withStdlibCommon = true)
doMultiPlatformTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6], withStdlibCommon = true)
}
fun testUseCorrectBuiltInsForCommonModule() {
doTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], TargetPlatformKind.JavaScript,
withStdlibCommon = true, useFullJdk = true, configureModule = { module, platform ->
doMultiPlatformTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_8], TargetPlatformKind.JavaScript,
withStdlibCommon = true, useFullJdk = true, configureModule = { module, platform ->
if (platform == TargetPlatformKind.JavaScript) {
module.addLibrary(ForTestCompileRuntime.stdlibJsForTests())
module.addLibrary(ForTestCompileRuntime.stdlibCommonForTests())
@@ -21,34 +21,15 @@ import org.jetbrains.kotlin.config.TargetPlatformKind
class MultiModuleLineMarkerTest : AbstractMultiModuleLineMarkerTest() {
private fun doTest(vararg platforms: TargetPlatformKind<*>) {
val commonModule = module("common")
commonModule.createFacet(TargetPlatformKind.Common)
for (platform in platforms) {
val path = when (platform) {
is TargetPlatformKind.Jvm -> "jvm"
is TargetPlatformKind.JavaScript -> "js"
else -> error("Unsupported platform: $platform")
}
val platformModule = module(path)
platformModule.createFacet(platform)
platformModule.enableMultiPlatform()
platformModule.addDependency(commonModule)
}
checkHighlightingInAllFiles()
}
fun testFromCommonToJvmHeader() {
doTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6])
doMultiPlatformTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6])
}
fun testFromCommonToJvmImpl() {
doTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6])
doMultiPlatformTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6])
}
fun testFromClassToAlias() {
doTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6])
doMultiPlatformTest(TargetPlatformKind.Jvm[JvmTarget.JVM_1_6])
}
}
@@ -16,8 +16,6 @@
package org.jetbrains.kotlin.idea.stubs
import com.intellij.codeInsight.completion.CompletionTestCase
import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl
import com.intellij.codeInsight.daemon.impl.HighlightInfo
import com.intellij.openapi.application.ApplicationManager