From 1481419bb2620a0a316afb023247e8b282fc01c3 Mon Sep 17 00:00:00 2001 From: Ivan Balaksha Date: Sun, 6 Jan 2019 20:28:29 +0800 Subject: [PATCH 1/2] add check to ApplicationView (#146) --- .../kotlin/com/malinskiy/marathon/cli/ApplicationView.kt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cli/src/main/kotlin/com/malinskiy/marathon/cli/ApplicationView.kt b/cli/src/main/kotlin/com/malinskiy/marathon/cli/ApplicationView.kt index 35ca3fa73..69ed5ebdb 100644 --- a/cli/src/main/kotlin/com/malinskiy/marathon/cli/ApplicationView.kt +++ b/cli/src/main/kotlin/com/malinskiy/marathon/cli/ApplicationView.kt @@ -17,6 +17,7 @@ import com.malinskiy.marathon.cli.config.DeserializeModule import com.malinskiy.marathon.cli.config.time.InstantTimeProviderImpl import com.malinskiy.marathon.log.MarathonLogging import com.xenomachina.argparser.ArgParser +import com.xenomachina.argparser.SystemExitException import com.xenomachina.argparser.mainBody private val logger = MarathonLogging.logger {} @@ -39,6 +40,10 @@ fun main(args: Array): Unit = mainBody( val marathon = Marathon(configuration = configuration) UsageAnalytics.enable = this.analyticsTracking UsageAnalytics.tracker.trackEvent(Event(TrackActionType.RunType, "cli")) - marathon.run() + val success = marathon.run() + if (!success && !configuration.ignoreFailures) { + throw SystemExitException("Build failed", 1) + } + success } } From a1bb50776a216b58e1969753791c2a1f214ef50f Mon Sep 17 00:00:00 2001 From: Ivan Balaksha Date: Sun, 6 Jan 2019 20:29:11 +0800 Subject: [PATCH 2/2] Add -r adb install param (#147) * add test for FileAndroidConfiguration * simplify FileAndroidConfiguration * add -r flag as a default one * use kluent instead of kotlin test --- .../cli/args/FileAndroidConfiguration.kt | 33 +++------ .../cli/args/FileAndroidConfigurationSpek.kt | 71 +++++++++++++++++++ .../marathon/android/AndroidConfiguration.kt | 4 +- .../android/executor/AndroidAppInstaller.kt | 4 +- 4 files changed, 84 insertions(+), 28 deletions(-) create mode 100644 cli/src/test/kotlin/com/malinskiy/marathon/cli/args/FileAndroidConfigurationSpek.kt diff --git a/cli/src/main/kotlin/com/malinskiy/marathon/cli/args/FileAndroidConfiguration.kt b/cli/src/main/kotlin/com/malinskiy/marathon/cli/args/FileAndroidConfiguration.kt index 8751cab7f..738e53496 100644 --- a/cli/src/main/kotlin/com/malinskiy/marathon/cli/args/FileAndroidConfiguration.kt +++ b/cli/src/main/kotlin/com/malinskiy/marathon/cli/args/FileAndroidConfiguration.kt @@ -2,6 +2,7 @@ package com.malinskiy.marathon.cli.args import com.fasterxml.jackson.annotation.JsonProperty import com.malinskiy.marathon.android.AndroidConfiguration +import com.malinskiy.marathon.android.defaultInitTimeoutMillis import com.malinskiy.marathon.exceptions.ConfigurationException import java.io.File @@ -18,30 +19,12 @@ data class FileAndroidConfiguration(@JsonProperty("androidSdk") val androidSdk: ?: environmentAndroidSdk ?: throw ConfigurationException("No android SDK path specified") - if (autoGrantPermission != null && adbInitTimeoutMillis != null) { - return AndroidConfiguration( - finalAndroidSdk, - applicationOutput, - testApplicationOutput, - autoGrantPermission, - adbInitTimeoutMillis) - } else if(autoGrantPermission != null) { - return AndroidConfiguration( - finalAndroidSdk, - applicationOutput, - testApplicationOutput, - autoGrantPermission = autoGrantPermission) - } else if(adbInitTimeoutMillis != null) { - return AndroidConfiguration( - finalAndroidSdk, - applicationOutput, - testApplicationOutput, - adbInitTimeoutMillis = adbInitTimeoutMillis) - } else { - return AndroidConfiguration( - finalAndroidSdk, - applicationOutput, - testApplicationOutput) - } + return AndroidConfiguration( + androidSdk = finalAndroidSdk, + applicationOutput = applicationOutput, + testApplicationOutput = testApplicationOutput, + autoGrantPermission = autoGrantPermission ?: false, + adbInitTimeoutMillis = adbInitTimeoutMillis ?: defaultInitTimeoutMillis + ) } } diff --git a/cli/src/test/kotlin/com/malinskiy/marathon/cli/args/FileAndroidConfigurationSpek.kt b/cli/src/test/kotlin/com/malinskiy/marathon/cli/args/FileAndroidConfigurationSpek.kt new file mode 100644 index 000000000..533364a66 --- /dev/null +++ b/cli/src/test/kotlin/com/malinskiy/marathon/cli/args/FileAndroidConfigurationSpek.kt @@ -0,0 +1,71 @@ +package com.malinskiy.marathon.cli.args + +import com.malinskiy.marathon.exceptions.ConfigurationException +import org.amshove.kluent.shouldEqual +import org.amshove.kluent.shouldThrow +import org.jetbrains.spek.api.Spek +import org.jetbrains.spek.api.dsl.describe +import org.jetbrains.spek.api.dsl.it +import java.io.File + +object FileAndroidConfigurationSpek : Spek({ + describe("FileAndroidConfiguration") { + val configuration by memoized { + FileAndroidConfiguration( + null, + null, + File.createTempFile("foo", "bar"), + null, + null + ) + } + + val env = File.createTempFile("foo", "bar") + val sdk = File.createTempFile("android", "sdk") + + group("androidSdk is null") { + it("should throw Exception if env android sdk also is null") { + { configuration.toAndroidConfiguration(null) } shouldThrow ConfigurationException::class + } + it("should use env android sdk if it is not null") { + configuration.toAndroidConfiguration(env).androidSdk shouldEqual env + } + } + group("android sdk is not null") { + it("should use android sdk instead of env if both exists") { + configuration.copy(androidSdk = sdk).toAndroidConfiguration(env).androidSdk shouldEqual sdk + } + } + group("test application output") { + it("should be null by default") { + configuration.toAndroidConfiguration(env).applicationOutput shouldEqual null + } + it("should be null if provided") { + configuration.copy(applicationOutput = env).toAndroidConfiguration(env).applicationOutput shouldEqual env + } + } + group("test application apk") { + it("should be equal") { + configuration.copy(testApplicationOutput = env).toAndroidConfiguration(env).testApplicationOutput shouldEqual env + } + } + group("auto grant permissions") { + it("should be false by default") { + configuration.toAndroidConfiguration(env).autoGrantPermission shouldEqual false + } + it("should be equal") { + configuration.copy(autoGrantPermission = false).toAndroidConfiguration(env).autoGrantPermission shouldEqual false + configuration.copy(autoGrantPermission = true).toAndroidConfiguration(env).autoGrantPermission shouldEqual true + } + } + group("adb init timeout millis") { + it("should be 30_000 by default") { + configuration.toAndroidConfiguration(env).adbInitTimeoutMillis shouldEqual 30_000 + } + it("should be equal") { + val timeout = 500_000 + configuration.copy(adbInitTimeoutMillis = timeout).toAndroidConfiguration(env).adbInitTimeoutMillis shouldEqual timeout + } + } + } +}) diff --git a/vendor/vendor-android/src/main/kotlin/com/malinskiy/marathon/android/AndroidConfiguration.kt b/vendor/vendor-android/src/main/kotlin/com/malinskiy/marathon/android/AndroidConfiguration.kt index 30eb2cc0a..b114b6fde 100644 --- a/vendor/vendor-android/src/main/kotlin/com/malinskiy/marathon/android/AndroidConfiguration.kt +++ b/vendor/vendor-android/src/main/kotlin/com/malinskiy/marathon/android/AndroidConfiguration.kt @@ -5,11 +5,13 @@ import com.malinskiy.marathon.execution.TestParser import com.malinskiy.marathon.vendor.VendorConfiguration import java.io.File +const val defaultInitTimeoutMillis = 30_000 + data class AndroidConfiguration(val androidSdk: File, val applicationOutput: File?, val testApplicationOutput: File, val autoGrantPermission: Boolean = false, - val adbInitTimeoutMillis: Int = 30_000) : VendorConfiguration { + val adbInitTimeoutMillis: Int = defaultInitTimeoutMillis) : VendorConfiguration { override fun testParser(): TestParser? { return AndroidTestParser() diff --git a/vendor/vendor-android/src/main/kotlin/com/malinskiy/marathon/android/executor/AndroidAppInstaller.kt b/vendor/vendor-android/src/main/kotlin/com/malinskiy/marathon/android/executor/AndroidAppInstaller.kt index dc4f323af..ba65edcaf 100644 --- a/vendor/vendor-android/src/main/kotlin/com/malinskiy/marathon/android/executor/AndroidAppInstaller.kt +++ b/vendor/vendor-android/src/main/kotlin/com/malinskiy/marathon/android/executor/AndroidAppInstaller.kt @@ -54,9 +54,9 @@ class AndroidAppInstaller(configuration: Configuration) { private fun optionalParams(device: IDevice): String { return if (device.version.apiLevel >= MARSHMALLOW_VERSION_CODE && androidConfiguration.autoGrantPermission) { - "-g" + "-g -r" } else { - "" + "-r" } } } \ No newline at end of file