From 859a2cefe04e9df2a7debf4b2c2a5e9d1ad7768c Mon Sep 17 00:00:00 2001 From: bootstraponline Date: Tue, 16 Apr 2019 12:04:34 -0400 Subject: [PATCH] Fix empty test targets (#544) --- .../src/main/kotlin/ftl/args/AndroidArgs.kt | 2 +- .../src/main/kotlin/ftl/args/ArgsToString.kt | 15 ++++++++++----- test_runner/src/main/kotlin/ftl/args/IosArgs.kt | 6 +++--- .../main/kotlin/ftl/args/yml/AndroidGcloudYml.kt | 2 +- .../src/main/kotlin/ftl/args/yml/IosFlankYml.kt | 2 +- .../main/kotlin/ftl/args/yml/YamlDeprecated.kt | 2 +- test_runner/src/main/kotlin/ftl/shard/Shard.kt | 4 ++-- .../src/test/kotlin/ftl/args/AndroidArgsTest.kt | 15 +++++++++++++++ .../src/test/kotlin/ftl/args/IosArgsTest.kt | 16 ++++++++++++++++ 9 files changed, 50 insertions(+), 14 deletions(-) diff --git a/test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt b/test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt index ce0053aadc..7970f6e450 100644 --- a/test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt +++ b/test_runner/src/main/kotlin/ftl/args/AndroidArgs.kt @@ -61,7 +61,7 @@ class AndroidArgs( val environmentVariables = cli?.environmentVariables ?: androidGcloud.environmentVariables val directoriesToPull = cli?.directoriesToPull ?: androidGcloud.directoriesToPull val performanceMetrics = cli?.performanceMetrics ?: cli?.noPerformanceMetrics?.not() ?: androidGcloud.performanceMetrics - val testTargets = cli?.testTargets ?: androidGcloud.testTargets + val testTargets = cli?.testTargets ?: androidGcloud.testTargets.filterNotNull() val devices = cli?.device ?: androidGcloud.device private val flank = flankYml.flank diff --git a/test_runner/src/main/kotlin/ftl/args/ArgsToString.kt b/test_runner/src/main/kotlin/ftl/args/ArgsToString.kt index 05a9fc35d0..f796400012 100644 --- a/test_runner/src/main/kotlin/ftl/args/ArgsToString.kt +++ b/test_runner/src/main/kotlin/ftl/args/ArgsToString.kt @@ -4,16 +4,21 @@ import ftl.config.Device object ArgsToString { - fun mapToString(map: Map): String { + fun mapToString(map: Map?): String { + if (map.isNullOrEmpty()) return "" return map.map { (key, value) -> " $key: $value" } .joinToString("\n") } - fun listToString(list: List): String { - return list.joinToString("\n") { dir -> " - $dir" } + fun listToString(list: List?): String { + if (list.isNullOrEmpty()) return "" + return list.filterNotNull() + .joinToString("\n") { dir -> " - $dir" } } - fun devicesToString(devices: List): String { - return devices.joinToString("\n") { "$it" } + fun devicesToString(devices: List?): String { + if (devices.isNullOrEmpty()) return "" + return devices.filterNotNull() + .joinToString("\n") { "$it" } } } diff --git a/test_runner/src/main/kotlin/ftl/args/IosArgs.kt b/test_runner/src/main/kotlin/ftl/args/IosArgs.kt index b3ac05d0d2..97634be143 100644 --- a/test_runner/src/main/kotlin/ftl/args/IosArgs.kt +++ b/test_runner/src/main/kotlin/ftl/args/IosArgs.kt @@ -60,7 +60,7 @@ class IosArgs( override val localResultDir = cli?.localResultsDir ?: flank.localResultDir private val iosFlank = iosFlankYml.flank - val testTargets = cli?.testTargets ?: iosFlank.testTargets + val testTargets = cli?.testTargets ?: iosFlank.testTargets.filterNotNull() // computed properties not specified in yaml override val testShardChunks: List> by lazy { @@ -166,13 +166,13 @@ ${listToString(testTargets)} } } -fun filterTests(validTestMethods: List, testTargetsRgx: List): List { +fun filterTests(validTestMethods: List, testTargetsRgx: List): List { if (testTargetsRgx.isEmpty()) { return validTestMethods } return validTestMethods.filter { test -> - testTargetsRgx.forEach { target -> + testTargetsRgx.filterNotNull().forEach { target -> try { if (test.matches(target.toRegex())) { return@filter true diff --git a/test_runner/src/main/kotlin/ftl/args/yml/AndroidGcloudYml.kt b/test_runner/src/main/kotlin/ftl/args/yml/AndroidGcloudYml.kt index 5d727c8034..48204892bd 100644 --- a/test_runner/src/main/kotlin/ftl/args/yml/AndroidGcloudYml.kt +++ b/test_runner/src/main/kotlin/ftl/args/yml/AndroidGcloudYml.kt @@ -33,7 +33,7 @@ class AndroidGcloudYmlParams( val performanceMetrics: Boolean = true, @field:JsonProperty("test-targets") - val testTargets: List = emptyList(), + val testTargets: List = emptyList(), val device: List = listOf(Device(defaultAndroidModel, defaultAndroidVersion)) ) { diff --git a/test_runner/src/main/kotlin/ftl/args/yml/IosFlankYml.kt b/test_runner/src/main/kotlin/ftl/args/yml/IosFlankYml.kt index 0838425555..f02560b3c0 100644 --- a/test_runner/src/main/kotlin/ftl/args/yml/IosFlankYml.kt +++ b/test_runner/src/main/kotlin/ftl/args/yml/IosFlankYml.kt @@ -7,7 +7,7 @@ import com.fasterxml.jackson.annotation.JsonProperty @JsonIgnoreProperties(ignoreUnknown = true) class IosFlankYmlParams( @field:JsonProperty("test-targets") - val testTargets: List = emptyList() + val testTargets: List = emptyList() ) { companion object : IYmlKeys { override val keys = listOf("test-targets") diff --git a/test_runner/src/main/kotlin/ftl/args/yml/YamlDeprecated.kt b/test_runner/src/main/kotlin/ftl/args/yml/YamlDeprecated.kt index 83501cd0ac..e4faad5516 100644 --- a/test_runner/src/main/kotlin/ftl/args/yml/YamlDeprecated.kt +++ b/test_runner/src/main/kotlin/ftl/args/yml/YamlDeprecated.kt @@ -119,7 +119,7 @@ object YamlDeprecated { if (fix) { Files.write(yamlPath, string.toByteArray()) - println("\nUpdated flank.yml file") + println("\nUpdated ${yamlPath.fileName} file") } return errorDetected } diff --git a/test_runner/src/main/kotlin/ftl/shard/Shard.kt b/test_runner/src/main/kotlin/ftl/shard/Shard.kt index 137c2e79ed..5f96f316f5 100644 --- a/test_runner/src/main/kotlin/ftl/shard/Shard.kt +++ b/test_runner/src/main/kotlin/ftl/shard/Shard.kt @@ -119,9 +119,9 @@ object Shard { shards = shards.sortedBy { it.time } } - val allTests = testsToRun.size + val allTests = testsToRun.size // zero when test targets is empty val cacheHit = allTests - cacheMiss - val cachePercent = cacheHit.toDouble() / allTests * 100.0 + val cachePercent = if (allTests == 0) 0.0 else cacheHit.toDouble() / allTests * 100.0 println() println(" Smart Flank cache hit: ${cachePercent.roundToInt()}% ($cacheHit / $allTests)") println(" Shard times: " + shards.joinToString(", ") { "${it.time.roundToInt()}s" } + "\n") diff --git a/test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt b/test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt index b93086fcb6..8b2ad00256 100644 --- a/test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt +++ b/test_runner/src/test/kotlin/ftl/args/AndroidArgsTest.kt @@ -75,6 +75,21 @@ class AndroidArgsTest { @JvmField var expectedException = ExpectedException.none()!! + @Test + fun empty_testTargets() { + val emptyTestTargets = """ + gcloud: + app: $appApk + test: $testApk + test-targets: + - + + """.trimIndent() + + val args = AndroidArgs.load(emptyTestTargets) + assertThat(args.testTargets.size).isEqualTo(0) + } + @Test fun androidArgs_invalidModel() { expectedException.expect(RuntimeException::class.java) diff --git a/test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt b/test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt index f07f5da41a..f46417e2a8 100644 --- a/test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt +++ b/test_runner/src/test/kotlin/ftl/args/IosArgsTest.kt @@ -75,6 +75,22 @@ class IosArgsTest { @JvmField val systemErrRule = SystemErrRule().muteForSuccessfulTests()!! + @Test + fun empty_testTargets() { + val emptyTestTargets = """ +gcloud: + test: "./src/test/kotlin/ftl/fixtures/tmp/ios_earlgrey2.zip" + xctestrun-file: "./src/test/kotlin/ftl/fixtures/tmp/EarlGreyExampleSwiftTests_iphoneos12.1-arm64e.xctestrun" +flank: + test-targets: + - + + """.trimIndent() + + val args = IosArgs.load(emptyTestTargets) + assertThat(args.testTargets.size).isEqualTo(0) + } + @Test fun args_invalidDeviceExits() { exceptionRule.expectMessage("iOS 99.9 on iphoneZ is not a supported device")