diff --git a/native/kotlin-test-native-xctest/src/nativeMain/kotlin/configuration.kt b/native/kotlin-test-native-xctest/src/nativeMain/kotlin/configuration.kt index 879435f0dc5..2a9cc8c3a2c 100644 --- a/native/kotlin-test-native-xctest/src/nativeMain/kotlin/configuration.kt +++ b/native/kotlin-test-native-xctest/src/nativeMain/kotlin/configuration.kt @@ -8,6 +8,7 @@ import kotlinx.cinterop.* import kotlin.native.internal.test.* import platform.Foundation.NSInvocation import platform.Foundation.NSBundle +import platform.Foundation.NSProcessInfo import platform.Foundation.NSStringFromSelector import platform.XCTest.* import platform.objc.* @@ -47,7 +48,7 @@ internal fun setupXCTestSuite(): XCTestSuite { // Set test observer that will log test execution XCTestObservationCenter.sharedTestObservationCenter.addTestObserver(NativeTestObserver(testSettings)) - if (testSettings.runTests == true) { + if (testSettings.runTests) { // Generate and add tests to the main suite testSettings.testSuites.generate().forEach { nativeTestSuite.addTest(it) @@ -66,17 +67,29 @@ internal fun setupXCTestSuite(): XCTestSuite { /** * Gets test arguments from the Info.plist using the provided key to create test settings. * - * @param key a key used in the `Info.plist` file to pass test arguments + * @param key a key used in the `Info.plist` file or as environment variable to pass test arguments */ +@Suppress("UNCHECKED_CAST") private fun testArguments(key: String): Array { + (NSProcessInfo.processInfo.arguments as? List)?.let { + // Drop the first element containing executable name. + // See https://developer.apple.com/documentation/foundation/nsprocessinfo/1415596-arguments + return it.drop(1).toTypedArray() + } + + (NSProcessInfo.processInfo.environment[key] as? String)?.let { + return it.split(" ").toTypedArray() + } + // As we don't know which bundle we are, iterate through all of them - val plistTestArgs = NSBundle.allBundles - .mapNotNull { - (it as? NSBundle)?.infoDictionary?.get(key) - }.singleOrNull() as? String - return plistTestArgs?.split(" ") - ?.toTypedArray() - ?: emptyArray() + NSBundle.allBundles + .mapNotNull { (it as? NSBundle)?.infoDictionary?.get(key) as? String } + .singleOrNull() + ?.let { + return it.split(" ").toTypedArray() + } + + return emptyArray() } internal val testMethodsNames: List