diff --git a/release_notes.md b/release_notes.md index 1221e810be..fa2828492a 100644 --- a/release_notes.md +++ b/release_notes.md @@ -1,6 +1,7 @@ ## next (unreleased) - [#567](https://github.com/TestArmada/flank/pull/567) Fix `--app` & `--test` on Android CLI. ([bootstraponline](https://github.com/bootstraponline)) +- [#571](https://github.com/TestArmada/flank/pull/571) Add `flank ios run --dump-shards` and `flank android run --dump-shards` for debugging ([bootstraponline](https://github.com/bootstraponline)) ## v6.2.2 diff --git a/test_runner/.gitignore b/test_runner/.gitignore index d2320fa139..15975e37b1 100644 --- a/test_runner/.gitignore +++ b/test_runner/.gitignore @@ -6,3 +6,4 @@ EarlGreyExample/ xctestrun/ src/test/kotlin/ftl/fixtures/error_result/*.xml src/test/kotlin/ftl/fixtures/success_result/*.xml +*.json diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/AndroidRunCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/AndroidRunCommand.kt index 9ca94226d8..141d67e7a4 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/AndroidRunCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/AndroidRunCommand.kt @@ -1,6 +1,7 @@ package ftl.cli.firebase.test.android import ftl.args.AndroidArgs +import ftl.args.AndroidTestShard import ftl.args.yml.AppTestPair import ftl.config.Device import ftl.config.FtlConstants @@ -9,7 +10,9 @@ import ftl.config.FtlConstants.defaultAndroidVersion import ftl.config.FtlConstants.defaultLocale import ftl.config.FtlConstants.defaultOrientation import ftl.run.TestRunner +import java.nio.file.Files import java.nio.file.Paths +import kotlin.system.exitProcess import kotlinx.coroutines.runBlocking import picocli.CommandLine.Command import picocli.CommandLine.Option @@ -32,11 +35,26 @@ class AndroidRunCommand : Runnable { override fun run() { val config = AndroidArgs.load(Paths.get(configPath), cli = this) + + if (dumpShards) { + val testShardChunks = AndroidTestShard.getTestShardChunks(config, config.testApk) + val testShardChunksJson = TestRunner.gson.toJson(testShardChunks) + val shardFile = "android_shards.json" + Files.write(Paths.get(shardFile), testShardChunksJson.toByteArray()) + println("Saved shards to $shardFile") + exitProcess(0) + } + runBlocking { TestRunner.newRun(config) } } + // Flank debug + + @Option(names = ["--dump-shards"], description = ["Dumps the shards to ios_shards.json for debugging"]) + var dumpShards: Boolean = false + // Flank specific @Option( diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/IosRunCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/IosRunCommand.kt index d786ec701c..8db2391d75 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/IosRunCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/IosRunCommand.kt @@ -6,7 +6,9 @@ import ftl.config.FtlConstants import ftl.config.FtlConstants.defaultIosModel import ftl.config.FtlConstants.defaultIosVersion import ftl.run.TestRunner +import java.nio.file.Files import java.nio.file.Paths +import kotlin.system.exitProcess import kotlinx.coroutines.runBlocking import picocli.CommandLine.Command import picocli.CommandLine.Option @@ -28,11 +30,25 @@ Configuration is read from flank.yml class IosRunCommand : Runnable { override fun run() { val config = IosArgs.load(Paths.get(configPath), cli = this) + + if (dumpShards) { + val testShardChunksJson = TestRunner.gson.toJson(config.testShardChunks) + val shardFile = "ios_shards.json" + Files.write(Paths.get(shardFile), testShardChunksJson.toByteArray()) + println("Saved shards to $shardFile") + exitProcess(0) + } + runBlocking { TestRunner.newRun(config) } } + // Flank debug + + @Option(names = ["--dump-shards"], description = ["Dumps the shards to ios_shards.json for debugging"]) + var dumpShards: Boolean = false + // Flank specific @Option( diff --git a/test_runner/src/main/kotlin/ftl/ios/Xctestrun.kt b/test_runner/src/main/kotlin/ftl/ios/Xctestrun.kt index 5b3a34672f..55e9186689 100644 --- a/test_runner/src/main/kotlin/ftl/ios/Xctestrun.kt +++ b/test_runner/src/main/kotlin/ftl/ios/Xctestrun.kt @@ -76,7 +76,7 @@ object Xctestrun { // Finds tests in a xctestrun file private fun findTestNames(xctestrun: File): List { val root = parse(xctestrun) - var result = listOf() + val result = mutableListOf() // EarlGreyExampleSwiftTests_iphoneos11.3-arm64.xctestrun => EarlGreyExampleSwiftTests val testRoot = xctestrun.parent + "/" diff --git a/test_runner/src/main/kotlin/ftl/run/TestRunner.kt b/test_runner/src/main/kotlin/ftl/run/TestRunner.kt index d62500ffae..665c5c11d6 100644 --- a/test_runner/src/main/kotlin/ftl/run/TestRunner.kt +++ b/test_runner/src/main/kotlin/ftl/run/TestRunner.kt @@ -39,7 +39,7 @@ import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking object TestRunner { - private val gson = GsonBuilder().setPrettyPrinting().create()!! + val gson = GsonBuilder().setPrettyPrinting().create()!! fun assertMockUrl() { if (!FtlConstants.useMock) return diff --git a/test_runner/src/test/kotlin/ftl/cli/firebase/test/android/AndroidRunCommandTest.kt b/test_runner/src/test/kotlin/ftl/cli/firebase/test/android/AndroidRunCommandTest.kt index 0687251090..1a50f8a018 100644 --- a/test_runner/src/test/kotlin/ftl/cli/firebase/test/android/AndroidRunCommandTest.kt +++ b/test_runner/src/test/kotlin/ftl/cli/firebase/test/android/AndroidRunCommandTest.kt @@ -61,6 +61,7 @@ class AndroidRunCommandTest { fun empty_params_parse_null() { val cmd = AndroidRunCommand() CommandLine(cmd).parse() + assertThat(cmd.dumpShards).isFalse() assertThat(cmd.app).isNull() assertThat(cmd.test).isNull() assertThat(cmd.testTargets).isNull() @@ -358,4 +359,12 @@ class AndroidRunCommandTest { val expected = AppTestPair(app = "a", test = "b") assertThat(cmd.additionalAppTestApks).isEqualTo(listOf(expected)) } + + @Test + fun `dump-shards parse`() { + val cmd = AndroidRunCommand() + CommandLine(cmd).parse("--dump-shards=true") + + assertThat(cmd.dumpShards).isEqualTo(true) + } } diff --git a/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/IosRunCommandTest.kt b/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/IosRunCommandTest.kt index a002475647..4b5f5b91fa 100644 --- a/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/IosRunCommandTest.kt +++ b/test_runner/src/test/kotlin/ftl/cli/firebase/test/ios/IosRunCommandTest.kt @@ -61,6 +61,7 @@ class IosRunCommandTest { fun empty_params_parse_null() { val cmd = IosRunCommand() CommandLine(cmd).parse() + assertThat(cmd.dumpShards).isFalse() assertThat(cmd.resultsBucket).isNull() assertThat(cmd.recordVideo).isNull() assertThat(cmd.noRecordVideo).isNull() @@ -273,4 +274,12 @@ class IosRunCommandTest { assertThat(cmd.smartFlankGcsPath).isEqualTo("foo") } + + @Test + fun `dump-shards parse`() { + val cmd = IosRunCommand() + CommandLine(cmd).parse("--dump-shards=true") + + assertThat(cmd.dumpShards).isEqualTo(true) + } }