From ce463cce0448b021198ddf8e15ea0c0510156717 Mon Sep 17 00:00:00 2001 From: schlaubi Date: Mon, 29 Jan 2024 15:59:54 +0100 Subject: [PATCH] Fix resolution of test files on Kotlin/Native --- .../src/main/kotlin/kord-multiplatform-module.gradle.kts | 5 +++++ test-kit/src/nativeMain/kotlin/Platform.kt | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts b/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts index a5e9ef293fa..2a7963d404f 100644 --- a/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts +++ b/buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts @@ -2,6 +2,7 @@ import org.gradle.configurationcache.extensions.capitalized import org.jetbrains.dokka.gradle.AbstractDokkaLeafTask import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest +import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeTest plugins { org.jetbrains.kotlin.multiplatform @@ -84,6 +85,10 @@ tasks { environment("PROJECT_ROOT", rootProject.projectDir.absolutePath) } + withType().configureEach { + environment("PROJECT_ROOT", rootProject.projectDir.absolutePath) + } + afterEvaluate { val compilationTasks = kotlin.targets.flatMap { buildList { diff --git a/test-kit/src/nativeMain/kotlin/Platform.kt b/test-kit/src/nativeMain/kotlin/Platform.kt index 71d88fed0d8..4ae488eb3a6 100644 --- a/test-kit/src/nativeMain/kotlin/Platform.kt +++ b/test-kit/src/nativeMain/kotlin/Platform.kt @@ -26,13 +26,13 @@ actual object Platform { @OptIn(ExperimentalForeignApi::class) actual fun getEnv(name: String) = getenv(name)?.toKString() -actual suspend fun file(project: String, path: String): String = read(path, Source::readString) +actual suspend fun file(project: String, path: String): String = read(project, path, Source::readString) actual suspend fun readFile(project: String, path: String): ByteReadChannel = - read(path) { ByteReadChannel(readByteArray()) } + read(project, path) { ByteReadChannel(readByteArray()) } -private inline fun read(path: String, readerAction: Source.() -> T): T { - val actualPath = Path(path) +private inline fun read(project: String, path: String, readerAction: Source.() -> T): T { + val actualPath = Path("${getEnv("PROJECT_ROOT")}/$project/src/commonTest/resources/$path") return try { SystemFileSystem.source(actualPath).buffered().readerAction() } catch (e: Throwable) {