Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 75b5834

Browse files
authored
Fixed tests not found error in native (#5068)
Fixed tests not found error in native Fixes #5029 Fixes #5053
1 parent 70f2581 commit 75b5834

File tree

6 files changed

+18
-90
lines changed

6 files changed

+18
-90
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ android.enableJetifier=true
3434
# Kotest build settings
3535
# enabled/disable Kotlin targets, for improving local dev & CI/CD performance
3636
kotest_enableKotlinJs=true
37-
kotest_enableKotlinNative=false
37+
kotest_enableKotlinNative=true

kotest-framework/kotest-framework-engine/src/jvmMain/java/io/kotest/engine/errors/handleEngineError.jvm.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
package io.kotest.engine.errors
44

55
import io.kotest.engine.EngineResult
6-
import kotlin.system.exitProcess
6+
import io.kotest.engine.extensions.MultipleExceptions
77

88
actual fun handleEngineResult(result: EngineResult) {
9-
exitProcess(1)
9+
if (result.testFailures) {
10+
error("Tests failed")
11+
}
12+
if (result.errors.isNotEmpty()) {
13+
throw MultipleExceptions(result.errors)
14+
}
1015
}

kotest-framework/kotest-framework-engine/src/nativeMain/kotlin/io/kotest/engine/errors/handleEngineError.native.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,13 @@
33
package io.kotest.engine.errors
44

55
import io.kotest.engine.EngineResult
6-
import kotlin.system.exitProcess
6+
import io.kotest.engine.extensions.MultipleExceptions
77

88
actual fun handleEngineResult(result: EngineResult) {
9-
exitProcess(1)
9+
if (result.testFailures) {
10+
error("Tests failed")
11+
}
12+
if (result.errors.isNotEmpty()) {
13+
throw MultipleExceptions(result.errors)
14+
}
1015
}

kotest-framework/kotest-framework-plugin-gradle/src/main/kotlin/io/kotest/framework/gradle/KotestPlugin.kt

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -207,21 +207,6 @@ abstract class KotestPlugin : Plugin<Project> {
207207
// we need to switch to TCSM format if running inside of intellij
208208
val listener = if (IntellijUtils.isIntellij()) "teamcity" else "console"
209209
existing.environment("KOTEST_FRAMEWORK_RUNTIME_NATIVE_LISTENER", listener)
210-
211-
// it seems the kotlin native test task empties this directory, so this currently does not do anything
212-
existing.environment(
213-
"KOTEST_FRAMEWORK_RUNTIME_NATIVE_MODULE_TEST_REPORTS_DIR",
214-
moduleTestDirAbsolutePath
215-
)
216-
217-
existing.environment(
218-
"KOTEST_FRAMEWORK_RUNTIME_NATIVE_ROOT_TEST_REPORTS_DIR",
219-
rootTestDirAbsolutePath
220-
)
221-
222-
// this sets the target name in the environment, which is used by the xml report generator
223-
// to add the target name to the test names
224-
existing.environment("KOTEST_FRAMEWORK_RUNTIME_NATIVE_TARGET", targetName)
225210
}
226211

227212
// the ksp plugin will create a configuration for each target that contains
@@ -230,6 +215,7 @@ abstract class KotestPlugin : Plugin<Project> {
230215
// do it for every different native target (there could be many!)
231216
wireKsp(target.project, kspConfigurationName(target))
232217

218+
// wire in the kmp test task into our kotest task
233219
target.project.tasks.getByName(KOTEST_TASK_NAME) {
234220
target.project.logger.info("> Configuring kotest task for $nativeTaskName")
235221
dependsOn(existing)

kotest-framework/kotest-framework-plugin-gradle/src/main/kotlin/io/kotest/framework/gradle/NativeExecConfiguration.kt

Lines changed: 0 additions & 62 deletions
This file was deleted.

kotest-framework/kotest-framework-symbol-processor/src/jvmMain/kotlin/io/kotest/framework/symbol/processor/NativeGenerator.kt

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,9 @@ class NativeGenerator(private val environment: SymbolProcessorEnvironment) {
3737
"""
3838
val includeArg = getenv("KOTEST_FRAMEWORK_RUNTIME_NATIVE_INCLUDE")?.toKString()
3939
val listenerType = getenv("KOTEST_FRAMEWORK_RUNTIME_NATIVE_LISTENER")?.toKString() ?: ""
40-
val moduleTestReportsDir = getenv("KOTEST_FRAMEWORK_RUNTIME_NATIVE_MODULE_TEST_REPORTS_DIR")?.toKString()
41-
val rootTestReportsDir = getenv("KOTEST_FRAMEWORK_RUNTIME_NATIVE_ROOT_TEST_REPORTS_DIR")?.toKString()
42-
val target = getenv("KOTEST_FRAMEWORK_RUNTIME_NATIVE_TARGET")?.toKString()
4340
4441
val descriptor = includeArg?.let { DescriptorPaths.parse(it) }
4542
val filter = descriptor?.let { IncludeDescriptorFilter(it) }
46-
val moduleXmlReporter = moduleTestReportsDir?.let { JunitXmlReportTestEngineListener(it, null, target) }
47-
val rootXmlReporter = rootTestReportsDir?.let { JunitXmlReportTestEngineListener(it, null, target) }
4843
4944
""".trim()
5045
)
@@ -53,9 +48,8 @@ val rootXmlReporter = rootTestReportsDir?.let { JunitXmlReportTestEngineListener
5348
"""
5449
val launcher = TestEngineLauncher()
5550
.withNative()
51+
.withTeamCityListener() // TCSM is always included to hook into the native test task reporting
5652
.addExtensions(listOfNotNull(filter))
57-
.withListener(moduleXmlReporter)
58-
.withListener(rootXmlReporter)
5953
.withSpecRefs(
6054
""".trim()
6155
).addCode("\n")
@@ -76,7 +70,7 @@ val launcher = TestEngineLauncher()
7670
function.addCode(
7771
"""
7872
val result = when (listenerType) {
79-
"teamcity" -> launcher.withTeamCityListener().launch()
73+
"teamcity" -> launcher.launch()
8074
else -> launcher.withConsoleListener().launch()
8175
}
8276
handleEngineResult(result)

0 commit comments

Comments
 (0)