Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR review changes
Browse files Browse the repository at this point in the history
pawelpasterz committed Sep 25, 2020
1 parent 5d9f30a commit bcff85f
Showing 3 changed files with 52 additions and 46 deletions.
8 changes: 5 additions & 3 deletions buildSrc/src/main/java/com/osacky/flank/gradle/YamlWriter.kt
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
@@ -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")

Original file line number Diff line number Diff line change
@@ -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<String> = emptyList()) =
GradleRunner.create()
.withPluginClasspath()
.withArguments(arguments)
.forwardOutput()
.withProjectDir(projectDir)
.build()
}

internal data class GradleRunFladle(
var arguments: List<String> = emptyList(),
var projectDir: File? = null
)

0 comments on commit bcff85f

Please sign in to comment.