From bcff85fab481c8b40a0b4e0564241e2f92c92f39 Mon Sep 17 00:00:00 2001 From: Pawel Pasterz Date: Fri, 25 Sep 2020 11:44:40 +0200 Subject: [PATCH] PR review changes --- .../com/osacky/flank/gradle/YamlWriter.kt | 8 +- .../gradle/integration/SanityRoboCheck.kt | 78 +++++++++++-------- .../flank/gradle/integration/TestFixtures.kt | 12 +-- 3 files changed, 52 insertions(+), 46 deletions(-) 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 7ee8f76c..55b238f7 100644 --- a/buildSrc/src/main/java/com/osacky/flank/gradle/YamlWriter.kt +++ b/buildSrc/src/main/java/com/osacky/flank/gradle/YamlWriter.kt @@ -9,12 +9,14 @@ internal class YamlWriter { check(base.serviceAccountCredentials.isPresent) { "ServiceAccountCredentials in fladle extension not set. https://github.com/runningcode/fladle#serviceaccountcredentials" } } check(base.debugApk.isPresent) { "debugApk must be specified" } - check(base.sanityRobo.get() == true || (base.instrumentationApk.isPresent xor !base.roboScript.isNullOrBlank())) { - """ + if (base.sanityRobo.get() == false) { + check(base.instrumentationApk.isPresent xor !base.roboScript.isNullOrBlank()) { + """ Either instrumentationApk file or roboScript file must be specified but not both. instrumentationApk=${base.instrumentationApk.orNull} roboScript=${base.roboScript} - """.trimIndent() + """.trimIndent() + } } val shouldPrintTestAndRobo = base.sanityRobo.get().not() diff --git a/buildSrc/src/test/java/com/osacky/flank/gradle/integration/SanityRoboCheck.kt b/buildSrc/src/test/java/com/osacky/flank/gradle/integration/SanityRoboCheck.kt index 1b69f9ee..0f5f4c1c 100644 --- a/buildSrc/src/test/java/com/osacky/flank/gradle/integration/SanityRoboCheck.kt +++ b/buildSrc/src/test/java/com/osacky/flank/gradle/integration/SanityRoboCheck.kt @@ -14,9 +14,11 @@ class SanityRoboCheck { fun setUp() = testProjectRoot.newFile("flank-gradle-service.json").writeText("{}") @Test - fun checkSanityRoboRunSimpleCase() { - makeGradleFile(where = testProjectRoot) { - """ + fun checkSanityRoboRunWithProjectProperty() { + makeGradleFile( + where = testProjectRoot, + buildScript = + """ |plugins { | id "com.osacky.fladle" |} @@ -26,12 +28,12 @@ class SanityRoboCheck { | debugApk = "foo.apk" |} """ - } + ) - val result = gradleRun { - arguments = listOf("writeConfigProps", "-PsanityRobo") + val result = gradleRun( + arguments = listOf("writeConfigProps", "-PsanityRobo"), projectDir = testProjectRoot.root - } + ) assertThat(result.output).contains("SUCCESS") @@ -64,8 +66,10 @@ class SanityRoboCheck { @Test fun checkSanityRoboRunWithApksAdded() { - makeGradleFile(where = testProjectRoot) { - """ + makeGradleFile( + where = testProjectRoot, + buildScript = + """ |plugins { | id "com.osacky.fladle" |} @@ -81,12 +85,12 @@ class SanityRoboCheck { | ] |} """ - } + ) - val result = gradleRun { - arguments = listOf("writeConfigProps", "-PsanityRobo") + val result = gradleRun( + arguments = listOf("writeConfigProps", "-PsanityRobo"), projectDir = testProjectRoot.root - } + ) assertThat(result.output).contains("SUCCESS") @@ -119,8 +123,10 @@ class SanityRoboCheck { @Test fun checkSanityRoboRunMultipleConfigs() { - makeGradleFile(where = testProjectRoot) { - """ + makeGradleFile( + where = testProjectRoot, + buildScript = + """ |plugins { | id "com.osacky.fladle" |} @@ -142,12 +148,12 @@ class SanityRoboCheck { | } |} """ - } + ) - val result = gradleRun { - arguments = listOf("writeConfigProps", "-PsanityRobo") + val result = gradleRun( + arguments = listOf("writeConfigProps", "-PsanityRobo"), projectDir = testProjectRoot.root - } + ) assertThat(result.output).contains("SUCCESS") @@ -177,10 +183,10 @@ class SanityRoboCheck { """ } - val resultOrange = gradleRun { - arguments = listOf("writeConfigPropsOrange", "-PsanityRobo") + val resultOrange = gradleRun( + arguments = listOf("writeConfigPropsOrange", "-PsanityRobo"), projectDir = testProjectRoot.root - } + ) assertThat(resultOrange.output).contains("SUCCESS") @@ -216,8 +222,10 @@ class SanityRoboCheck { @Test fun checkSanityRoboRunRoboScript() { - makeGradleFile(where = testProjectRoot) { - """ + makeGradleFile( + where = testProjectRoot, + buildScript = + """ |plugins { | id "com.osacky.fladle" |} @@ -228,12 +236,12 @@ class SanityRoboCheck { | roboScript = "some/path/script.json" |} """ - } + ) - val result = gradleRun { - arguments = listOf("writeConfigProps", "-PsanityRobo") + val result = gradleRun( + arguments = listOf("writeConfigProps", "-PsanityRobo"), projectDir = testProjectRoot.root - } + ) assertThat(result.output).contains("SUCCESS") @@ -266,8 +274,10 @@ class SanityRoboCheck { @Test fun checkSanityRoboRunRoboDirectives() { - makeGradleFile(where = testProjectRoot) { - """ + makeGradleFile( + where = testProjectRoot, + buildScript = + """ |plugins { | id "com.osacky.fladle" |} @@ -282,12 +292,12 @@ class SanityRoboCheck { | ] |} """ - } + ) - val result = gradleRun { - arguments = listOf("writeConfigProps", "-PsanityRobo") + val result = gradleRun( + arguments = listOf("writeConfigProps", "-PsanityRobo"), projectDir = testProjectRoot.root - } + ) assertThat(result.output).contains("SUCCESS") diff --git a/buildSrc/src/test/java/com/osacky/flank/gradle/integration/TestFixtures.kt b/buildSrc/src/test/java/com/osacky/flank/gradle/integration/TestFixtures.kt index c2c6e865..37c3ee3f 100644 --- a/buildSrc/src/test/java/com/osacky/flank/gradle/integration/TestFixtures.kt +++ b/buildSrc/src/test/java/com/osacky/flank/gradle/integration/TestFixtures.kt @@ -8,20 +8,14 @@ fun TemporaryFolder.setupFixture(fixtureName: String) { File(this::class.java.classLoader.getResource(fixtureName)!!.file).copyRecursively(newFile(fixtureName), true) } -internal fun makeGradleFile(where: TemporaryFolder, stringProvider: () -> String) = where +internal fun makeGradleFile(where: TemporaryFolder, buildScript: String) = where .newFile("build.gradle") - .writeText(stringProvider().trimMargin()) + .writeText(buildScript.trimMargin()) -internal fun gradleRun(block: GradleRunFladle.() -> Unit) = GradleRunFladle().apply(block).run { +internal fun gradleRun(projectDir: File, arguments: List = emptyList()) = GradleRunner.create() .withPluginClasspath() .withArguments(arguments) .forwardOutput() .withProjectDir(projectDir) .build() -} - -internal data class GradleRunFladle( - var arguments: List = emptyList(), - var projectDir: File? = null -)