[Gradle, K/N] Add more cases for cinterop test

This commit is contained in:
Alexander.Likhachev
2020-10-14 00:20:17 +03:00
parent be7cc32c10
commit 3dda02459d
14 changed files with 161 additions and 24 deletions
@@ -687,24 +687,27 @@ class GeneralNativeIT : BaseGradleIT() {
}
@Test
fun testCinterop() {
with(transformNativeTestProjectWithPluginDsl("native-cinterop")) {
build(":build") {
assertSuccessful()
assertFileExists("build/libs/host/main/native-cinterop-cinterop-number.klib")
assertFileExists("build/classes/kotlin/host/main/native-cinterop-cinterop-number.klib")
assertFileExists("build/classes/kotlin/host/test/native-cinterop_test.klib")
}
fun testCinterop() = with(transformNativeTestProjectWithPluginDsl("native-cinterop")) {
fun libraryFiles(projectName: String, cinteropName: String) = listOf(
"$projectName/build/classes/kotlin/host/main/${projectName}-cinterop-$cinteropName.klib",
"$projectName/build/classes/kotlin/host/main/${projectName}.klib",
"$projectName/build/classes/kotlin/host/test/${projectName}_test.klib",
)
// Check that changing the compiler version in properties causes interop reprocessing and source recompilation.
val hostLibraryTasks = listOf(
":cinteropNumberHost",
":compileKotlinHost"
)
build(":build") {
assertSuccessful()
assertTasksUpToDate(hostLibraryTasks)
}
build(":projectLibrary:build") {
assertSuccessful()
assertTasksExecuted(":projectLibrary:cinteropAnotherNumberHost")
libraryFiles("projectLibrary", "anotherNumber").forEach { assertFileExists(it) }
}
build(":publishedLibrary:build", ":publishedLibrary:publish") {
assertSuccessful()
assertTasksExecuted(":publishedLibrary:cinteropNumberHost")
libraryFiles("publishedLibrary", "number").forEach { assertFileExists(it) }
}
build(":build") {
assertSuccessful()
}
}
@@ -5,12 +5,22 @@ plugins {
repositories {
mavenLocal()
jcenter()
maven { url 'repo' }
}
kotlin {
sourceSets {
hostMain {
dependencies {
implementation project(':projectLibrary')
implementation 'org.example:publishedLibrary:1.0'
}
}
}
<SingleNativeTarget>("host") {
compilations.main.cinterops {
number {
compilations.test.cinterops {
testNumber {
packageName 'example.cinterop.project'
extraOpts '-nodefaultlibs'
compilerOpts '-DEVEN_NUMBER'
@@ -0,0 +1,21 @@
plugins {
id("org.jetbrains.kotlin.multiplatform")
id("maven-publish")
}
repositories {
mavenLocal()
jcenter()
}
kotlin {
<SingleNativeTarget>("host") {
compilations.main.cinterops {
anotherNumber {
packageName 'library.cinterop.project'
extraOpts '-nodefaultlibs'
compilerOpts '-DEVEN_NUMBER'
}
}
}
}
@@ -0,0 +1,10 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package library.cinterop.project
fun projectAnswer(): Int {
return getAnotherNumber() * 2
}
@@ -0,0 +1,12 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package library.cinterop.project
import kotlin.test.*
@Test
fun testAnswer() {
assertEquals(8, projectAnswer())
}
@@ -0,0 +1,11 @@
compilerOpts.osx = -D_ANSI_SOURCE
---
int getAnotherNumber()
{
#ifdef EVEN_NUMBER
return 4;
#else
return 3;
#endif
}
@@ -0,0 +1,32 @@
plugins {
id("org.jetbrains.kotlin.multiplatform")
id("maven-publish")
}
group = 'org.example'
version = '1.0'
repositories {
mavenLocal()
jcenter()
}
kotlin {
<SingleNativeTarget>("host") {
compilations.main.cinterops {
number {
packageName 'library.cinterop.project'
extraOpts '-nodefaultlibs'
compilerOpts '-DEVEN_NUMBER'
}
}
}
}
publishing {
repositories {
maven {
url = '../repo'
}
}
}
@@ -0,0 +1,10 @@
/*
* Copyright 2010-2018 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package library.cinterop.project
fun publishedAnswer(): Int {
return getNumber() * 2
}
@@ -0,0 +1,12 @@
/*
* Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors.
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
*/
package library.cinterop.project
import kotlin.test.*
@Test
fun testAnswer() {
assertEquals(4, publishedAnswer())
}
@@ -9,3 +9,6 @@ pluginManagement {
enableFeaturePreview('GRADLE_METADATA')
rootProject.name = "native-cinterop"
include 'projectLibrary'
include 'publishedLibrary'
@@ -5,8 +5,12 @@
package example.cinterop.project
import example.cinterop.project.*
import library.cinterop.project.*
fun answer(): Int {
return getNumber() * 2
fun libraryAnswer(): Int {
return publishedAnswer() + projectAnswer()
}
fun selfCalculatedAnswer(): Int {
return getNumber() * 2 + getAnotherNumber() * 2
}
@@ -7,6 +7,8 @@ package example.cinterop.project
import kotlin.test.*
@Test
fun compilerOptsTest() {
assertEquals(4, answer())
fun testAnswer() {
assertEquals(12, libraryAnswer())
assertEquals(12, selfCalculatedAnswer())
assertEquals(5, getTestNumber())
}
@@ -0,0 +1,7 @@
compilerOpts.osx = -D_ANSI_SOURCE
---
int getTestNumber()
{
return 5;
}