Create test tasks for all native hosts + tests
#KT-26547 fixed
This commit is contained in:
committed by
Ilya Matveev
parent
03e1e8d19d
commit
41367b0285
+38
-33
@@ -23,6 +23,13 @@ import kotlin.test.assertTrue
|
||||
class NewMultiplatformIT : BaseGradleIT() {
|
||||
val gradleVersion = GradleVersionRequired.AtLeast("4.8")
|
||||
|
||||
val nativeHostTargetName = when {
|
||||
HostManager.hostIsMingw -> "mingw64"
|
||||
HostManager.hostIsLinux -> "linux64"
|
||||
HostManager.hostIsMac -> "macos64"
|
||||
else -> error("Unknown host")
|
||||
}
|
||||
|
||||
private fun Project.targetClassesDir(targetName: String, sourceSetName: String = "main") =
|
||||
classesDir(sourceSet = "$targetName/$sourceSetName")
|
||||
|
||||
@@ -32,15 +39,8 @@ class NewMultiplatformIT : BaseGradleIT() {
|
||||
val appProject = Project("sample-app", gradleVersion, "new-mpp-lib-and-app")
|
||||
val oldStyleAppProject = Project("sample-old-style-app", gradleVersion, "new-mpp-lib-and-app")
|
||||
|
||||
val hostTargetName = when {
|
||||
HostManager.hostIsMingw -> "mingw64"
|
||||
HostManager.hostIsLinux -> "linux64"
|
||||
HostManager.hostIsMac -> "macos64"
|
||||
else -> error("Unknown host")
|
||||
}
|
||||
|
||||
val compileTasksNames =
|
||||
listOf("Jvm6", "NodeJs", "Metadata", "Wasm32", hostTargetName.capitalize()).map { ":compileKotlin$it" }
|
||||
listOf("Jvm6", "NodeJs", "Metadata", "Wasm32", nativeHostTargetName.capitalize()).map { ":compileKotlin$it" }
|
||||
|
||||
with(libProject) {
|
||||
build("publish") {
|
||||
@@ -52,7 +52,7 @@ class NewMultiplatformIT : BaseGradleIT() {
|
||||
val jsJarName = "sample-lib-nodejs/1.0/sample-lib-nodejs-1.0.jar"
|
||||
val metadataJarName = "sample-lib-metadata/1.0/sample-lib-metadata-1.0.jar"
|
||||
val wasmKlibName = "sample-lib-wasm32/1.0/sample-lib-wasm32-1.0.klib"
|
||||
val nativeKlibName = "sample-lib-$hostTargetName/1.0/sample-lib-$hostTargetName-1.0.klib"
|
||||
val nativeKlibName = "sample-lib-$nativeHostTargetName/1.0/sample-lib-$nativeHostTargetName-1.0.klib"
|
||||
|
||||
listOf(jvmJarName, jsJarName, metadataJarName, "sample-lib/1.0/sample-lib-1.0.module").forEach {
|
||||
Assert.assertTrue("$it should exist", groupDir.resolve(it).exists())
|
||||
@@ -117,8 +117,8 @@ class NewMultiplatformIT : BaseGradleIT() {
|
||||
assertFileExists("build/bin/wasm32/main/release/executable/sample_app.wasm")
|
||||
|
||||
val nativeExeName = if (isWindows) "sample-app.exe" else "sample-app.kexe"
|
||||
assertFileExists("build/bin/$hostTargetName/main/release/executable/$nativeExeName")
|
||||
assertFileExists("build/bin/$hostTargetName/main/debug/executable/$nativeExeName")
|
||||
assertFileExists("build/bin/$nativeHostTargetName/main/release/executable/$nativeExeName")
|
||||
assertFileExists("build/bin/$nativeHostTargetName/main/debug/executable/$nativeExeName")
|
||||
}
|
||||
|
||||
build("assemble", "resolveRuntimeDependencies") {
|
||||
@@ -457,36 +457,30 @@ class NewMultiplatformIT : BaseGradleIT() {
|
||||
|
||||
@Test
|
||||
fun testCanProduceNativeLibraries() = with(Project("new-mpp-native-libraries", gradleVersion)) {
|
||||
val hostTargetName = when {
|
||||
HostManager.hostIsMingw -> "mingw64"
|
||||
HostManager.hostIsLinux -> "linux64"
|
||||
HostManager.hostIsMac -> "macos64"
|
||||
else -> error("Unknown host")
|
||||
}
|
||||
val baseName = "native_lib"
|
||||
|
||||
val sharedPrefix = CompilerOutputKind.DYNAMIC.prefix(HostManager.host)
|
||||
val sharedSuffix = CompilerOutputKind.DYNAMIC.suffix(HostManager.host)
|
||||
val sharedPaths = listOf(
|
||||
"build/bin/$hostTargetName/main/debug/shared/$sharedPrefix$baseName$sharedSuffix",
|
||||
"build/bin/$hostTargetName/main/release/shared/$sharedPrefix$baseName$sharedSuffix"
|
||||
"build/bin/$nativeHostTargetName/main/debug/shared/$sharedPrefix$baseName$sharedSuffix",
|
||||
"build/bin/$nativeHostTargetName/main/release/shared/$sharedPrefix$baseName$sharedSuffix"
|
||||
)
|
||||
|
||||
val staticPrefix = CompilerOutputKind.STATIC.prefix(HostManager.host)
|
||||
val staticSuffix = CompilerOutputKind.STATIC.suffix(HostManager.host)
|
||||
val staticPaths = listOf(
|
||||
"build/bin/$hostTargetName/main/debug/static/$staticPrefix$baseName$staticSuffix",
|
||||
"build/bin/$hostTargetName/main/release/static/$staticPrefix$baseName$staticSuffix"
|
||||
"build/bin/$nativeHostTargetName/main/debug/static/$staticPrefix$baseName$staticSuffix",
|
||||
"build/bin/$nativeHostTargetName/main/release/static/$staticPrefix$baseName$staticSuffix"
|
||||
)
|
||||
|
||||
val headerPaths = listOf(
|
||||
"build/bin/$hostTargetName/main/debug/shared/$sharedPrefix${baseName}_api.h",
|
||||
"build/bin/$hostTargetName/main/release/shared/$sharedPrefix${baseName}_api.h",
|
||||
"build/bin/$hostTargetName/main/debug/static/$staticPrefix${baseName}_api.h",
|
||||
"build/bin/$hostTargetName/main/release/static/$staticPrefix${baseName}_api.h"
|
||||
"build/bin/$nativeHostTargetName/main/debug/shared/$sharedPrefix${baseName}_api.h",
|
||||
"build/bin/$nativeHostTargetName/main/release/shared/$sharedPrefix${baseName}_api.h",
|
||||
"build/bin/$nativeHostTargetName/main/debug/static/$staticPrefix${baseName}_api.h",
|
||||
"build/bin/$nativeHostTargetName/main/release/static/$staticPrefix${baseName}_api.h"
|
||||
)
|
||||
|
||||
val taskSuffix = hostTargetName.capitalize()
|
||||
val taskSuffix = nativeHostTargetName.capitalize()
|
||||
val linkTasks = listOf(
|
||||
":linkMainDebugShared$taskSuffix",
|
||||
":linkMainReleaseShared$taskSuffix",
|
||||
@@ -523,13 +517,6 @@ class NewMultiplatformIT : BaseGradleIT() {
|
||||
build("publish") {
|
||||
assertSuccessful()
|
||||
|
||||
val nativeHostTargetName = when {
|
||||
HostManager.hostIsMingw -> "mingw64"
|
||||
HostManager.hostIsLinux -> "linux64"
|
||||
HostManager.hostIsMac -> "macos64"
|
||||
else -> error("Unknown host")
|
||||
}
|
||||
|
||||
val groupDir = projectDir.resolve("repo/com/example/")
|
||||
val targetArtifactIdAppendices = listOf("metadata", "jvm6", "nodejs", "wasm32", nativeHostTargetName)
|
||||
|
||||
@@ -546,4 +533,22 @@ class NewMultiplatformIT : BaseGradleIT() {
|
||||
assertEquals(setOf("commonMain", "${nativeHostTargetName}Main"), sourceJarSourceRoots[nativeHostTargetName])
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testNativeTests() = with(Project("new-mpp-native-tests", gradleVersion)) {
|
||||
val testTasks = listOf("macos64Test", "linux64Test", "mingw64Test")
|
||||
val hostTestTask = ":${nativeHostTargetName}Test"
|
||||
build("tasks") {
|
||||
assertSuccessful()
|
||||
println(output)
|
||||
testTasks.forEach {
|
||||
// We need to create tasks for all hosts
|
||||
assertTrue(output.contains("$it - "), "There is no test task '$it' in the task list.")
|
||||
}
|
||||
}
|
||||
build("check") {
|
||||
assertSuccessful()
|
||||
assertTasksExecuted(hostTestTask)
|
||||
}
|
||||
}
|
||||
}
|
||||
+28
@@ -0,0 +1,28 @@
|
||||
group 'com.example'
|
||||
version '1.0'
|
||||
|
||||
buildscript {
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
}
|
||||
dependencies {
|
||||
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
|
||||
}
|
||||
}
|
||||
|
||||
apply plugin: 'kotlin-multiplatform'
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
jcenter()
|
||||
maven { url "http://dl.bintray.com/kotlin/kotlinx.html/" }
|
||||
}
|
||||
|
||||
kotlin {
|
||||
targets {
|
||||
fromPreset(presets.macosX64, 'macos64')
|
||||
fromPreset(presets.linuxX64, 'linux64')
|
||||
fromPreset(presets.mingwX64, 'mingw64')
|
||||
}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
enableFeaturePreview('GRADLE_METADATA')
|
||||
|
||||
rootProject.name = 'native-tests'
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.foo
|
||||
|
||||
fun foo() = "Foo call"
|
||||
|
||||
internal fun bar() = "Bar call"
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||
* that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.foo.test
|
||||
|
||||
import org.foo.*
|
||||
import kotlin.test.*
|
||||
|
||||
@Test
|
||||
fun fooTest() {
|
||||
println(foo())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun barTest() {
|
||||
println(bar())
|
||||
}
|
||||
|
||||
|
||||
+6
-4
@@ -380,6 +380,7 @@ open class KotlinNativeTargetConfigurator(
|
||||
createDefaultSourceSets = true,
|
||||
createTestCompilation = true
|
||||
) {
|
||||
private val hostTargets = listOf(KonanTarget.LINUX_X64, KonanTarget.MACOS_X64, KonanTarget.MINGW_X64)
|
||||
|
||||
private val Collection<*>.isDimensionVisible: Boolean
|
||||
get() = size > 1
|
||||
@@ -400,7 +401,8 @@ open class KotlinNativeTargetConfigurator(
|
||||
val testTask = tasks.create(taskName, RunTestExecutable::class.java).apply {
|
||||
group = LifecycleBasePlugin.VERIFICATION_GROUP
|
||||
description = "Executes Kotlin/Native unit tests from the '${compilation.name}' compilation " +
|
||||
"for target '${compilation.target.name}'"
|
||||
"for target '${compilation.target.name}'."
|
||||
enabled = compilation.target.konanTarget.isCurrentHost
|
||||
|
||||
val testExecutableProperty = testExecutableLinkTask.outputFile
|
||||
executable = testExecutableProperty.get().absolutePath
|
||||
@@ -495,7 +497,7 @@ open class KotlinNativeTargetConfigurator(
|
||||
outputKind = compilerOutputKind
|
||||
group = BasePlugin.BUILD_GROUP
|
||||
description = "Links ${kind.description} from the '${compilation.name}' " +
|
||||
"compilation for target '${compilation.platformType.name}'"
|
||||
"compilation for target '${compilation.platformType.name}'."
|
||||
enabled = compilation.target.konanTarget.enabledOnCurrentHost
|
||||
|
||||
optimized = buildType.optimized
|
||||
@@ -508,7 +510,7 @@ open class KotlinNativeTargetConfigurator(
|
||||
|
||||
if (compilation.isTestCompilation &&
|
||||
buildType == NativeBuildType.DEBUG &&
|
||||
konanTarget == HostManager.host
|
||||
konanTarget in hostTargets
|
||||
) {
|
||||
// TODO: Refactor and move into the corresponding method of AbstractKotlinTargetConfigurator.
|
||||
createTestTask(compilation, linkTask)
|
||||
@@ -549,7 +551,7 @@ open class KotlinNativeTargetConfigurator(
|
||||
outputKind = CompilerOutputKind.LIBRARY
|
||||
group = BasePlugin.BUILD_GROUP
|
||||
description = "Compiles a klibrary from the '${compilation.name}' " +
|
||||
"compilation for target '${compilation.platformType.name}'"
|
||||
"compilation for target '${compilation.platformType.name}'."
|
||||
enabled = compilation.target.konanTarget.enabledOnCurrentHost
|
||||
|
||||
registerOutputFiles(klibOutputDirectory(compilation))
|
||||
|
||||
+3
@@ -289,6 +289,9 @@ class KotlinNativeTargetPreset(
|
||||
}
|
||||
}
|
||||
|
||||
internal val KonanTarget.isCurrentHost: Boolean
|
||||
get() = this == HostManager.host
|
||||
|
||||
internal val KonanTarget.enabledOnCurrentHost
|
||||
get() = HostManager().isEnabled(this)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user