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() {
|
class NewMultiplatformIT : BaseGradleIT() {
|
||||||
val gradleVersion = GradleVersionRequired.AtLeast("4.8")
|
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") =
|
private fun Project.targetClassesDir(targetName: String, sourceSetName: String = "main") =
|
||||||
classesDir(sourceSet = "$targetName/$sourceSetName")
|
classesDir(sourceSet = "$targetName/$sourceSetName")
|
||||||
|
|
||||||
@@ -32,15 +39,8 @@ class NewMultiplatformIT : BaseGradleIT() {
|
|||||||
val appProject = Project("sample-app", gradleVersion, "new-mpp-lib-and-app")
|
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 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 =
|
val compileTasksNames =
|
||||||
listOf("Jvm6", "NodeJs", "Metadata", "Wasm32", hostTargetName.capitalize()).map { ":compileKotlin$it" }
|
listOf("Jvm6", "NodeJs", "Metadata", "Wasm32", nativeHostTargetName.capitalize()).map { ":compileKotlin$it" }
|
||||||
|
|
||||||
with(libProject) {
|
with(libProject) {
|
||||||
build("publish") {
|
build("publish") {
|
||||||
@@ -52,7 +52,7 @@ class NewMultiplatformIT : BaseGradleIT() {
|
|||||||
val jsJarName = "sample-lib-nodejs/1.0/sample-lib-nodejs-1.0.jar"
|
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 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 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 {
|
listOf(jvmJarName, jsJarName, metadataJarName, "sample-lib/1.0/sample-lib-1.0.module").forEach {
|
||||||
Assert.assertTrue("$it should exist", groupDir.resolve(it).exists())
|
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")
|
assertFileExists("build/bin/wasm32/main/release/executable/sample_app.wasm")
|
||||||
|
|
||||||
val nativeExeName = if (isWindows) "sample-app.exe" else "sample-app.kexe"
|
val nativeExeName = if (isWindows) "sample-app.exe" else "sample-app.kexe"
|
||||||
assertFileExists("build/bin/$hostTargetName/main/release/executable/$nativeExeName")
|
assertFileExists("build/bin/$nativeHostTargetName/main/release/executable/$nativeExeName")
|
||||||
assertFileExists("build/bin/$hostTargetName/main/debug/executable/$nativeExeName")
|
assertFileExists("build/bin/$nativeHostTargetName/main/debug/executable/$nativeExeName")
|
||||||
}
|
}
|
||||||
|
|
||||||
build("assemble", "resolveRuntimeDependencies") {
|
build("assemble", "resolveRuntimeDependencies") {
|
||||||
@@ -457,36 +457,30 @@ class NewMultiplatformIT : BaseGradleIT() {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun testCanProduceNativeLibraries() = with(Project("new-mpp-native-libraries", gradleVersion)) {
|
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 baseName = "native_lib"
|
||||||
|
|
||||||
val sharedPrefix = CompilerOutputKind.DYNAMIC.prefix(HostManager.host)
|
val sharedPrefix = CompilerOutputKind.DYNAMIC.prefix(HostManager.host)
|
||||||
val sharedSuffix = CompilerOutputKind.DYNAMIC.suffix(HostManager.host)
|
val sharedSuffix = CompilerOutputKind.DYNAMIC.suffix(HostManager.host)
|
||||||
val sharedPaths = listOf(
|
val sharedPaths = listOf(
|
||||||
"build/bin/$hostTargetName/main/debug/shared/$sharedPrefix$baseName$sharedSuffix",
|
"build/bin/$nativeHostTargetName/main/debug/shared/$sharedPrefix$baseName$sharedSuffix",
|
||||||
"build/bin/$hostTargetName/main/release/shared/$sharedPrefix$baseName$sharedSuffix"
|
"build/bin/$nativeHostTargetName/main/release/shared/$sharedPrefix$baseName$sharedSuffix"
|
||||||
)
|
)
|
||||||
|
|
||||||
val staticPrefix = CompilerOutputKind.STATIC.prefix(HostManager.host)
|
val staticPrefix = CompilerOutputKind.STATIC.prefix(HostManager.host)
|
||||||
val staticSuffix = CompilerOutputKind.STATIC.suffix(HostManager.host)
|
val staticSuffix = CompilerOutputKind.STATIC.suffix(HostManager.host)
|
||||||
val staticPaths = listOf(
|
val staticPaths = listOf(
|
||||||
"build/bin/$hostTargetName/main/debug/static/$staticPrefix$baseName$staticSuffix",
|
"build/bin/$nativeHostTargetName/main/debug/static/$staticPrefix$baseName$staticSuffix",
|
||||||
"build/bin/$hostTargetName/main/release/static/$staticPrefix$baseName$staticSuffix"
|
"build/bin/$nativeHostTargetName/main/release/static/$staticPrefix$baseName$staticSuffix"
|
||||||
)
|
)
|
||||||
|
|
||||||
val headerPaths = listOf(
|
val headerPaths = listOf(
|
||||||
"build/bin/$hostTargetName/main/debug/shared/$sharedPrefix${baseName}_api.h",
|
"build/bin/$nativeHostTargetName/main/debug/shared/$sharedPrefix${baseName}_api.h",
|
||||||
"build/bin/$hostTargetName/main/release/shared/$sharedPrefix${baseName}_api.h",
|
"build/bin/$nativeHostTargetName/main/release/shared/$sharedPrefix${baseName}_api.h",
|
||||||
"build/bin/$hostTargetName/main/debug/static/$staticPrefix${baseName}_api.h",
|
"build/bin/$nativeHostTargetName/main/debug/static/$staticPrefix${baseName}_api.h",
|
||||||
"build/bin/$hostTargetName/main/release/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(
|
val linkTasks = listOf(
|
||||||
":linkMainDebugShared$taskSuffix",
|
":linkMainDebugShared$taskSuffix",
|
||||||
":linkMainReleaseShared$taskSuffix",
|
":linkMainReleaseShared$taskSuffix",
|
||||||
@@ -523,13 +517,6 @@ class NewMultiplatformIT : BaseGradleIT() {
|
|||||||
build("publish") {
|
build("publish") {
|
||||||
assertSuccessful()
|
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 groupDir = projectDir.resolve("repo/com/example/")
|
||||||
val targetArtifactIdAppendices = listOf("metadata", "jvm6", "nodejs", "wasm32", nativeHostTargetName)
|
val targetArtifactIdAppendices = listOf("metadata", "jvm6", "nodejs", "wasm32", nativeHostTargetName)
|
||||||
|
|
||||||
@@ -546,4 +533,22 @@ class NewMultiplatformIT : BaseGradleIT() {
|
|||||||
assertEquals(setOf("commonMain", "${nativeHostTargetName}Main"), sourceJarSourceRoots[nativeHostTargetName])
|
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,
|
createDefaultSourceSets = true,
|
||||||
createTestCompilation = true
|
createTestCompilation = true
|
||||||
) {
|
) {
|
||||||
|
private val hostTargets = listOf(KonanTarget.LINUX_X64, KonanTarget.MACOS_X64, KonanTarget.MINGW_X64)
|
||||||
|
|
||||||
private val Collection<*>.isDimensionVisible: Boolean
|
private val Collection<*>.isDimensionVisible: Boolean
|
||||||
get() = size > 1
|
get() = size > 1
|
||||||
@@ -400,7 +401,8 @@ open class KotlinNativeTargetConfigurator(
|
|||||||
val testTask = tasks.create(taskName, RunTestExecutable::class.java).apply {
|
val testTask = tasks.create(taskName, RunTestExecutable::class.java).apply {
|
||||||
group = LifecycleBasePlugin.VERIFICATION_GROUP
|
group = LifecycleBasePlugin.VERIFICATION_GROUP
|
||||||
description = "Executes Kotlin/Native unit tests from the '${compilation.name}' compilation " +
|
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
|
val testExecutableProperty = testExecutableLinkTask.outputFile
|
||||||
executable = testExecutableProperty.get().absolutePath
|
executable = testExecutableProperty.get().absolutePath
|
||||||
@@ -495,7 +497,7 @@ open class KotlinNativeTargetConfigurator(
|
|||||||
outputKind = compilerOutputKind
|
outputKind = compilerOutputKind
|
||||||
group = BasePlugin.BUILD_GROUP
|
group = BasePlugin.BUILD_GROUP
|
||||||
description = "Links ${kind.description} from the '${compilation.name}' " +
|
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
|
enabled = compilation.target.konanTarget.enabledOnCurrentHost
|
||||||
|
|
||||||
optimized = buildType.optimized
|
optimized = buildType.optimized
|
||||||
@@ -508,7 +510,7 @@ open class KotlinNativeTargetConfigurator(
|
|||||||
|
|
||||||
if (compilation.isTestCompilation &&
|
if (compilation.isTestCompilation &&
|
||||||
buildType == NativeBuildType.DEBUG &&
|
buildType == NativeBuildType.DEBUG &&
|
||||||
konanTarget == HostManager.host
|
konanTarget in hostTargets
|
||||||
) {
|
) {
|
||||||
// TODO: Refactor and move into the corresponding method of AbstractKotlinTargetConfigurator.
|
// TODO: Refactor and move into the corresponding method of AbstractKotlinTargetConfigurator.
|
||||||
createTestTask(compilation, linkTask)
|
createTestTask(compilation, linkTask)
|
||||||
@@ -549,7 +551,7 @@ open class KotlinNativeTargetConfigurator(
|
|||||||
outputKind = CompilerOutputKind.LIBRARY
|
outputKind = CompilerOutputKind.LIBRARY
|
||||||
group = BasePlugin.BUILD_GROUP
|
group = BasePlugin.BUILD_GROUP
|
||||||
description = "Compiles a klibrary from the '${compilation.name}' " +
|
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
|
enabled = compilation.target.konanTarget.enabledOnCurrentHost
|
||||||
|
|
||||||
registerOutputFiles(klibOutputDirectory(compilation))
|
registerOutputFiles(klibOutputDirectory(compilation))
|
||||||
|
|||||||
+3
@@ -289,6 +289,9 @@ class KotlinNativeTargetPreset(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal val KonanTarget.isCurrentHost: Boolean
|
||||||
|
get() = this == HostManager.host
|
||||||
|
|
||||||
internal val KonanTarget.enabledOnCurrentHost
|
internal val KonanTarget.enabledOnCurrentHost
|
||||||
get() = HostManager().isEnabled(this)
|
get() = HostManager().isEnabled(this)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user