diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts index 264a06b5..93e65370 100644 --- a/buildSrc/build.gradle.kts +++ b/buildSrc/build.gradle.kts @@ -153,7 +153,6 @@ fun org.gradle.api.publish.maven.MavenPom.configureForFladle(pluginName: String) tasks.withType(Test::class.java).configureEach { // Test fixtures are stored in here so we should re-run tests if the test projects change. inputs.dir("src/test/resources") - maxParallelForks = Runtime.getRuntime().availableProcessors() testLogging { events = setOf(TestLogEvent.SKIPPED, TestLogEvent.FAILED, TestLogEvent.PASSED) } diff --git a/buildSrc/src/main/java/com/osacky/flank/gradle/FladleConfigImpl.kt b/buildSrc/src/main/java/com/osacky/flank/gradle/FladleConfigImpl.kt index 05e2a0c5..b8c21d3f 100644 --- a/buildSrc/src/main/java/com/osacky/flank/gradle/FladleConfigImpl.kt +++ b/buildSrc/src/main/java/com/osacky/flank/gradle/FladleConfigImpl.kt @@ -49,7 +49,14 @@ data class FladleConfigImpl( override val legacyJunitResult: Property, override val fullJunitResult: Property ) : FladleConfig { - fun sanityRoboRun() { + /** + * Prepare config to run sanity robo. + * + * Sets [sanityRobo] property as `true`. + * + * Cleans [instrumentationApk], [additionalTestApks], [roboDirectives], [roboScript] properties. + */ + fun clearPropertiesForSanityRobo() { sanityRobo.set(true) additionalTestApks.empty() instrumentationApk.set("") diff --git a/buildSrc/src/main/java/com/osacky/flank/gradle/SanityConfigValidation.kt b/buildSrc/src/main/java/com/osacky/flank/gradle/SanityConfigValidation.kt index 0588ce13..5539bbb7 100644 --- a/buildSrc/src/main/java/com/osacky/flank/gradle/SanityConfigValidation.kt +++ b/buildSrc/src/main/java/com/osacky/flank/gradle/SanityConfigValidation.kt @@ -6,38 +6,25 @@ import org.gradle.api.provider.Property @Throws(GradleException::class) fun checkIfSanityAndValidateConfigs(config: FladleConfig) = when (config) { - is FlankGradleExtension -> config.checkAndValidateExtension() - is FladleConfigImpl -> config.checkAndValidateConfig() - else -> throw GradleException("Unable to check for sanity, check config type") -} - -private fun FlankGradleExtension.checkAndValidateExtension() { - if (sanityRobo.getOrElse(false)) when { - instrumentationApk.isNotPresentOrBlank -> throwBaseConfigError("instrumentationApk") - additionalTestApks.isNotPresentOrEmpty -> throwBaseConfigError("additionalTestApks") - roboDirectives.isNotPresentOrEmpty -> throwBaseConfigError("roboDirectives") - roboScript.isNotPresentOrBlank -> throwBaseConfigError("roboScript") + is FlankGradleExtension -> config.checkAndValidateConfig() { option, _ -> + "Incorrect [base] configuration. [$option] can't be used together with sanityRobo." + } + is FladleConfigImpl -> config.checkAndValidateConfig(config.name) { option, name -> + "Incorrect [$name] configuration. [$option] can't be used together with sanityRobo. " + + "If you want to launch robo test run without robo script place only clearPropertiesForSanityRobo() into [$name] configuration" } + else -> throw GradleException("Unable to check for sanity, check config type") } -private fun FladleConfigImpl.checkAndValidateConfig() { +private fun FladleConfig.checkAndValidateConfig(name: String = "base", message: (String, String) -> String) { if (sanityRobo.getOrElse(false)) when { - roboDirectives.isNotPresentOrEmpty -> throwAdditionalConfigError("roboDirectives", name) - roboScript.isNotPresentOrBlank -> throwAdditionalConfigError("roboScript", name) - instrumentationApk.isNotPresentOrBlank -> throwAdditionalConfigError("instrumentationApk", name) - additionalTestApks.isNotPresentOrEmpty -> throwAdditionalConfigError("additionalTestApks", name) + roboDirectives.isNotPresentOrEmpty -> throw GradleException(message("roboDirectives", name)) + roboScript.isNotPresentOrBlank -> throw GradleException(message("roboScript", name)) + instrumentationApk.isNotPresentOrBlank -> throw GradleException(message("instrumentationApk", name)) + additionalTestApks.isNotPresentOrEmpty -> throw GradleException(message("additionalTestApks", name)) } } -private fun throwBaseConfigError(option: String): Nothing = - throw GradleException("Incorrect [base] configuration. [$option] can't be used together with sanityRobo.") - -private fun throwAdditionalConfigError(option: String, name: String): Nothing = - throw GradleException( - "Incorrect [$name] configuration. [$option] can't be used together with sanityRobo. " + - "If you want to launch robo test run without robo script place only sanityRoboRun() into [$name] configuration" - ) - private val Property.isNotPresentOrBlank get() = orNull.isNullOrBlank().not() diff --git a/buildSrc/src/main/java/com/osacky/flank/gradle/YamlWriter.kt b/buildSrc/src/main/java/com/osacky/flank/gradle/YamlWriter.kt index 74fa98a8..1a2b7d5c 100644 --- a/buildSrc/src/main/java/com/osacky/flank/gradle/YamlWriter.kt +++ b/buildSrc/src/main/java/com/osacky/flank/gradle/YamlWriter.kt @@ -28,8 +28,8 @@ internal class YamlWriter { } val shouldPrintTestAndRobo = config.sanityRobo.get().not() - val additionalProperties = writeAdditionalProperties(config, shouldPrintTestAndRobo) - val flankProperties = writeFlankProperties(config, shouldPrintTestAndRobo) + val additionalProperties = writeAdditionalProperties(config) + val flankProperties = writeFlankProperties(config) return buildString { appendln("gcloud:") @@ -44,7 +44,7 @@ internal class YamlWriter { } } - internal fun writeFlankProperties(config: FladleConfig, printApk: Boolean = true): String = buildString { + internal fun writeFlankProperties(config: FladleConfig): String = buildString { appendln("flank:") appendProperty(config.testShards, name = "max-test-shards") @@ -54,7 +54,7 @@ internal class YamlWriter { appendProperty(config.projectId, name = "project") appendProperty(config.keepFilePath, name = "keep-file-path") appendListProperty(config.filesToDownload, name = "files-to-download") { appendln(" - $it") } - if (printApk) + if (!config.sanityRobo.get()) appendListProperty(config.additionalTestApks, name = "additional-app-test-apks") { appendln(" $it") } appendProperty(config.runTimeout, name = "run-timeout") appendProperty(config.ignoreFailedTests, name = "ignore-failed-tests") @@ -67,7 +67,7 @@ internal class YamlWriter { appendProperty(config.outputStyle, name = "output-style") } - internal fun writeAdditionalProperties(config: FladleConfig, printRobo: Boolean = true): String = buildString { + internal fun writeAdditionalProperties(config: FladleConfig): String = buildString { appendProperty(config.useOrchestrator, name = "use-orchestrator") appendProperty(config.autoGoogleLogin, name = "auto-google-login") appendProperty(config.recordVideo, name = "record-video") @@ -87,7 +87,7 @@ internal class YamlWriter { appendMapProperty(config.clientDetails, name = "client-details") { appendln(" ${it.key}: ${it.value}") } appendMapProperty(config.otherFiles, name = "other-files") { appendln(" ${it.key}: ${it.value}") } appendProperty(config.networkProfile, name = "network-profile") - if (printRobo) { + if (!config.sanityRobo.get()) { appendProperty(config.roboScript, name = "robo-script") appendListProperty(config.roboDirectives, name = "robo-directives") { val value = it.getOrElse(2) { "" }.let { stringValue -> if (stringValue.isBlank()) "\"\"" else stringValue } diff --git a/buildSrc/src/test/java/com/osacky/flank/gradle/integration/SanityRoboTest.kt b/buildSrc/src/test/java/com/osacky/flank/gradle/integration/SanityRoboTest.kt index a905ed6a..e1127cff 100644 --- a/buildSrc/src/test/java/com/osacky/flank/gradle/integration/SanityRoboTest.kt +++ b/buildSrc/src/test/java/com/osacky/flank/gradle/integration/SanityRoboTest.kt @@ -7,7 +7,7 @@ import org.junit.Test import org.junit.rules.TemporaryFolder private fun baseConfigMessage(option: String) = "Incorrect [base] configuration. [$option] can't be used together with sanityRobo." -private fun additionalConfigMessage(option: String, name: String) = "Incorrect [$name] configuration. [$option] can't be used together with sanityRobo. If you want to launch robo test run without robo script place only sanityRoboRun() into [$name] configuration" +private fun additionalConfigMessage(option: String, name: String) = "Incorrect [$name] configuration. [$option] can't be used together with sanityRobo. If you want to launch robo test run without robo script place only clearPropertiesForSanityRobo() into [$name] configuration" class SanityRoboTest { @get:Rule @@ -33,7 +33,6 @@ class SanityRoboTest { | instrumentationApk = "test.apk" | configs { | sanity { - | sanityRobo.set(true) | makeSanityRun() | } | } @@ -171,7 +170,7 @@ class SanityRoboTest { | ] | configs { | sanity { - | sanityRobo.set(true) + | clearPropertiesForSanityRobo() | roboScript.set("path/to/script.json") | } | } @@ -219,7 +218,7 @@ class SanityRoboTest { | ] | configs { | orange { - | sanityRoboRun() + | clearPropertiesForSanityRobo() | } | } |} diff --git a/buildSrc/src/test/java/com/osacky/flank/gradle/integration/SanityWithAutoConfigureTest.kt b/buildSrc/src/test/java/com/osacky/flank/gradle/integration/SanityWithAutoConfigureTest.kt index ee30b0fd..f9edfb2a 100644 --- a/buildSrc/src/test/java/com/osacky/flank/gradle/integration/SanityWithAutoConfigureTest.kt +++ b/buildSrc/src/test/java/com/osacky/flank/gradle/integration/SanityWithAutoConfigureTest.kt @@ -64,7 +64,7 @@ class SanityWithAutoConfigureTest { smartFlankGcsPath = "gs://test-lab-yr9w6qsdvy45q-iurp80dm95h8a/flank/test_app_android.xml" configs { sanity { - sanityRoboRun() + clearPropertiesForSanityRobo() useOrchestrator.set(false) testTargets.set(project.provider { [ "class com.osacky.flank.gradle.sample.ExampleInstrumentedTest#runAndFail"