Skip to content
This repository has been archived by the owner on Dec 7, 2019. It is now read-only.

Commit

Permalink
Added the ability to pass in device ids to filter the execution on th…
Browse files Browse the repository at this point in the history
…ose devices only (#85)
  • Loading branch information
jurenovic authored and ming13 committed Jul 25, 2017
1 parent d115821 commit 773e5f1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 3 deletions.
14 changes: 12 additions & 2 deletions composer/src/main/kotlin/com/gojuno/composer/Args.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ data class Args(
val shard: Boolean,
val outputDirectory: String,
val instrumentationArguments: List<Pair<String, String>>,
val verboseOutput: Boolean
val verboseOutput: Boolean,
val devices: List<String>
)

// No way to share array both for runtime and annotation without reflection.
Expand Down Expand Up @@ -86,6 +87,14 @@ private class JCommanderArgs {
description = "Either `true` or `false` to enable/disable verbose output for Swarmer. `false` by default."
)
var verboseOutput: Boolean? = null

@Parameter(
names = arrayOf("--devices"),
required = false,
variableArity = true,
description = "Connected devices/emulators that will be used to run tests against. If not passed — tests will run on all connected devices/emulators. Usage example: `--devices emulator-5554 emulator-5556`."
)
var devices: List<String>? = null
}

fun parseArgs(rawArgs: Array<String>): Args {
Expand Down Expand Up @@ -119,7 +128,8 @@ fun parseArgs(rawArgs: Array<String>): Args {
}
}
},
verboseOutput = jCommanderArgs.verboseOutput ?: false
verboseOutput = jCommanderArgs.verboseOutput ?: false,
devices = jCommanderArgs.devices ?: emptyList()
)
}
}
Expand Down
6 changes: 6 additions & 0 deletions composer/src/main/kotlin/com/gojuno/composer/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ fun main(rawArgs: Array<String>) {
val gson = Gson()

val suites: List<Suite> = connectedAdbDevices()
.map {
when (args.devices.isEmpty()) {
true -> it
false -> it.filter { args.devices.contains(it.id) }
}
}
.map {
it.filter { it.online }.apply {
if (isEmpty()) {
Expand Down
27 changes: 26 additions & 1 deletion composer/src/test/kotlin/com/gojuno/composer/ArgsSpec.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ class ArgsSpec : Spek({
shard = true,
outputDirectory = "composer-output",
instrumentationArguments = emptyList(),
verboseOutput = false
verboseOutput = false,
devices = emptyList()
))
}
}
Expand Down Expand Up @@ -78,4 +79,28 @@ class ArgsSpec : Spek({
}
}
}

context("parse args with passed --devices") {

val args by memoized {
parseArgs(rawArgsWithOnlyRequiredFields + arrayOf("--devices", "emulator-5554"))
}

it("parses correctly device ids") {
assertThat(args.devices).isEqualTo(listOf("emulator-5554"))
}

}

context("parse args with passed two --devices") {

val args by memoized {
parseArgs(rawArgsWithOnlyRequiredFields + arrayOf("--devices", "emulator-5554", "emulator-5556"))
}

it("parses correctly two device ids") {
assertThat(args.devices).isEqualTo(listOf("emulator-5554", "emulator-5556"))
}

}
})

0 comments on commit 773e5f1

Please sign in to comment.