mirror of
https://gitflic.ru/project/openide/openide.git
synced 2025-12-15 02:59:33 +07:00
[Kotlin] Add a standard library dependency to KMP test descriptor
KTIJ-29725 GitOrigin-RevId: d0bf3401f437a3a8740cd4cd00bd6b039c58f451
This commit is contained in:
committed by
intellij-monorepo-bot
parent
35f71e23fe
commit
1f8598525c
@@ -4,7 +4,6 @@ package org.jetbrains.kotlin.idea.fir.documentation
|
||||
import com.intellij.lang.documentation.ide.IdeDocumentationTargetProvider
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.openapi.vfs.VfsUtilCore
|
||||
import com.intellij.platform.backend.documentation.impl.computeDocumentationBlocking
|
||||
import com.intellij.platform.testFramework.core.FileComparisonFailedError
|
||||
import org.jetbrains.kotlin.idea.base.test.InTextDirectivesUtils
|
||||
@@ -23,7 +22,7 @@ abstract class AbstractFirQuickDocMultiplatformTest: KotlinLightMultiplatformCod
|
||||
}
|
||||
|
||||
fun doTest(path: String) {
|
||||
val virtualFile = configureModuleStructure(path)
|
||||
val virtualFile = configureModuleStructure(path).second
|
||||
require(virtualFile != null)
|
||||
|
||||
myFixture.configureFromExistingVirtualFile(virtualFile)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
// 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.fir.kmp
|
||||
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightMultiplatformCodeInsightFixtureTestCase
|
||||
|
||||
abstract class AbstractK2KmpLightFixtureHighlightingTest : KotlinLightMultiplatformCodeInsightFixtureTestCase() {
|
||||
override fun isFirPlugin(): Boolean = true
|
||||
|
||||
fun doTest(path: String) {
|
||||
val allFiles = configureModuleStructure(path).first
|
||||
myFixture.testHighlightingAllFiles(true, false, false, *allFiles.toTypedArray())
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
// 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.fir.kmp;
|
||||
|
||||
import com.intellij.testFramework.TestDataPath;
|
||||
import org.jetbrains.kotlin.idea.test.JUnit3RunnerWithInners;
|
||||
import org.jetbrains.kotlin.idea.test.KotlinTestUtils;
|
||||
import org.jetbrains.kotlin.test.TestMetadata;
|
||||
import org.jetbrains.kotlin.idea.base.test.TestRoot;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
/**
|
||||
* This class is generated by {@link org.jetbrains.kotlin.testGenerator.generator.TestGenerator}.
|
||||
* DO NOT MODIFY MANUALLY.
|
||||
*/
|
||||
@SuppressWarnings("all")
|
||||
@TestRoot("fir/tests")
|
||||
@TestDataPath("$CONTENT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
@TestMetadata("testData/kmp/highlighting")
|
||||
public class K2KmpLightFixtureHighlightingTestGenerated extends AbstractK2KmpLightFixtureHighlightingTest {
|
||||
private void runTest(String testDataFilePath) throws Exception {
|
||||
KotlinTestUtils.runTest(this::doTest, this, testDataFilePath);
|
||||
}
|
||||
|
||||
@TestMetadata("collectionBuilders.kt")
|
||||
public void testCollectionBuilders() throws Exception {
|
||||
runTest("testData/kmp/highlighting/collectionBuilders.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("expectActualFunctions.kt")
|
||||
public void testExpectActualFunctions() throws Exception {
|
||||
runTest("testData/kmp/highlighting/expectActualFunctions.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("literals.kt")
|
||||
public void testLiterals() throws Exception {
|
||||
runTest("testData/kmp/highlighting/literals.kt");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// PLATFORM: Common
|
||||
// FILE: A.kt
|
||||
|
||||
fun commonThings() {
|
||||
val c = listOf(1, 2, 3)
|
||||
val d = sequenceOf("a", "b")
|
||||
val e = mapOf("1" to 1)
|
||||
}
|
||||
|
||||
// PLATFORM: Jvm
|
||||
// FILE: B.kt
|
||||
|
||||
fun jvmThings() {
|
||||
val c = listOf(1, 2, 3)
|
||||
val d = sequenceOf("a", "b")
|
||||
val e = sortedMapOf("1" to 1)
|
||||
}
|
||||
|
||||
// PLATFORM: Js
|
||||
// FILE: C.kt
|
||||
|
||||
fun jsThings() {
|
||||
val c = listOf(1, 2, 3)
|
||||
val d = sequenceOf("a", "b")
|
||||
val e = linkedStringMapOf("1" to 1)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// PLATFORM: Common
|
||||
// FILE: A.kt
|
||||
|
||||
expect fun foo(): String
|
||||
|
||||
fun useFoo() {
|
||||
foo()
|
||||
}
|
||||
|
||||
// PLATFORM: Jvm
|
||||
// FILE: B.kt
|
||||
|
||||
actual fun foo(): String = "JVM"
|
||||
|
||||
fun useFoo() {
|
||||
foo()
|
||||
}
|
||||
|
||||
// PLATFORM: Js
|
||||
// FILE: C.kt
|
||||
|
||||
actual fun foo(): String = "JS"
|
||||
|
||||
fun useFoo() {
|
||||
foo()
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
// PLATFORM: Common
|
||||
// FILE: A.kt
|
||||
|
||||
fun common() {
|
||||
val f: Float = 0.0f
|
||||
val d: Double = 0.0
|
||||
val b: Byte = 0
|
||||
val s: Short = 0
|
||||
val i: Int = 0
|
||||
val l: Long = 0L
|
||||
val bool: Boolean = true
|
||||
val char: Char = '~'
|
||||
val string: String = "~"
|
||||
}
|
||||
|
||||
// PLATFORM: Jvm
|
||||
// FILE: B.kt
|
||||
|
||||
fun jvm() {
|
||||
val f: Float = 0.0f
|
||||
val d: Double = 0.0
|
||||
val b: Byte = 0
|
||||
val s: Short = 0
|
||||
val i: Int = 0
|
||||
val l: Long = 0L
|
||||
val bool: Boolean = true
|
||||
val char: Char = '~'
|
||||
val string: String = "~"
|
||||
}
|
||||
|
||||
// PLATFORM: Js
|
||||
// FILE: C.kt
|
||||
|
||||
fun js() {
|
||||
val f: Float = 0.0f
|
||||
val d: Double = 0.0
|
||||
val b: Byte = 0
|
||||
val s: Short = 0
|
||||
val i: Int = 0
|
||||
val l: Long = 0L
|
||||
val bool: Boolean = true
|
||||
val char: Char = '~'
|
||||
val string: String = "~"
|
||||
}
|
||||
@@ -12,7 +12,6 @@ import com.intellij.usageView.UsageViewLongNameLocation
|
||||
import org.jetbrains.kotlin.idea.test.KotlinLightMultiplatformCodeInsightFixtureTestCase
|
||||
import org.jetbrains.kotlin.idea.test.KotlinTestUtils
|
||||
import org.jetbrains.kotlin.psi.KtCallableDeclaration
|
||||
import org.jetbrains.kotlin.psi.KtClass
|
||||
import org.jetbrains.kotlin.psi.KtClassOrObject
|
||||
import java.nio.file.Paths
|
||||
|
||||
@@ -20,7 +19,7 @@ abstract class AbstractKotlinDefinitionsSearcherMultiplatformTest : KotlinLightM
|
||||
override fun isFirPlugin(): Boolean = true
|
||||
|
||||
fun doTestKotlinClass(path: String) {
|
||||
val virtualFile = configureModuleStructure(path)
|
||||
val virtualFile = configureModuleStructure(path).second
|
||||
require(virtualFile != null)
|
||||
|
||||
myFixture.configureFromExistingVirtualFile(virtualFile)
|
||||
@@ -41,7 +40,7 @@ abstract class AbstractKotlinDefinitionsSearcherMultiplatformTest : KotlinLightM
|
||||
|
||||
|
||||
fun doTestCallable(path: String) {
|
||||
val virtualFile = configureModuleStructure(path)
|
||||
val virtualFile = configureModuleStructure(path).second
|
||||
require(virtualFile != null)
|
||||
|
||||
myFixture.configureFromExistingVirtualFile(virtualFile)
|
||||
|
||||
@@ -32,11 +32,12 @@ abstract class KotlinLightMultiplatformCodeInsightFixtureTestCase : KotlinLightC
|
||||
*
|
||||
* Each file is added to the test project's platform module.
|
||||
*
|
||||
* Returns file which was marked as `MAIN` or null
|
||||
* Returns a list of all files and a file which was marked as `MAIN` or `null` if it's absent.
|
||||
*/
|
||||
fun configureModuleStructure(abstractFilePath: String): VirtualFile? {
|
||||
fun configureModuleStructure(abstractFilePath: String): Pair<List<VirtualFile>, VirtualFile?> {
|
||||
val map = ModuleStructureSplitter.splitPerModule(File(abstractFilePath))
|
||||
var mainFile: VirtualFile? = null
|
||||
val allFiles: MutableList<VirtualFile> = mutableListOf()
|
||||
map.forEach { (platform, files) ->
|
||||
val platformDescriptor = when (platform) {
|
||||
"Common" -> KotlinMultiPlatformProjectDescriptor.PlatformDescriptor.COMMON
|
||||
@@ -47,6 +48,7 @@ abstract class KotlinLightMultiplatformCodeInsightFixtureTestCase : KotlinLightC
|
||||
if (platformDescriptor != null) {
|
||||
for (testFile in files) {
|
||||
val virtualFile = VfsTestUtil.createFile(platformDescriptor.sourceRoot()!!, testFile.relativePath, testFile.text)
|
||||
allFiles.add(virtualFile)
|
||||
if (testFile.isMain) {
|
||||
mainFile = virtualFile
|
||||
}
|
||||
@@ -54,7 +56,7 @@ abstract class KotlinLightMultiplatformCodeInsightFixtureTestCase : KotlinLightC
|
||||
}
|
||||
}
|
||||
}
|
||||
return mainFile
|
||||
return allFiles to mainFile
|
||||
}
|
||||
|
||||
override fun setUp() {
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.intellij.openapi.vfs.ex.temp.TempFileSystem
|
||||
import com.intellij.pom.java.LanguageLevel
|
||||
import com.intellij.testFramework.IdeaTestUtil
|
||||
import com.intellij.testFramework.IndexingTestUtil
|
||||
import com.intellij.testFramework.fixtures.MavenDependencyUtil
|
||||
import org.jetbrains.jps.model.java.JavaSourceRootType
|
||||
import org.jetbrains.kotlin.idea.framework.KotlinSdkType
|
||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||
@@ -23,7 +24,7 @@ import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
||||
/**
|
||||
* The project is created with three modules: Common, Jvm -> Common, Js -> Common.
|
||||
*
|
||||
* Currently, no libraries are added.
|
||||
* Standard library dependency is added to all modules.
|
||||
*/
|
||||
object KotlinMultiPlatformProjectDescriptor : KotlinLightProjectDescriptor() {
|
||||
enum class PlatformDescriptor(
|
||||
@@ -32,6 +33,7 @@ object KotlinMultiPlatformProjectDescriptor : KotlinLightProjectDescriptor() {
|
||||
val targetPlatform: TargetPlatform,
|
||||
val isKotlinSdkUsed: Boolean = true,
|
||||
val refinementDependencies: List<PlatformDescriptor> = emptyList(),
|
||||
val dependencyCoordinates: List<String> = emptyList(),
|
||||
) {
|
||||
COMMON(
|
||||
moduleName = "Common",
|
||||
@@ -42,6 +44,9 @@ object KotlinMultiPlatformProjectDescriptor : KotlinLightProjectDescriptor() {
|
||||
JsPlatforms.defaultJsPlatform.single()
|
||||
)
|
||||
),
|
||||
dependencyCoordinates = listOf(
|
||||
"org.jetbrains.kotlin:kotlin-stdlib-common:1.9.23", // TODO (KTIJ-29725): make stdlib version dynamic
|
||||
),
|
||||
),
|
||||
JVM(
|
||||
moduleName = "Jvm",
|
||||
@@ -49,12 +54,18 @@ object KotlinMultiPlatformProjectDescriptor : KotlinLightProjectDescriptor() {
|
||||
targetPlatform = JvmPlatforms.jvm8,
|
||||
isKotlinSdkUsed = false,
|
||||
refinementDependencies = listOf(COMMON),
|
||||
dependencyCoordinates = listOf(
|
||||
"org.jetbrains.kotlin:kotlin-stdlib:1.9.23",
|
||||
),
|
||||
),
|
||||
JS(
|
||||
moduleName = "Js",
|
||||
sourceRootName = "src_js",
|
||||
targetPlatform = JsPlatforms.defaultJsPlatform,
|
||||
refinementDependencies = listOf(COMMON),
|
||||
dependencyCoordinates = listOf(
|
||||
"org.jetbrains.kotlin:kotlin-stdlib-js:1.9.23",
|
||||
),
|
||||
);
|
||||
|
||||
fun sourceRoot(): VirtualFile? = findRoot(sourceRootName)
|
||||
@@ -96,6 +107,21 @@ object KotlinMultiPlatformProjectDescriptor : KotlinLightProjectDescriptor() {
|
||||
model.addContentEntry(sourceRoot).addSourceFolder(sourceRoot, JavaSourceRootType.SOURCE)
|
||||
}
|
||||
|
||||
setUpSdk(module, model, descriptor)
|
||||
|
||||
module.createMultiplatformFacetM3(
|
||||
platformKind = descriptor.targetPlatform,
|
||||
useProjectSettings = false,
|
||||
dependsOnModuleNames = descriptor.refinementDependencies.map(PlatformDescriptor::moduleName),
|
||||
pureKotlinSourceFolders = listOf(descriptor.sourceRoot()!!.path),
|
||||
)
|
||||
|
||||
for (libraryCoordinates in descriptor.dependencyCoordinates) {
|
||||
MavenDependencyUtil.addFromMaven(model, libraryCoordinates)
|
||||
}
|
||||
}
|
||||
|
||||
private fun setUpSdk(module: Module, model: ModifiableRootModel, descriptor: PlatformDescriptor) {
|
||||
if (descriptor.isKotlinSdkUsed) {
|
||||
KotlinSdkType.setUpIfNeeded(module)
|
||||
ConfigLibraryUtil.configureSdk(
|
||||
@@ -106,13 +132,6 @@ object KotlinMultiPlatformProjectDescriptor : KotlinLightProjectDescriptor() {
|
||||
} else {
|
||||
model.sdk = sdk
|
||||
}
|
||||
|
||||
module.createMultiplatformFacetM3(
|
||||
platformKind = descriptor.targetPlatform,
|
||||
useProjectSettings = false,
|
||||
dependsOnModuleNames = descriptor.refinementDependencies.map(PlatformDescriptor::moduleName),
|
||||
pureKotlinSourceFolders = listOf(descriptor.sourceRoot()!!.path),
|
||||
)
|
||||
}
|
||||
|
||||
fun cleanupSourceRoots() = runWriteAction {
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.jetbrains.kotlin.idea.fir.folding.AbstractFirFoldingTest
|
||||
import org.jetbrains.kotlin.idea.fir.imports.AbstractFirJvmOptimizeImportsTest
|
||||
import org.jetbrains.kotlin.idea.fir.imports.AbstractK2AutoImportTest
|
||||
import org.jetbrains.kotlin.idea.fir.imports.AbstractK2FilteringAutoImportTest
|
||||
import org.jetbrains.kotlin.idea.fir.kmp.AbstractK2KmpLightFixtureHighlightingTest
|
||||
import org.jetbrains.kotlin.idea.fir.low.level.api.AbstractFirLibraryModuleDeclarationResolveTest
|
||||
import org.jetbrains.kotlin.idea.fir.navigation.AbstractFirGotoDeclarationTest
|
||||
import org.jetbrains.kotlin.idea.fir.navigation.AbstractFirGotoRelatedSymbolMultiModuleTest
|
||||
@@ -61,7 +62,7 @@ import org.jetbrains.kotlin.testGenerator.model.Patterns.KT_WITHOUT_DOT_AND_FIR_
|
||||
import org.jetbrains.kotlin.testGenerator.model.Patterns.KT_WITHOUT_FIR_PREFIX
|
||||
import org.jetbrains.kotlin.testGenerator.model.Patterns.TEST
|
||||
|
||||
fun main(@Suppress("UNUSED_PARAMETER") args: Array<String>) {
|
||||
fun main(@Suppress("UNUSED_PARAMETER", "unused") args: Array<String>) {
|
||||
generateK2Tests()
|
||||
}
|
||||
|
||||
@@ -423,6 +424,10 @@ private fun assembleWorkspace(): TWorkspace = workspace {
|
||||
testClass<AbstractK2MultiModuleHighlightingTest> {
|
||||
model("resolve/anchors", isRecursive = false, pattern = Patterns.forRegex("^([^\\._]+)$"))
|
||||
}
|
||||
|
||||
testClass<AbstractK2KmpLightFixtureHighlightingTest> {
|
||||
model("kmp/highlighting", pattern = KT_WITHOUT_DOTS)
|
||||
}
|
||||
}
|
||||
|
||||
testGroup("fir/tests", category = COMPLETION) {
|
||||
|
||||
Reference in New Issue
Block a user