Skip to content

Commit

Permalink
Fix resolution of test files on Kotlin/Native
Browse files Browse the repository at this point in the history
  • Loading branch information
schlaubi authored and schlaubi committed Jan 29, 2024
1 parent c68a078 commit ce463cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions buildSrc/src/main/kotlin/kord-multiplatform-module.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -84,6 +85,10 @@ tasks {
environment("PROJECT_ROOT", rootProject.projectDir.absolutePath)
}

withType<KotlinNativeTest>().configureEach {
environment("PROJECT_ROOT", rootProject.projectDir.absolutePath)
}

afterEvaluate {
val compilationTasks = kotlin.targets.flatMap {
buildList {
Expand Down
8 changes: 4 additions & 4 deletions test-kit/src/nativeMain/kotlin/Platform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 <T> read(path: String, readerAction: Source.() -> T): T {
val actualPath = Path(path)
private inline fun <T> 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) {
Expand Down

0 comments on commit ce463cc

Please sign in to comment.