Skip to content

Commit e136ff0

Browse files
authored
Fix test suites running for ios target (#21)
1 parent 2a8b3a2 commit e136ff0

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

build.gradle.kts

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ kotlin {
4949
val macOsTargets = listOf<KotlinTarget>(
5050
macosX64(),
5151
macosArm64(),
52+
iosX64(),
5253
iosArm64(),
5354
iosSimulatorArm64(),
5455
)

test-suites/build.gradle.kts

+13
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import io.gitlab.arturbosch.detekt.Detekt
22
import org.jetbrains.kotlin.gradle.plugin.KotlinTarget
33
import org.jetbrains.kotlin.gradle.plugin.KotlinTargetWithTests
4+
import org.jetbrains.kotlin.gradle.targets.js.testing.KotlinJsTest
5+
import org.jetbrains.kotlin.gradle.targets.native.tasks.KotlinNativeSimulatorTest
46
import org.jlleitschuh.gradle.ktlint.reporter.ReporterType
57

68
@Suppress("DSL_SCOPE_VIOLATION") // TODO: remove when migrate to Gradle 8
@@ -34,6 +36,7 @@ kotlin {
3436
val macOsTargets = listOf<KotlinTarget>(
3537
macosX64(),
3638
macosArm64(),
39+
iosX64(),
3740
iosArm64(),
3841
iosSimulatorArm64(),
3942
)
@@ -115,6 +118,16 @@ kotlin {
115118
}
116119
}
117120

121+
tasks.withType<KotlinJsTest> {
122+
// This is used to pass the right location for Node.js test
123+
environment("TEST_SUITES_DIR", "$projectDir/schema-test-suite/tests")
124+
}
125+
126+
tasks.withType<KotlinNativeSimulatorTest> {
127+
// prefix SIMCTL_CHILD_ is used to pass the env variable to the simulator
128+
environment("SIMCTL_CHILD_TEST_SUITES_DIR", "$projectDir/schema-test-suite/tests")
129+
}
130+
118131
ktlint {
119132
version.set(libs.versions.ktlint)
120133
reporters {

test-suites/src/commonTest/kotlin/io/github/optimumcode/json/schema/suite/AbstractSchemaTestSuite.kt

+7-15
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import io.kotest.assertions.throwables.shouldNotThrowAny
66
import io.kotest.assertions.withClue
77
import io.kotest.core.spec.style.FunSpec
88
import io.kotest.matchers.shouldBe
9+
import io.kotest.mpp.env
910
import kotlinx.serialization.ExperimentalSerializationApi
1011
import kotlinx.serialization.Serializable
1112
import kotlinx.serialization.builtins.ListSerializer
@@ -50,10 +51,12 @@ internal fun FunSpec.runTestSuites(
5051
val testSuiteDir = when {
5152
fs.exists(TEST_SUITES_DIR) -> TEST_SUITES_DIR
5253
fs.exists(TEST_SUITES_DIR_FROM_ROOT) -> TEST_SUITES_DIR_FROM_ROOT
53-
else -> fs.resolveRoot()
54+
else -> env(TEST_SUITES_DIR_ENV_VAR)?.toPath()
5455
}?.resolve(draftName)
55-
?: error("neither $TEST_SUITES_DIR or $TEST_SUITES_DIR_FROM_ROOT exist " +
56-
"(current dir: ${fs.canonicalize(".".toPath())})")
56+
?: error(
57+
"neither $TEST_SUITES_DIR or $TEST_SUITES_DIR_FROM_ROOT exist " +
58+
"(current dir: ${fs.canonicalize(".".toPath())}, env: ${env(TEST_SUITES_DIR_ENV_VAR)})",
59+
)
5760

5861
require(fs.exists(testSuiteDir)) { "folder $testSuiteDir does not exist" }
5962

@@ -134,17 +137,6 @@ private class SchemaTest(
134137

135138
private val TEST_SUITES_DIR: Path = "schema-test-suite/tests".toPath()
136139
private val TEST_SUITES_DIR_FROM_ROOT: Path = "test-suites".toPath() / TEST_SUITES_DIR
137-
138-
/**
139-
* This function tries to find the repo root using `build` folder as maker.
140-
*
141-
* This is done in order to execute NodeJS tests
142-
*/
143-
private fun FileSystem.resolveRoot(): Path? {
144-
val absolutePath = canonicalize(".".toPath())
145-
return generateSequence(absolutePath) {
146-
it.parent
147-
}.find { it.name == "build" }?.parent?.resolve(TEST_SUITES_DIR_FROM_ROOT)
148-
}
140+
private const val TEST_SUITES_DIR_ENV_VAR: String = "TEST_SUITES_DIR"
149141

150142
expect fun fileSystem(): FileSystem

0 commit comments

Comments
 (0)