[K/N] XCTest runner test arguments processing
Get test arguments from the process arguments and environment. There is the following order to get args: 1. Get from the process arguments. 2. If no arguments are specified, try to use process environment. 3. Get the KotlinNativeTestArgs key from the Info.plist. Part of the ^KT-58928
This commit is contained in:
committed by
Space Team
parent
42a982b400
commit
24c91bbf56
@@ -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<String> {
|
||||
(NSProcessInfo.processInfo.arguments as? List<String>)?.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<String>()
|
||||
NSBundle.allBundles
|
||||
.mapNotNull { (it as? NSBundle)?.infoDictionary?.get(key) as? String }
|
||||
.singleOrNull()
|
||||
?.let {
|
||||
return it.split(" ").toTypedArray()
|
||||
}
|
||||
|
||||
return emptyArray()
|
||||
}
|
||||
|
||||
internal val testMethodsNames: List<String>
|
||||
|
||||
Reference in New Issue
Block a user