Add test for using multiple Kotlin frameworks in single application
This commit is contained in:
committed by
SvyatoslavScherbina
parent
9180befd83
commit
4d7f39b51d
@@ -3735,6 +3735,42 @@ if (isAppleTarget(project)) {
|
||||
}
|
||||
swiftSources = ['framework/stdlib/stdlib.swift']
|
||||
}
|
||||
|
||||
task testMultipleFrameworks(type: FrameworkTest) {
|
||||
testName = "MultipleFrameworks"
|
||||
final String firstFrameworkName = 'First'
|
||||
final String secondFrameworkName = 'Second'
|
||||
frameworkNames = [firstFrameworkName, secondFrameworkName]
|
||||
|
||||
final String dir = "$testOutputFramework/$testName"
|
||||
|
||||
konanArtifacts {
|
||||
framework(firstFrameworkName, targets: [ targetName ]) {
|
||||
srcDir 'framework/multiple/framework1'
|
||||
srcDir 'framework/multiple/shared'
|
||||
baseDir dir
|
||||
|
||||
if (!useCustomDist) {
|
||||
dependsOn ":${targetName}CrossDistRuntime", ':commonDistRuntime', ':distCompiler'
|
||||
}
|
||||
|
||||
extraOpts project.globalTestArgs
|
||||
}
|
||||
|
||||
framework(secondFrameworkName, targets: [ targetName ]) {
|
||||
srcDir 'framework/multiple/framework2'
|
||||
srcDir 'framework/multiple/shared'
|
||||
baseDir dir
|
||||
|
||||
if (!useCustomDist) {
|
||||
dependsOn ":${targetName}CrossDistRuntime", ':commonDistRuntime', ':distCompiler'
|
||||
}
|
||||
|
||||
extraOpts project.globalTestArgs
|
||||
}
|
||||
}
|
||||
swiftSources = ['framework/multiple/multiple.swift']
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
@file:Suppress("UNUSED")
|
||||
|
||||
package multiple
|
||||
|
||||
interface I1 {
|
||||
fun getFortyTwo(): Int
|
||||
}
|
||||
|
||||
class I1Impl : I1 {
|
||||
override fun getFortyTwo(): Int = 42
|
||||
}
|
||||
|
||||
class C
|
||||
|
||||
fun getUnit(): Unit? = Unit
|
||||
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
@file:Suppress("UNUSED")
|
||||
|
||||
package multiple
|
||||
|
||||
val name = "first"
|
||||
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
@file:Suppress("UNUSED")
|
||||
|
||||
package multiple
|
||||
|
||||
interface I2 {
|
||||
fun getFortyTwo(): Int
|
||||
}
|
||||
|
||||
fun getFortyTwoFrom(i2: I2): Int = i2.getFortyTwo()
|
||||
|
||||
class C
|
||||
|
||||
fun isUnit(obj: Any?): Boolean = (obj === Unit)
|
||||
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
@file:Suppress("UNUSED")
|
||||
|
||||
package multiple
|
||||
|
||||
val name = "second"
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2010-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the LICENSE file.
|
||||
*/
|
||||
|
||||
import First
|
||||
import Second
|
||||
|
||||
func testClashingNames() throws {
|
||||
try assertEquals(actual: "first", expected: First.TestKt.name)
|
||||
try assertEquals(actual: "second", expected: Second.TestKt.name)
|
||||
|
||||
let c1 = First.C()
|
||||
let c2 = Second.C()
|
||||
try assertTrue(type(of: c1) == First.C.self)
|
||||
try assertTrue(type(of: c2) == Second.C.self)
|
||||
try assertTrue(First.C.self != Second.C.self)
|
||||
try assertTrue(objc_getClass(class_getName(First.C.self)) as AnyObject === First.C.self)
|
||||
try assertTrue(objc_getClass(class_getName(Second.C.self)) as AnyObject === Second.C.self)
|
||||
}
|
||||
|
||||
extension I1Impl : I2 {}
|
||||
|
||||
func testInteraction() throws {
|
||||
try assertEquals(actual: SecondKt.getFortyTwoFrom(i2: I1Impl()), expected: 42)
|
||||
}
|
||||
|
||||
func testIsolation() throws {
|
||||
try assertFalse(SecondKt.isUnit(obj: FirstKt.getUnit()))
|
||||
|
||||
// Ensure frameworks don't share the same runtime (state):
|
||||
try assertFalse(First.RuntimeState().consumeChange())
|
||||
try assertFalse(Second.RuntimeState().consumeChange())
|
||||
Second.RuntimeState().produceChange()
|
||||
try assertFalse(First.RuntimeState().consumeChange())
|
||||
try assertTrue(Second.RuntimeState().consumeChange())
|
||||
}
|
||||
|
||||
class MultipleFrameworksTests : TestProvider {
|
||||
var tests: [TestCase] = []
|
||||
|
||||
init() {
|
||||
tests = [
|
||||
TestCase(name: "TestClashingNames", method: withAutorelease(testClashingNames)),
|
||||
TestCase(name: "TestInteraction", method: withAutorelease(testInteraction)),
|
||||
TestCase(name: "TestIsolation", method: withAutorelease(testIsolation)),
|
||||
]
|
||||
providers.append(self)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import kotlin.native.concurrent.Worker
|
||||
|
||||
object RuntimeState {
|
||||
fun produceChange() {
|
||||
Worker.current.executeAfter {}
|
||||
}
|
||||
|
||||
fun consumeChange(): Boolean {
|
||||
return Worker.current.processQueue()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user