Gradle, native: Fix creating test binaries for non-host platforms
Issue #KT-31725 fixed
This commit is contained in:
+11
-3
@@ -1173,7 +1173,15 @@ class NewMultiplatformIT : BaseGradleIT() {
|
|||||||
// Check that test binaries can be accessed in a buildscript.
|
// Check that test binaries can be accessed in a buildscript.
|
||||||
build("checkNewGetters") {
|
build("checkNewGetters") {
|
||||||
assertSuccessful()
|
assertSuccessful()
|
||||||
listOf("test.$suffix", "another.$suffix").forEach {
|
val suffixes = listOf("exe", "kexe", "wasm")
|
||||||
|
val names = listOf("test", "another")
|
||||||
|
val files = names.flatMap { name ->
|
||||||
|
suffixes.map { suffix ->
|
||||||
|
"$name.$suffix"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
files.forEach {
|
||||||
assertContains("Get test: $it")
|
assertContains("Get test: $it")
|
||||||
assertContains("Find test: $it")
|
assertContains("Find test: $it")
|
||||||
}
|
}
|
||||||
@@ -1187,7 +1195,7 @@ class NewMultiplatformIT : BaseGradleIT() {
|
|||||||
|Probably you are accessing the default test binary using the 'binaries.getExecutable("test", DEBUG)' method.
|
|Probably you are accessing the default test binary using the 'binaries.getExecutable("test", DEBUG)' method.
|
||||||
|Since 1.3.40 tests are represented by a separate binary type. To get the default test binary, use:
|
|Since 1.3.40 tests are represented by a separate binary type. To get the default test binary, use:
|
||||||
|
|
|
|
||||||
| binaries.getTest(DEBUG)
|
| binaries.getTest("DEBUG")
|
||||||
""".trimMargin()
|
""".trimMargin()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -1199,7 +1207,7 @@ class NewMultiplatformIT : BaseGradleIT() {
|
|||||||
|Probably you are accessing the default test binary using the 'binaries.findExecutable("test", DEBUG)' method.
|
|Probably you are accessing the default test binary using the 'binaries.findExecutable("test", DEBUG)' method.
|
||||||
|Since 1.3.40 tests are represented by a separate binary type. To get the default test binary, use:
|
|Since 1.3.40 tests are represented by a separate binary type. To get the default test binary, use:
|
||||||
|
|
|
|
||||||
| binaries.findTest(DEBUG)
|
| binaries.findTest("DEBUG")
|
||||||
""".trimMargin()
|
""".trimMargin()
|
||||||
)
|
)
|
||||||
assertContains("Find test: null")
|
assertContains("Find test: null")
|
||||||
|
|||||||
+5
-2
@@ -25,7 +25,10 @@ kotlin {
|
|||||||
fromPreset(presets.linuxX64, 'linux64')
|
fromPreset(presets.linuxX64, 'linux64')
|
||||||
fromPreset(presets.mingwX64, 'mingw64')
|
fromPreset(presets.mingwX64, 'mingw64')
|
||||||
|
|
||||||
configure([macos64, linux64, mingw64]) {
|
// Test creating and accessing test binaries for cross-targets
|
||||||
|
fromPreset(presets.wasm32, 'wasm')
|
||||||
|
|
||||||
|
configure([macos64, linux64, mingw64, wasm]) {
|
||||||
compilations.create("anotherTest")
|
compilations.create("anotherTest")
|
||||||
binaries {
|
binaries {
|
||||||
test("another", [DEBUG]) {
|
test("another", [DEBUG]) {
|
||||||
@@ -68,7 +71,7 @@ task checkOldFind {
|
|||||||
task checkNewGetters {
|
task checkNewGetters {
|
||||||
doLast {
|
doLast {
|
||||||
kotlin.targets {
|
kotlin.targets {
|
||||||
configure([macos64, linux64, mingw64]) {
|
configure([macos64, linux64, mingw64, wasm]) {
|
||||||
println("Get test: ${binaries.getTest(DEBUG).outputFile.name}")
|
println("Get test: ${binaries.getTest(DEBUG).outputFile.name}")
|
||||||
println("Find test: ${binaries.findTest(DEBUG).outputFile.name}")
|
println("Find test: ${binaries.findTest(DEBUG).outputFile.name}")
|
||||||
println("Get test: ${binaries.getTest("another", DEBUG).outputFile.name}")
|
println("Get test: ${binaries.getTest("another", DEBUG).outputFile.name}")
|
||||||
|
|||||||
+2
-2
@@ -163,7 +163,7 @@ open class KotlinNativeBinaryContainer @Inject constructor(
|
|||||||
|Probably you are accessing the default test binary using the 'binaries.getExecutable("$DEFAULT_TEST_NAME_PREFIX", ${DEFAULT_TEST_BUILD_TYPE.name})' method.
|
|Probably you are accessing the default test binary using the 'binaries.getExecutable("$DEFAULT_TEST_NAME_PREFIX", ${DEFAULT_TEST_BUILD_TYPE.name})' method.
|
||||||
|Since 1.3.40 tests are represented by a separate binary type. To get the default test binary, use:
|
|Since 1.3.40 tests are represented by a separate binary type. To get the default test binary, use:
|
||||||
|
|
|
|
||||||
| binaries.getTest(DEBUG)
|
| binaries.getTest("DEBUG")
|
||||||
|
|
|
|
||||||
""".trimMargin()
|
""".trimMargin()
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ open class KotlinNativeBinaryContainer @Inject constructor(
|
|||||||
|Probably you are accessing the default test binary using the 'binaries.findExecutable("$DEFAULT_TEST_NAME_PREFIX", ${DEFAULT_TEST_BUILD_TYPE.name})' method.
|
|Probably you are accessing the default test binary using the 'binaries.findExecutable("$DEFAULT_TEST_NAME_PREFIX", ${DEFAULT_TEST_BUILD_TYPE.name})' method.
|
||||||
|Since 1.3.40 tests are represented by a separate binary type. To get the default test binary, use:
|
|Since 1.3.40 tests are represented by a separate binary type. To get the default test binary, use:
|
||||||
|
|
|
|
||||||
| binaries.findTest(DEBUG)
|
| binaries.findTest("DEBUG")
|
||||||
|
|
|
|
||||||
""".trimMargin()
|
""".trimMargin()
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-18
@@ -232,30 +232,31 @@ open class KotlinNativeTargetConfigurator(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun configureTest(target: KotlinNativeTarget): Unit = with(target.project) {
|
override fun configureTest(target: KotlinNativeTarget): Unit = with(target.project) {
|
||||||
// We don't create test tasks for non-host platforms.
|
// We create test binaries for all platforms.
|
||||||
if (target.konanTarget !in listOf(KonanTarget.MACOS_X64, KonanTarget.MINGW_X64, KonanTarget.LINUX_X64)) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
val taskName = lowerCamelCaseName(target.disambiguationClassifier, testTaskNameSuffix)
|
|
||||||
target.binaries.test(listOf(NativeBuildType.DEBUG)) {
|
target.binaries.test(listOf(NativeBuildType.DEBUG)) {
|
||||||
val testTask = createOrRegisterTask<KotlinNativeTest>(taskName) { testTask ->
|
|
||||||
testTask.group = LifecycleBasePlugin.VERIFICATION_GROUP
|
|
||||||
testTask.description = "Executes Kotlin/Native unit tests for target ${target.name}."
|
|
||||||
testTask.targetName = compilation.target.targetName
|
|
||||||
|
|
||||||
testTask.enabled = target.konanTarget.isCurrentHost
|
// But run them only on host ones.
|
||||||
|
if (target.konanTarget in listOf(KonanTarget.MACOS_X64, KonanTarget.MINGW_X64, KonanTarget.LINUX_X64)) {
|
||||||
|
|
||||||
testTask.executable { outputFile }
|
val taskName = lowerCamelCaseName(target.disambiguationClassifier, testTaskNameSuffix)
|
||||||
testTask.workingDir = project.projectDir.absolutePath
|
val testTask = createOrRegisterTask<KotlinNativeTest>(taskName) { testTask ->
|
||||||
|
testTask.group = LifecycleBasePlugin.VERIFICATION_GROUP
|
||||||
|
testTask.description = "Executes Kotlin/Native unit tests for target ${target.name}."
|
||||||
|
testTask.targetName = compilation.target.targetName
|
||||||
|
|
||||||
testTask.onlyIf { outputFile.exists() }
|
testTask.enabled = target.konanTarget.isCurrentHost
|
||||||
testTask.dependsOn(linkTaskName)
|
|
||||||
|
|
||||||
testTask.configureConventions()
|
testTask.executable { outputFile }
|
||||||
|
testTask.workingDir = project.projectDir.absolutePath
|
||||||
|
|
||||||
|
testTask.onlyIf { outputFile.exists() }
|
||||||
|
testTask.dependsOn(linkTaskName)
|
||||||
|
|
||||||
|
testTask.configureConventions()
|
||||||
|
}
|
||||||
|
|
||||||
|
kotlinTestRegistry.registerTestTask(testTask)
|
||||||
}
|
}
|
||||||
|
|
||||||
kotlinTestRegistry.registerTestTask(testTask)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user