From 4e6ff783bb1983333b5e391e0b1158c264d5cafe Mon Sep 17 00:00:00 2001 From: Cristian Garcia Date: Tue, 17 May 2022 01:24:05 +0200 Subject: [PATCH] Verify DSL compatibility with groovy (#25) --- build.gradle.kts | 2 +- .../kotlin/io/github/flank/gradle/Device.kt | 8 +- src/test/kotlin/DslCompatibility.kt | 155 ++++++++++++++++++ 3 files changed, 162 insertions(+), 3 deletions(-) create mode 100644 src/test/kotlin/DslCompatibility.kt diff --git a/build.gradle.kts b/build.gradle.kts index 074e5f1..5a9a668 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,7 +6,7 @@ plugins { } group = "io.github.flank.gradle" -version = "0.2.0" +version = "0.2.1" repositories { google() diff --git a/src/main/kotlin/io/github/flank/gradle/Device.kt b/src/main/kotlin/io/github/flank/gradle/Device.kt index 0b45724..9c7a174 100644 --- a/src/main/kotlin/io/github/flank/gradle/Device.kt +++ b/src/main/kotlin/io/github/flank/gradle/Device.kt @@ -4,7 +4,9 @@ import org.gradle.api.tasks.Input import org.gradle.api.tasks.Internal import org.gradle.api.tasks.Optional -open class Device( +open class Device +@JvmOverloads +constructor( @Input val id: String, @Input val osVersion: Int, @Internal val make: String? = null, @@ -41,7 +43,9 @@ open class Device( override fun compareTo(other: Device): Int = comparator.compare(this, other) } -class NexusLowRes(osVersion: Int, locale: String? = null, orientation: Orientation? = null) : +class NexusLowRes +@JvmOverloads +constructor(osVersion: Int, locale: String? = null, orientation: Orientation? = null) : Device(id, osVersion, make, model, locale, orientation) { companion object : MinSdk { override val id = "NexusLowRes" diff --git a/src/test/kotlin/DslCompatibility.kt b/src/test/kotlin/DslCompatibility.kt new file mode 100644 index 0000000..11a644d --- /dev/null +++ b/src/test/kotlin/DslCompatibility.kt @@ -0,0 +1,155 @@ +import java.io.File +import org.junit.Test +import strikt.api.expectThat +import strikt.assertions.isNotNull +import strikt.gradle.testkit.isSuccess +import strikt.gradle.testkit.task + +class DslCompatibility : GradleTest() { + @Test + fun kotlinCompatibility() { + projectFromResources("app") + File(testProjectDir.root, "build.gradle.kts") + .appendText( + """ + simpleFlank { + // Changing the credentials file, default: rootProject.file("ftl-credentials.json") + credentialsFile.set(file("some-credentials.json")) + + // Making the tests cacheable + hermeticTests.set(true) + // if all modules have hermetic tests, add `simple-flank.hermeticTests=true` to your `gradle.properties` + + // Choosing the devices manually + // default is NexusLowRes, and the minSdk from the project + devices.set(listOf( + io.github.flank.gradle.NexusLowRes(23), + io.github.flank.gradle.NexusLowRes(30, "es_ES", io.github.flank.gradle.Device.Orientation.landscape), + io.github.flank.gradle.Device("oriole", 31, "Google", "Pixel 6") + )) + + // Filtering tests + testTargets { + inClass("io.flank.sample.TestClass") + notInClass("io.flank.sample.NotATestClass", "io.flank.sample.NotATestClassEither") + + small() // or medium() or large() + + annotation("io.flank.test.InstrumentationTest") + notAnnotation("io.flank.test.Flaky") + + inPackage("io.flank.sample") + notInPackage("io.flank.external") + + testFile("/sdcard/tmp/testFile.txt") + notTestFile("/sdcard/tmp/notTestFile.txt") + + regex("BarTest.*") + + filter("com.android.foo.MyCustomFilter", "com.android.foo.AnotherCustomFilter") + + runnerBuilder("com.android.foo.MyCustomBuilder", "com.android.foo.AnotherCustomBuilder") + } + + // EnvironmentVariables + // default + environmentVariables.set(mapOf("clearPackageData" to "true", "something" to "1", "whatever" to "I don't know")) + + // default extracted from credentials + projectId.set("my-GCP-project") + + // Downloading files + directoriesToPull.set(listOf("/sdcard/")) + filesToDownload.set(listOf("a.txt","b.txt")) + keepFilePath.set(true) + + + // other options + testTimeout.set("15m") + recordVideo.set(true) + numFlakyTestAttempts.set(3) + failFast.set(true) + performanceMetrics.set(true) + } + """.trimIndent()) + + val build = gradleRunner("flankDoctorDebug", "--stacktrace").forwardOutput().build() + + expectThat(build) { task(":flankDoctorDebug").isNotNull().isSuccess() } + } + + @Test + fun groovyCompatibility() { + projectFromResources("library") + File(testProjectDir.root, "build.gradle") + .appendText( + """ + simpleFlank { + // Changing the credentials file, default: rootProject.file("ftl-credentials.json") + credentialsFile = file("some-credentials.json") + + // Making the tests cacheable + hermeticTests = true + // if all modules have hermetic tests, add `simple-flank.hermeticTests=true` to your `gradle.properties` + + // Choosing the devices manually + // default is NexusLowRes, and the minSdk from the project + devices = [ + new io.github.flank.gradle.NexusLowRes(23), + new io.github.flank.gradle.NexusLowRes(30, "es_ES", io.github.flank.gradle.Device.Orientation.landscape), + new io.github.flank.gradle.Device("oriole", 31, "Google", "Pixel 6") + ] + + // Filtering tests + testTargets { + inClass("io.flank.sample.TestClass") + notInClass("io.flank.sample.NotATestClass", "io.flank.sample.NotATestClassEither") + + small() // or medium() or large() + + annotation("io.flank.test.InstrumentationTest") + notAnnotation("io.flank.test.Flaky") + + inPackage("io.flank.sample") + notInPackage("io.flank.external") + + testFile("/sdcard/tmp/testFile.txt") + notTestFile("/sdcard/tmp/notTestFile.txt") + + regex("BarTest.*") + + filter("com.android.foo.MyCustomFilter", "com.android.foo.AnotherCustomFilter") + + runnerBuilder("com.android.foo.MyCustomBuilder", "com.android.foo.AnotherCustomBuilder") + } + + // EnvironmentVariables + // default + environmentVariables = [ + clearPackageData: "true", + something: "1", + whatever: "I don't know" + ] + + // default extracted from credentials + projectId = "my-GCP-project" + + // Downloading files + directoriesToPull = ["/sdcard/"] + filesToDownload = ["a.txt","b.txt"] + keepFilePath = true + + // other options + testTimeout = "15m" + recordVideo = true + numFlakyTestAttempts = 3 + failFast = true + performanceMetrics = true + } + """.trimIndent()) + + val build = gradleRunner("flankDoctorDebug", "--stacktrace").forwardOutput().build() + + expectThat(build) { task(":flankDoctorDebug").isNotNull().isSuccess() } + } +}