Add test about resolution to klib from non/common platforms
This commit is contained in:
committed by
Space Team
parent
7f33097634
commit
6c062b0cea
+9
@@ -0,0 +1,9 @@
|
|||||||
|
package common
|
||||||
|
|
||||||
|
import some.example.Person
|
||||||
|
|
||||||
|
fun greetEachOther(people: Collection<Person>) {
|
||||||
|
for (person in people) {
|
||||||
|
person.greet()
|
||||||
|
}
|
||||||
|
}
|
||||||
+19
@@ -0,0 +1,19 @@
|
|||||||
|
package jvmTest
|
||||||
|
|
||||||
|
import common.greetEachOther
|
||||||
|
import some.example.Person
|
||||||
|
|
||||||
|
private class MyPerson(
|
||||||
|
name: String
|
||||||
|
) : Person(name) {
|
||||||
|
override fun greet() = "Hi"
|
||||||
|
}
|
||||||
|
|
||||||
|
fun test() {
|
||||||
|
greetEachOther(
|
||||||
|
listOf(
|
||||||
|
Person("Alice"),
|
||||||
|
MyPerson("Bob"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package some.example
|
||||||
|
|
||||||
|
open class Person(
|
||||||
|
val name: String
|
||||||
|
) {
|
||||||
|
open fun greet() = "Hello"
|
||||||
|
}
|
||||||
+53
-6
@@ -25,12 +25,10 @@ import org.jetbrains.kotlin.name.ClassId
|
|||||||
import org.jetbrains.kotlin.name.FqName
|
import org.jetbrains.kotlin.name.FqName
|
||||||
import org.jetbrains.kotlin.name.Name
|
import org.jetbrains.kotlin.name.Name
|
||||||
import org.jetbrains.kotlin.platform.CommonPlatforms
|
import org.jetbrains.kotlin.platform.CommonPlatforms
|
||||||
import org.jetbrains.kotlin.platform.js.JsPlatforms
|
|
||||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
||||||
import org.jetbrains.kotlin.psi.KtCallExpression
|
import org.jetbrains.kotlin.psi.KtCallExpression
|
||||||
import org.jetbrains.kotlin.psi.KtFile
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType
|
import org.jetbrains.kotlin.psi.psiUtil.findDescendantOfType
|
||||||
import org.jetbrains.kotlin.utils.PathUtil
|
|
||||||
import org.junit.jupiter.api.Assertions
|
import org.junit.jupiter.api.Assertions
|
||||||
import org.junit.jupiter.api.Test
|
import org.junit.jupiter.api.Test
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
@@ -76,6 +74,7 @@ class StandaloneSessionBuilderTest : TestWithDisposable() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testResolveAgainstCommonKlib() {
|
fun testResolveAgainstCommonKlib() {
|
||||||
|
val root = "resolveAgainstCommonKLib"
|
||||||
lateinit var sourceModule: KtSourceModule
|
lateinit var sourceModule: KtSourceModule
|
||||||
val session = buildStandaloneAnalysisAPISession(disposable) {
|
val session = buildStandaloneAnalysisAPISession(disposable) {
|
||||||
registerProjectService(KtLifetimeTokenProvider::class.java, KtAlwaysAccessibleLifetimeTokenProvider())
|
registerProjectService(KtLifetimeTokenProvider::class.java, KtAlwaysAccessibleLifetimeTokenProvider())
|
||||||
@@ -84,7 +83,7 @@ class StandaloneSessionBuilderTest : TestWithDisposable() {
|
|||||||
platform = CommonPlatforms.defaultCommonPlatform
|
platform = CommonPlatforms.defaultCommonPlatform
|
||||||
val kLib = addModule(
|
val kLib = addModule(
|
||||||
buildKtLibraryModule {
|
buildKtLibraryModule {
|
||||||
val compiledKLibRoot = compileCommonKlib(testDataPath("resolveAgainstCommonKLib/klibSrc"))
|
val compiledKLibRoot = compileCommonKlib(testDataPath(root).resolve("klibSrc"))
|
||||||
addBinaryRoot(compiledKLibRoot)
|
addBinaryRoot(compiledKLibRoot)
|
||||||
platform = CommonPlatforms.defaultCommonPlatform
|
platform = CommonPlatforms.defaultCommonPlatform
|
||||||
libraryName = "klib"
|
libraryName = "klib"
|
||||||
@@ -92,7 +91,7 @@ class StandaloneSessionBuilderTest : TestWithDisposable() {
|
|||||||
)
|
)
|
||||||
sourceModule = addModule(
|
sourceModule = addModule(
|
||||||
buildKtSourceModule {
|
buildKtSourceModule {
|
||||||
addSourceRoot(testDataPath("resolveAgainstCommonKLib/src"))
|
addSourceRoot(testDataPath(root).resolve("src"))
|
||||||
addRegularDependency(kLib)
|
addRegularDependency(kLib)
|
||||||
platform = CommonPlatforms.defaultCommonPlatform
|
platform = CommonPlatforms.defaultCommonPlatform
|
||||||
moduleName = "source"
|
moduleName = "source"
|
||||||
@@ -106,8 +105,56 @@ class StandaloneSessionBuilderTest : TestWithDisposable() {
|
|||||||
ktCallExpression.assertIsCallOf(CallableId(FqName("commonKLib"), Name.identifier("commonKLibFunction")))
|
ktCallExpression.assertIsCallOf(CallableId(FqName("commonKLib"), Name.identifier("commonKLibFunction")))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun testResolveAgainstCommonKlibFromOtherModule() {
|
||||||
|
val root = "resolveAgainstCommonKLibFromOtherModule"
|
||||||
|
lateinit var commonModule: KtSourceModule
|
||||||
|
lateinit var sourceModule: KtSourceModule
|
||||||
|
val session = buildStandaloneAnalysisAPISession(disposable) {
|
||||||
|
registerProjectService(KtLifetimeTokenProvider::class.java, KtAlwaysAccessibleLifetimeTokenProvider())
|
||||||
|
|
||||||
|
buildKtModuleProvider {
|
||||||
|
platform = CommonPlatforms.defaultCommonPlatform
|
||||||
|
val kLib = addModule(
|
||||||
|
buildKtLibraryModule {
|
||||||
|
val compiledKLibRoot = compileCommonKlib(testDataPath(root).resolve("klibSrc"))
|
||||||
|
addBinaryRoot(compiledKLibRoot)
|
||||||
|
platform = CommonPlatforms.defaultCommonPlatform
|
||||||
|
libraryName = "klib"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
commonModule = addModule(
|
||||||
|
buildKtSourceModule {
|
||||||
|
addSourceRoot(testDataPath(root).resolve("commonMain"))
|
||||||
|
addRegularDependency(kLib)
|
||||||
|
platform = CommonPlatforms.defaultCommonPlatform
|
||||||
|
moduleName = "common"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
sourceModule = addModule(
|
||||||
|
buildKtSourceModule {
|
||||||
|
addSourceRoot(testDataPath(root).resolve("jvmMain"))
|
||||||
|
addRegularDependency(kLib)
|
||||||
|
addRegularDependency(commonModule)
|
||||||
|
platform = JvmPlatforms.defaultJvmPlatform
|
||||||
|
moduleName = "app"
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val ktFileInCommon = session.modulesWithFiles.getValue(commonModule).single() as KtFile
|
||||||
|
val callInCommon = ktFileInCommon.findDescendantOfType<KtCallExpression>()!!
|
||||||
|
callInCommon.assertIsCallOf(CallableId(FqName("some.example"), FqName("Person"), Name.identifier("greet")))
|
||||||
|
|
||||||
|
val ktFileInJvm = session.modulesWithFiles.getValue(sourceModule).single() as KtFile
|
||||||
|
val callInJvm = ktFileInJvm.findDescendantOfType<KtCallExpression>()!!
|
||||||
|
callInJvm.assertIsCallOf(CallableId(FqName("common"), Name.identifier("greetEachOther")))
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testKotlinSourceModuleSessionBuilder() {
|
fun testKotlinSourceModuleSessionBuilder() {
|
||||||
|
val root = "otherModuleUsage"
|
||||||
lateinit var sourceModule: KtSourceModule
|
lateinit var sourceModule: KtSourceModule
|
||||||
val session = buildStandaloneAnalysisAPISession(disposable) {
|
val session = buildStandaloneAnalysisAPISession(disposable) {
|
||||||
registerProjectService(KtLifetimeTokenProvider::class.java, KtAlwaysAccessibleLifetimeTokenProvider())
|
registerProjectService(KtLifetimeTokenProvider::class.java, KtAlwaysAccessibleLifetimeTokenProvider())
|
||||||
@@ -116,14 +163,14 @@ class StandaloneSessionBuilderTest : TestWithDisposable() {
|
|||||||
platform = JvmPlatforms.defaultJvmPlatform
|
platform = JvmPlatforms.defaultJvmPlatform
|
||||||
val main = addModule(
|
val main = addModule(
|
||||||
buildKtSourceModule {
|
buildKtSourceModule {
|
||||||
addSourceRoot(testDataPath("otherModuleUsage").resolve("dependent"))
|
addSourceRoot(testDataPath(root).resolve("dependent"))
|
||||||
platform = JvmPlatforms.defaultJvmPlatform
|
platform = JvmPlatforms.defaultJvmPlatform
|
||||||
moduleName = "dependent"
|
moduleName = "dependent"
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
sourceModule = addModule(
|
sourceModule = addModule(
|
||||||
buildKtSourceModule {
|
buildKtSourceModule {
|
||||||
addSourceRoot(testDataPath("otherModuleUsage").resolve("main"))
|
addSourceRoot(testDataPath(root).resolve("main"))
|
||||||
addRegularDependency(main)
|
addRegularDependency(main)
|
||||||
platform = JvmPlatforms.defaultJvmPlatform
|
platform = JvmPlatforms.defaultJvmPlatform
|
||||||
moduleName = "main"
|
moduleName = "main"
|
||||||
|
|||||||
Reference in New Issue
Block a user