From e136ff0fb9a41625324a0ebb7b86d3db5bd31d63 Mon Sep 17 00:00:00 2001 From: Oleg Smirnov Date: Fri, 28 Jul 2023 15:13:31 +0400 Subject: [PATCH] Fix test suites running for ios target (#21) --- build.gradle.kts | 1 + test-suites/build.gradle.kts | 13 +++++++++++ .../schema/suite/AbstractSchemaTestSuite.kt | 22 ++++++------------- 3 files changed, 21 insertions(+), 15 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 43bef10d..f5e9007f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -49,6 +49,7 @@ kotlin { val macOsTargets = listOf( macosX64(), macosArm64(), + iosX64(), iosArm64(), iosSimulatorArm64(), ) diff --git a/test-suites/build.gradle.kts b/test-suites/build.gradle.kts index 74cfc3ff..bbb0a5d8 100644 --- a/test-suites/build.gradle.kts +++ b/test-suites/build.gradle.kts @@ -1,6 +1,8 @@ import io.gitlab.arturbosch.detekt.Detekt import org.jetbrains.kotlin.gradle.plugin.KotlinTarget import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests +import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest +import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest import org.jlleitschuh.gradle.ktlint.reporter.ReporterType @Suppress("DSL_SCOPE_VIOLATION") // TODO: remove when migrate to Gradle 8 @@ -34,6 +36,7 @@ kotlin { val macOsTargets = listOf( macosX64(), macosArm64(), + iosX64(), iosArm64(), iosSimulatorArm64(), ) @@ -115,6 +118,16 @@ kotlin { } } +tasks.withType { + // This is used to pass the right location for Node.js test + environment("TEST_SUITES_DIR", "$projectDir/schema-test-suite/tests") +} + +tasks.withType { + // prefix SIMCTL_CHILD_ is used to pass the env variable to the simulator + environment("SIMCTL_CHILD_TEST_SUITES_DIR", "$projectDir/schema-test-suite/tests") +} + ktlint { version.set(libs.versions.ktlint) reporters { diff --git a/test-suites/src/commonTest/kotlin/io/github/optimumcode/json/schema/suite/AbstractSchemaTestSuite.kt b/test-suites/src/commonTest/kotlin/io/github/optimumcode/json/schema/suite/AbstractSchemaTestSuite.kt index 14ea9430..87d117f4 100644 --- a/test-suites/src/commonTest/kotlin/io/github/optimumcode/json/schema/suite/AbstractSchemaTestSuite.kt +++ b/test-suites/src/commonTest/kotlin/io/github/optimumcode/json/schema/suite/AbstractSchemaTestSuite.kt @@ -6,6 +6,7 @@ import io.kotest.assertions.throwables.shouldNotThrowAny import io.kotest.assertions.withClue import io.kotest.core.spec.style.FunSpec import io.kotest.matchers.shouldBe +import io.kotest.mpp.env import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.Serializable import kotlinx.serialization.builtins.ListSerializer @@ -50,10 +51,12 @@ internal fun FunSpec.runTestSuites( val testSuiteDir = when { fs.exists(TEST_SUITES_DIR) -> TEST_SUITES_DIR fs.exists(TEST_SUITES_DIR_FROM_ROOT) -> TEST_SUITES_DIR_FROM_ROOT - else -> fs.resolveRoot() + else -> env(TEST_SUITES_DIR_ENV_VAR)?.toPath() }?.resolve(draftName) - ?: error("neither $TEST_SUITES_DIR or $TEST_SUITES_DIR_FROM_ROOT exist " + - "(current dir: ${fs.canonicalize(".".toPath())})") + ?: error( + "neither $TEST_SUITES_DIR or $TEST_SUITES_DIR_FROM_ROOT exist " + + "(current dir: ${fs.canonicalize(".".toPath())}, env: ${env(TEST_SUITES_DIR_ENV_VAR)})", + ) require(fs.exists(testSuiteDir)) { "folder $testSuiteDir does not exist" } @@ -134,17 +137,6 @@ private class SchemaTest( private val TEST_SUITES_DIR: Path = "schema-test-suite/tests".toPath() private val TEST_SUITES_DIR_FROM_ROOT: Path = "test-suites".toPath() / TEST_SUITES_DIR - -/** - * This function tries to find the repo root using `build` folder as maker. - * - * This is done in order to execute NodeJS tests - */ -private fun FileSystem.resolveRoot(): Path? { - val absolutePath = canonicalize(".".toPath()) - return generateSequence(absolutePath) { - it.parent - }.find { it.name == "build" }?.parent?.resolve(TEST_SUITES_DIR_FROM_ROOT) -} +private const val TEST_SUITES_DIR_ENV_VAR: String = "TEST_SUITES_DIR" expect fun fileSystem(): FileSystem \ No newline at end of file