jessewilson
07/28/2022, 2:25 PM~/Library/Developer/CoreSimulator/Devices/C641A553-AA3D-4FAD-4AE-8BDD0E346C5D/data
.
Anyone know of a way to recover the project directory when running a test in a simulator?Landry Norris
07/28/2022, 2:29 PMLandry Norris
07/28/2022, 2:30 PMval iosTestTasks = arrayOf("iosX64Test", "iosArm64Test").mapNotNull {
tasks.findByName(it)
}
iosTestTasks.forEach {
it.doFirst {
copy {
from(File(projectDir, "src/nativeTest/resources"))
into(File(buildDir, "bin/iosX64/debugTest/resources"))
}
}
}
and use an expect/actual that points to the proper directory on iOS.mbonnin
07/28/2022, 2:34 PMmbonnin
07/28/2022, 2:35 PMLandry Norris
07/28/2022, 2:37 PMjessewilson
07/28/2022, 2:47 PMjessewilson
07/28/2022, 3:17 PMGITHUB_WORKSPACE
directory to find my project in CI, but environment variables also don’t come across into the simulatorLandry Norris
07/28/2022, 3:18 PMJeff Lockhart
07/28/2022, 6:49 PMContext.assets.open()
and iOS NSBundle.mainBundle.pathForResource()
APIs. I created this youtrack to have the resources automatically copied for both test targets.Paul Woitaschek
07/28/2022, 7:01 PMPaul Woitaschek
07/28/2022, 7:03 PMtasks.withType<KotlinNativeTest> {
val frameworkDir = executable.parentFile
val copyResources = tasks.register<Sync>("copyResourcesFor${name.capitalize()}") {
from("src/appleTest/resources/BundleLocalizerTest.bundle")
into(File(frameworkDir, "BundleLocalizerTest.bundle"))
}
dependsOn(copyResources)
}
Paul Woitaschek
07/28/2022, 7:03 PMval bundlePath = NSBundle.mainBundle.resourcePath!!
val sharedResourceBundlePath = "$bundlePath/BundleLocalizerTest.bundle"
NSBundle(path = sharedResourceBundlePath)
Paul Woitaschek
07/28/2022, 7:05 PMJeff Lockhart
07/28/2022, 7:36 PMjessewilson
04/15/2023, 2:07 PMSIMCTL_CHILD_
. I also set it without that prefix for non-simulator builds:
tasks.withType<KotlinNativeTest>().configureEach {
// <https://stackoverflow.com/a/53604237/40013>
environment("SIMCTL_CHILD_OKHTTP_ICU_ROOT_DIR", rootDir)
environment("OKHTTP_ICU_ROOT_DIR", rootDir)
}
Lookup the environment variable during test execution:
val okhttpIcuRootDir = platform.posix.getenv("OKHTTP_ICU_ROOT_DIR")?.toKString()
And voila, we can pass the project directory to the simulator test process.jessewilson
04/15/2023, 2:08 PMPaul Woitaschek
04/15/2023, 2:10 PMjessewilson
04/16/2023, 2:07 AMPaul Woitaschek
04/16/2023, 8:09 AMjessewilson
04/16/2023, 11:02 AMPaul Woitaschek
04/16/2023, 11:04 AMjessewilson
04/16/2023, 11:05 AM