mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[kotlin] test framework to set up light multiplatform tests in one file
changes after review KTIJ-28551 GitOrigin-RevId: 8035d2e8a98c46c47cb5121d0902147e052ebbe5
This commit is contained in:
committed by
intellij-monorepo-bot
parent
17f7f5c7c2
commit
01711f3ea2
+6
-3
@@ -23,7 +23,7 @@ object ModuleStructureSplitter {
|
||||
var isMainFile = false
|
||||
|
||||
fun dumpFile(currentPlatform: String?, currentFileName: String?, currentText: String?) {
|
||||
if (currentText != null && currentFileName != null && currentPlatform != null) {
|
||||
if (!currentText.isNullOrEmpty() && currentFileName != null && currentPlatform != null) {
|
||||
result.getOrPut(currentPlatform) { mutableListOf() }.add(TestFile(currentFileName, currentText, isMainFile))
|
||||
}
|
||||
}
|
||||
@@ -31,10 +31,13 @@ object ModuleStructureSplitter {
|
||||
lines.forEach { line ->
|
||||
if (line == IS_MAIN) {
|
||||
isMainFile = true
|
||||
} else if (line.startsWith(PLATFORM_PREFIX)) {
|
||||
} else if (line.startsWith(PLATFORM_PREFIX, true)) {
|
||||
dumpFile(currentPlatform, currentFileName, currentText)
|
||||
currentPlatform = line.substringAfter(PLATFORM_PREFIX).trim()
|
||||
currentText = ""
|
||||
currentFileName = null
|
||||
currentPlatform = line.substring(PLATFORM_PREFIX.length).trim()
|
||||
} else if (line.startsWith(FILE_PATH_PREFIX)) {
|
||||
dumpFile(currentPlatform, currentFileName, currentText)
|
||||
isMainFile = false
|
||||
currentFileName = line.substringAfter(FILE_PATH_PREFIX).trim()
|
||||
currentText = ""
|
||||
|
||||
+5
@@ -28,6 +28,11 @@ public class FirQuickDocMultiplatformTestGenerated extends AbstractFirQuickDocMu
|
||||
runTest("../../idea/tests/testData/editor/quickDoc/multiplatform/OnActualClassWithConstructorFromExpect.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("OnActualDeclarationWithDocWhenInheritedDocPresent.kt")
|
||||
public void testOnActualDeclarationWithDocWhenInheritedDocPresent() throws Exception {
|
||||
runTest("../../idea/tests/testData/editor/quickDoc/multiplatform/OnActualDeclarationWithDocWhenInheritedDocPresent.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("OnActualDeclarationWithInheritedDoc.kt")
|
||||
public void testOnActualDeclarationWithInheritedDoc() throws Exception {
|
||||
runTest("../../idea/tests/testData/editor/quickDoc/multiplatform/OnActualDeclarationWithInheritedDoc.kt");
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
// PLATFORM: Common
|
||||
// FILE: Foo.kt
|
||||
/**
|
||||
* Doc for expected class Foo
|
||||
*/
|
||||
expect class Foo
|
||||
|
||||
// PLATFORM: Jvm
|
||||
// FILE: Foo.kt
|
||||
// MAIN
|
||||
/**
|
||||
* Doc for actual class Foo
|
||||
*/
|
||||
actual class F<caret>oo
|
||||
|
||||
//INFO: <div class='definition'><pre><span style="color:#000080;font-weight:bold;">public</span> <span style="color:#000080;font-weight:bold;">actual</span> <span style="color:#000080;font-weight:bold;">final</span> <span style="color:#000080;font-weight:bold;">class</span> <span style="color:#000000;">Foo</span></pre></div><div class='content'><p style='margin-top:0;padding-top:0;'>Doc for actual class Foo</p></div><table class='sections'></table><div class='bottom'><icon src="/org/jetbrains/kotlin/idea/icons/kotlin_file.svg"/> Foo.kt<br/></div>
|
||||
+3
-10
@@ -11,8 +11,6 @@ import java.io.File
|
||||
|
||||
abstract class KotlinLightMultiplatformCodeInsightFixtureTestCase : KotlinLightCodeInsightFixtureTestCaseBase() {
|
||||
|
||||
private val exceptions = ArrayList<Throwable>()
|
||||
|
||||
@Deprecated("Migrate to 'testDataDirectory'.", ReplaceWith("testDataDirectory"))
|
||||
final override fun getTestDataPath(): String = testDataDirectory.slashedPath
|
||||
|
||||
@@ -37,7 +35,7 @@ abstract class KotlinLightMultiplatformCodeInsightFixtureTestCase : KotlinLightC
|
||||
*/
|
||||
fun configureModuleStructure(abstractFilePath: String): VirtualFile? {
|
||||
val map = ModuleStructureSplitter.splitPerModule(File(abstractFilePath))
|
||||
var currentFile: VirtualFile? = null
|
||||
var mainFile: VirtualFile? = null
|
||||
map.forEach { (platform, files) ->
|
||||
val platformDescriptor = when (platform) {
|
||||
"Common" -> KotlinMultiPlatformProjectDescriptor.PlatformDescriptor.COMMON
|
||||
@@ -49,13 +47,13 @@ abstract class KotlinLightMultiplatformCodeInsightFixtureTestCase : KotlinLightC
|
||||
for (testFile in files) {
|
||||
val virtualFile = VfsTestUtil.createFile(platformDescriptor.sourceRoot()!!, testFile.relativePath, testFile.text)
|
||||
if (testFile.isMain) {
|
||||
currentFile = virtualFile
|
||||
mainFile = virtualFile
|
||||
}
|
||||
myFixture.configureFromExistingVirtualFile(virtualFile)
|
||||
}
|
||||
}
|
||||
}
|
||||
return currentFile
|
||||
return mainFile
|
||||
}
|
||||
|
||||
override fun tearDown() {
|
||||
@@ -64,11 +62,6 @@ abstract class KotlinLightMultiplatformCodeInsightFixtureTestCase : KotlinLightC
|
||||
{ KotlinSdkType.removeKotlinSdkInTests() },
|
||||
{ super.tearDown() },
|
||||
)
|
||||
|
||||
if (exceptions.isNotEmpty()) {
|
||||
exceptions.forEach { it.printStackTrace() }
|
||||
throw AssertionError("Exceptions in other threads happened")
|
||||
}
|
||||
}
|
||||
|
||||
override fun getProjectDescriptor(): LightProjectDescriptor = KotlinMultiPlatformProjectDescriptor
|
||||
|
||||
+18
-3
@@ -1,9 +1,11 @@
|
||||
// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package org.jetbrains.kotlin.idea.test
|
||||
|
||||
import com.intellij.openapi.application.runReadAction
|
||||
import com.intellij.openapi.application.runWriteAction
|
||||
import com.intellij.openapi.module.Module
|
||||
import com.intellij.openapi.project.Project
|
||||
import com.intellij.openapi.projectRoots.ProjectJdkTable
|
||||
import com.intellij.openapi.projectRoots.Sdk
|
||||
import com.intellij.openapi.roots.*
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
@@ -13,6 +15,7 @@ import com.intellij.pom.java.LanguageLevel
|
||||
import com.intellij.testFramework.IdeaTestUtil
|
||||
import com.intellij.testFramework.IndexingTestUtil
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootType
|
||||
import org.jetbrains.kotlin.idea.framework.KotlinSdkType
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
import org.jetbrains.kotlin.platform.js.JsPlatforms
|
||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
||||
@@ -65,21 +68,32 @@ object KotlinMultiPlatformProjectDescriptor : KotlinLightProjectDescriptor() {
|
||||
|
||||
private fun configureModule(module: Module, model: ModifiableRootModel, descriptor: PlatformDescriptor) {
|
||||
model.getModuleExtension(LanguageLevelModuleExtension::class.java).languageLevel = LanguageLevel.HIGHEST
|
||||
model.sdk = sdk
|
||||
if (descriptor.sourceRootName != null) {
|
||||
val sourceRoot = createSourceRoot(module, descriptor.sourceRootName)
|
||||
model.addContentEntry(sourceRoot).addSourceFolder(sourceRoot, JavaSourceRootType.SOURCE)
|
||||
}
|
||||
|
||||
val setupKotlinSdk: () -> Unit = {
|
||||
KotlinSdkType.setUpIfNeeded(module)
|
||||
ConfigLibraryUtil.configureSdk(
|
||||
module,
|
||||
runReadAction { ProjectJdkTable.getInstance() }.findMostRecentSdkOfType(KotlinSdkType.INSTANCE)
|
||||
?: error("Kotlin SDK wasn't created")
|
||||
)
|
||||
}
|
||||
when (descriptor) {
|
||||
PlatformDescriptor.JVM -> {
|
||||
model.sdk = sdk
|
||||
module.createMultiplatformFacetM3(JvmPlatforms.jvm8, false, listOf("Common"), listOf(descriptor.sourceRoot()!!.path))
|
||||
}
|
||||
|
||||
PlatformDescriptor.JS ->
|
||||
PlatformDescriptor.JS -> {
|
||||
setupKotlinSdk()
|
||||
module.createMultiplatformFacetM3(JsPlatforms.defaultJsPlatform, false, listOf("Common"), listOf(descriptor.sourceRoot()!!.path))
|
||||
}
|
||||
|
||||
PlatformDescriptor.COMMON ->
|
||||
PlatformDescriptor.COMMON -> {
|
||||
setupKotlinSdk()
|
||||
module.createMultiplatformFacetM3(
|
||||
TargetPlatform(
|
||||
setOf(
|
||||
@@ -88,6 +102,7 @@ object KotlinMultiPlatformProjectDescriptor : KotlinLightProjectDescriptor() {
|
||||
)
|
||||
), false, emptyList(), listOf(descriptor.sourceRoot()!!.path)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user