Skip to content

Commit

Permalink
Merge branch 'develop' of github.com:Malinskiy/marathon into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
tagantroy committed Jan 6, 2019
2 parents 845a629 + a1bb507 commit bc489c2
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand All @@ -39,6 +40,10 @@ fun main(args: Array<String>): 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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
)
}
}
Original file line number Diff line number Diff line change
@@ -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
}
}
}
})
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}

0 comments on commit bc489c2

Please sign in to comment.