Skip to content

Commit

Permalink
feat(ios): implement xcodebuildTestArgs (#837)
Browse files Browse the repository at this point in the history
  • Loading branch information
Malinskiy authored Sep 6, 2023
1 parent 2541d11 commit ca7f42a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ sealed class VendorConfiguration {
@JsonProperty("hideRunnerOutput") val hideRunnerOutput: Boolean = false,
@JsonProperty("compactOutput") val compactOutput: Boolean = false,
@JsonProperty("rsync") val rsync: RsyncConfiguration = RsyncConfiguration(),

@JsonProperty("xcodebuildTestArgs") val xcodebuildTestArgs: Map<String, String> = emptyMap(),

@JsonProperty("signing") val signing: SigningConfiguration = SigningConfiguration(),
) : VendorConfiguration() {
fun validate() {
Expand Down
15 changes: 15 additions & 0 deletions docs/docs/ios/configure.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,21 @@ If you specify custom ones then your values will be placed as a lower priority p

:::

### xcodebuild test-without-building arguments
You can specify additional arguments to pass to the underlying `xcodebuild test-without-building` invocation.
```yaml
xcodebuildTestArgs:
"-test-timeouts-enabled": "YES"
"-maximum-test-execution-time-allowance": "60"
```

It is impossible to override the following reserved arguments:
- `-xctestrun`
- `-enableCodeCoverage`
- `-resultBundlePath`
- `-destination-timeout`
- `-destination`

### Test run lifecycle
Marathon provides two lifecycle hooks: `onPrepare` and `onDispose`.
For each you can specify one of the following actions: `SHUTDOWN` (shutdown simulator), `ERASE` (erase simulator) and `TERMINATE` (terminate simulator).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class Xcrun(
private val timeoutConfiguration = vendorConfiguration.timeoutConfiguration

val simctl = Simctl(commandExecutor, configuration, vendorConfiguration, gson)
val xcodebuild = Xcodebuild(commandExecutor, configuration, timeoutConfiguration)
val xcodebuild = Xcodebuild(commandExecutor, configuration, vendorConfiguration, timeoutConfiguration)
val xcresulttool = Xcresulttool(commandExecutor, timeoutConfiguration)

suspend fun getSdkPlatformPath(sdk: Sdk): String {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.malinskiy.marathon.ios.bin.xcrun.xcodebuild

import com.malinskiy.marathon.config.Configuration
import com.malinskiy.marathon.config.vendor.VendorConfiguration
import com.malinskiy.marathon.config.vendor.ios.TimeoutConfiguration
import com.malinskiy.marathon.ios.bin.xcrun.simctl.SimctlService
import com.malinskiy.marathon.ios.cmd.CommandExecutor
import com.malinskiy.marathon.ios.cmd.CommandSession
import com.malinskiy.marathon.ios.model.XcodeVersion
Expand All @@ -16,19 +16,34 @@ import java.time.Duration
class Xcodebuild(
private val commandExecutor: CommandExecutor,
private val configuration: Configuration,
private val vendorConfiguration: VendorConfiguration.IOSConfiguration,
private val timeoutConfiguration: TimeoutConfiguration,
) {
private val logger = MarathonLogging.logger {}

suspend fun testWithoutBuilding(udid: String, request: TestRequest): CommandSession {
val args = mutableMapOf<String, String>().apply {
putAll(vendorConfiguration.xcodebuildTestArgs)
put("-enableCodeCoverage", codeCoverageFlag(request))
put("-resultBundlePath", request.xcresult)
put("-destination-timeout", timeoutConfiguration.testDestination.seconds.toString())
put("-destination", "\'platform=iOS simulator,id=$udid\'")
}
.filterKeys { it != "-xctestrun" }
.toList()
.flatMap {
if (it.second.isNotEmpty()) {
listOf(it.first, it.second)
} else {
listOf(it.first)
}
}

val command = listOf(
"xcrun", "xcodebuild", "test-without-building",
"-xctestrun", request.remoteXctestrun,
*request.toXcodebuildTestFilter(),
"-enableCodeCoverage", codeCoverageFlag(request),
"-resultBundlePath", request.xcresult,
"-destination-timeout", timeoutConfiguration.testDestination.seconds.toString(),
"-destination", "\'platform=iOS simulator,id=$udid\'"
*args.toTypedArray(),
)
logger.debug { "Running ${command.joinToString(" ")}" }
return commandExecutor.execute(
Expand Down

0 comments on commit ca7f42a

Please sign in to comment.