diff --git a/docs/index.md b/docs/index.md index 32a4095b0f..7bea0236b1 100644 --- a/docs/index.md +++ b/docs/index.md @@ -305,11 +305,12 @@ flank: ## The JUnit XML is used to determine failure. (default: false) # ignore-failed-tests: true - ### Output Style - ## Output style of execution status. May be one of [verbose, multi, single]. + ### Output Style flag + ## Output style of execution status. May be one of [verbose, multi, single, compact]. ## For runs with only one test execution the default value is 'verbose', in other cases ## 'multi' is used as the default. The output style 'multi' is not displayed correctly on consoles ## which don't support ansi codes, to avoid corrupted output use single or verbose. + ## The output style `compact` is used to produce less detailed output, it prints just Args, test and matrix count, weblinks, cost, and result reports. # output-style: single ### Full Junit Result flag @@ -650,10 +651,11 @@ flank: # legacy-junit-result: false ### Output Style flag - ## Output style of execution status. May be one of [verbose, multi, single]. + ## Output style of execution status. May be one of [verbose, multi, single, compact]. ## For runs with only one test execution the default value is 'verbose', in other cases ## 'multi' is used as the default. The output style 'multi' is not displayed correctly on consoles ## which don't support ansi codes, to avoid corrupted output use single or verbose. + ## The output style `compact` is used to produce less detailed output, it prints just Args, test and matrix count, weblinks, cost, and result reports. # output-style: single ### Full Junit Result flag diff --git a/docs/logging.md b/docs/logging.md new file mode 100644 index 0000000000..5becdfe8c3 --- /dev/null +++ b/docs/logging.md @@ -0,0 +1,7 @@ +# Logs in Flank + +1. Log level depends on the output style. +1. ```Simple, multi``` and ```verbose``` output style prints logs from ```SIMPLE``` and ```DETAILED``` levels. +1. ```Compact``` style prints log only from ```SIMPLE``` level. +1. If you want a print message for all output styles uses ```log``` or ```logLn``` with only ```message``` parameter. +1. If you want print message more detailed message use ```log``` or ```logLn``` and set ```level``` to ```OutputLogLevel.DETAILED``` diff --git a/test_runner/flank.ios.yml b/test_runner/flank.ios.yml index 2f80562215..67f66f8362 100644 --- a/test_runner/flank.ios.yml +++ b/test_runner/flank.ios.yml @@ -236,10 +236,11 @@ flank: # ignore-failed-tests: true ### Output Style - ## Output style of execution status. May be one of [verbose, multi, single]. + ## Output style of execution status. May be one of [verbose, multi, single, compact]. ## For runs with only one test execution the default value is 'verbose', in other cases ## 'multi' is used as the default. The output style 'multi' is not displayed correctly on consoles ## which don't support ansi codes, to avoid corrupted output use single or verbose. + ## The output style `compact` is used to produce less detailed output, it prints just Args, test and matrix count, weblinks, cost, and result reports. # output-style: single ### Full Junit Result flag diff --git a/test_runner/flank.yml b/test_runner/flank.yml index 9f985ba452..de262c2a7b 100644 --- a/test_runner/flank.yml +++ b/test_runner/flank.yml @@ -318,10 +318,11 @@ flank: # legacy-junit-result: false ### Output Style flag - ## Output style of execution status. May be one of [verbose, multi, single]. + ## Output style of execution status. May be one of [verbose, multi, single, compact]. ## For runs with only one test execution the default value is 'verbose', in other cases ## 'multi' is used as the default. The output style 'multi' is not displayed correctly on consoles ## which don't support ansi codes, to avoid corrupted output use single or verbose. + ## The output style `compact` is used to produce less detailed output, it prints just Args, test and matrix count, weblinks, cost, and result reports. # output-style: single ### Full Junit Result flag diff --git a/test_runner/src/main/kotlin/ftl/Main.kt b/test_runner/src/main/kotlin/ftl/Main.kt index 4380dd8ff4..466ad96d82 100644 --- a/test_runner/src/main/kotlin/ftl/Main.kt +++ b/test_runner/src/main/kotlin/ftl/Main.kt @@ -9,6 +9,7 @@ import ftl.cli.firebase.test.IPBlocksCommand import ftl.cli.firebase.test.IosCommand import ftl.cli.firebase.test.NetworkProfilesCommand import ftl.cli.firebase.test.ProvidedSoftwareCommand +import ftl.log.logLn import ftl.log.setDebugLogging import ftl.util.readRevision import ftl.util.readVersion @@ -53,9 +54,9 @@ class Main : Runnable { // Flank must invoke exitProcess to exit cleanly. // https://github.com/bugsnag/bugsnag-java/issues/151 withGlobalExceptionHandling { - println("version: " + readVersion()) - println("revision: " + readRevision()) - println() + logLn("version: " + readVersion()) + logLn("revision: " + readRevision()) + logLn() CommandLine(Main()).execute(*args) } } diff --git a/test_runner/src/main/kotlin/ftl/android/AndroidCatalog.kt b/test_runner/src/main/kotlin/ftl/android/AndroidCatalog.kt index 42ab2b2dda..09774cad00 100644 --- a/test_runner/src/main/kotlin/ftl/android/AndroidCatalog.kt +++ b/test_runner/src/main/kotlin/ftl/android/AndroidCatalog.kt @@ -10,6 +10,7 @@ import ftl.environment.common.asPrintableTable import ftl.environment.getLocaleDescription import ftl.gc.GcTesting import ftl.http.executeWithRetry +import ftl.log.logLn /** * Contains lists of possible Android device and version ids, as well as checks @@ -77,7 +78,7 @@ object AndroidCatalog { val form = deviceCatalog(projectId).models .find { it.id.equals(modelId, ignoreCase = true) }?.form ?: DeviceType.PHYSICAL.name.also { - println("Unable to find device type for $modelId. PHYSICAL used as fallback in cost calculations") + logLn("Unable to find device type for $modelId. PHYSICAL used as fallback in cost calculations") } return form.equals(DeviceType.VIRTUAL.name, ignoreCase = true) diff --git a/test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt b/test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt index 45192ed582..de79f070d8 100644 --- a/test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt +++ b/test_runner/src/main/kotlin/ftl/args/ArgsHelper.kt @@ -20,6 +20,7 @@ import ftl.config.credential import ftl.config.defaultCredentialPath import ftl.gc.GcStorage import ftl.gc.GcToolResults +import ftl.log.logLn import ftl.reports.xml.model.JUnitTestResult import ftl.run.exception.FlankConfigurationError import ftl.run.exception.FlankGeneralError @@ -171,7 +172,7 @@ object ArgsHelper { .build() ) } catch (e: Exception) { - println("Warning: Failed to make bucket for $projectId\nCause: ${e.message}") + logLn("Warning: Failed to make bucket for $projectId\nCause: ${e.message}") } return bucket @@ -187,8 +188,8 @@ object ArgsHelper { GenericJson::class.java )["project_id"] as String } catch (e: Exception) { - println("Parsing $defaultCredentialPath failed:") - println(e.printStackTrace()) + logLn("Parsing $defaultCredentialPath failed:") + logLn(e.printStackTrace()) } return null @@ -211,7 +212,7 @@ object ArgsHelper { val envName = matcher.group(1) val envValue: String? = System.getenv(envName) if (envValue == null) { - println("WARNING: $envName not found") + logLn("WARNING: $envName not found") } matcher.appendReplacement(buffer, envValue ?: "") } diff --git a/test_runner/src/main/kotlin/ftl/args/IArgs.kt b/test_runner/src/main/kotlin/ftl/args/IArgs.kt index f0b19dfbb5..c946e3faa0 100644 --- a/test_runner/src/main/kotlin/ftl/args/IArgs.kt +++ b/test_runner/src/main/kotlin/ftl/args/IArgs.kt @@ -3,6 +3,7 @@ package ftl.args import ftl.args.yml.Type import ftl.config.Device import ftl.config.common.CommonFlankConfig.Companion.defaultLocalResultsDir +import ftl.log.OutputLogLevel import ftl.run.status.OutputStyle import ftl.util.timeoutToMils @@ -82,3 +83,10 @@ interface IArgs { val validArgs: Map> } } + +val IArgs.logLevel + get() = if (outputStyle == OutputStyle.Compact) OutputLogLevel.SIMPLE else OutputLogLevel.DETAILED + +fun IArgs.setupLogLevel() = also { + ftl.log.setLogLevel(logLevel) +} diff --git a/test_runner/src/main/kotlin/ftl/args/ValidateAndroidArgs.kt b/test_runner/src/main/kotlin/ftl/args/ValidateAndroidArgs.kt index 130a2709c2..28db717fa8 100644 --- a/test_runner/src/main/kotlin/ftl/args/ValidateAndroidArgs.kt +++ b/test_runner/src/main/kotlin/ftl/args/ValidateAndroidArgs.kt @@ -9,6 +9,7 @@ import ftl.android.UnsupportedVersionId import ftl.args.yml.Type import ftl.config.containsPhysicalDevices import ftl.config.containsVirtualDevices +import ftl.log.logLn import ftl.run.exception.FlankConfigurationError import ftl.run.exception.FlankGeneralError import ftl.run.exception.IncompatibleTestDimensionError @@ -146,7 +147,7 @@ private fun AndroidArgs.assertMaxTestShardsByDeviceType() = } private fun AndroidArgs.assertDevicesShards() { - if (inVirtualRange && !inPhysicalRange) println("Physical devices configured, but max-test-shards limit set to $maxTestShards, for physical devices range is ${IArgs.AVAILABLE_PHYSICAL_SHARD_COUNT_RANGE.first} to ${IArgs.AVAILABLE_PHYSICAL_SHARD_COUNT_RANGE.last}, you additionally have configured virtual devices. In this case, the physical limit will be decreased to: ${IArgs.AVAILABLE_PHYSICAL_SHARD_COUNT_RANGE.last}") + if (inVirtualRange && !inPhysicalRange) logLn("Physical devices configured, but max-test-shards limit set to $maxTestShards, for physical devices range is ${IArgs.AVAILABLE_PHYSICAL_SHARD_COUNT_RANGE.first} to ${IArgs.AVAILABLE_PHYSICAL_SHARD_COUNT_RANGE.last}, you additionally have configured virtual devices. In this case, the physical limit will be decreased to: ${IArgs.AVAILABLE_PHYSICAL_SHARD_COUNT_RANGE.last}") else if (!inVirtualRange && !inPhysicalRange) throwMaxTestShardsLimitExceeded() } @@ -217,15 +218,15 @@ private fun AndroidArgs.assertOtherFiles() { private fun AndroidArgs.checkEnvironmentVariables() { if (environmentVariables.isNotEmpty() && directoriesToPull.isEmpty()) - println("WARNING: environment-variables set but directories-to-pull is empty, this will result in the coverage file not downloading to the bucket.") + logLn("WARNING: environment-variables set but directories-to-pull is empty, this will result in the coverage file not downloading to the bucket.") } private fun AndroidArgs.checkFilesToDownload() { if (filesToDownload.isNotEmpty() && directoriesToPull.isEmpty()) - println("WARNING: files-to-download is set but directories-to-pull is empty, the coverage file may fail to download into the bucket.") + logLn("WARNING: files-to-download is set but directories-to-pull is empty, the coverage file may fail to download into the bucket.") } private fun AndroidArgs.checkNumUniformShards() { if ((numUniformShards ?: 0) > 0 && disableSharding) - println("WARNING: disable-sharding is enabled with num-uniform-shards = $numUniformShards, Flank will ignore num-uniform-shards and disable sharding.") + logLn("WARNING: disable-sharding is enabled with num-uniform-shards = $numUniformShards, Flank will ignore num-uniform-shards and disable sharding.") } diff --git a/test_runner/src/main/kotlin/ftl/args/ValidateCommonArgs.kt b/test_runner/src/main/kotlin/ftl/args/ValidateCommonArgs.kt index 94cd7e80a4..66aad47df1 100644 --- a/test_runner/src/main/kotlin/ftl/args/ValidateCommonArgs.kt +++ b/test_runner/src/main/kotlin/ftl/args/ValidateCommonArgs.kt @@ -4,6 +4,7 @@ import ftl.config.Device import ftl.config.FtlConstants import ftl.config.defaultCredentialPath import ftl.gc.GcStorage +import ftl.log.logLn import ftl.reports.FullJUnitReport import ftl.reports.JUnitReport import ftl.run.exception.FlankConfigurationError @@ -72,10 +73,10 @@ private fun CommonArgs.assertSmartFlankGcsPath() = with(smartFlankGcsPath) { fun IArgs.checkResultsDirUnique() { if (useLegacyJUnitResult && GcStorage.exist(resultsBucket, resultsDir)) - println("WARNING: Google cloud storage result directory should be unique, otherwise results from multiple test matrices will be overwritten or intermingled\n") + logLn("WARNING: Google cloud storage result directory should be unique, otherwise results from multiple test matrices will be overwritten or intermingled\n") } fun IArgs.checkDisableSharding() { if (disableSharding && maxTestShards > 0) - println("WARNING: disable-sharding enabled with max-test-shards = $maxTestShards, Flank will ignore max-test-shard and disable sharding.") + logLn("WARNING: disable-sharding enabled with max-test-shards = $maxTestShards, Flank will ignore max-test-shard and disable sharding.") } 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 c8bac5b930..6ba0506a66 100644 --- a/test_runner/src/main/kotlin/ftl/args/yml/YamlDeprecated.kt +++ b/test_runner/src/main/kotlin/ftl/args/yml/YamlDeprecated.kt @@ -8,6 +8,7 @@ import com.fasterxml.jackson.databind.node.MissingNode import com.fasterxml.jackson.databind.node.ObjectNode import com.google.common.annotations.VisibleForTesting import ftl.args.ArgsHelper.yamlMapper +import ftl.log.logLn import ftl.util.loadFile import ftl.run.exception.FlankConfigurationError import ftl.run.exception.FlankGeneralError @@ -116,7 +117,7 @@ object YamlDeprecated { private fun validate(key: Key, keyValue: JsonNode): Transform? { transforms.forEach { if (it.old == key) { - println("${it.level}: `${it.old.parent}: ${it.old.name}:` renamed to `${it.new.parent}: ${it.new.name}:`") + logLn("${it.level}: `${it.old.parent}: ${it.old.name}:` renamed to `${it.new.parent}: ${it.new.name}:`") return Transform(keyValue, it) } } @@ -132,7 +133,7 @@ object YamlDeprecated { val (errorDetected, string) = modify(loadFile(yamlPath)) Files.write(yamlPath, string.toByteArray()) - println("\nUpdated ${yamlPath.fileName} file") + logLn("\nUpdated ${yamlPath.fileName} file") return errorDetected } diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/CommandUtil.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/CommandUtil.kt index 1f3bc6fcdb..f9d61a5831 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/CommandUtil.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/CommandUtil.kt @@ -2,19 +2,20 @@ package ftl.cli.firebase.test import ftl.args.yml.YamlDeprecated import ftl.args.yml.fixDevices +import ftl.log.logLn import ftl.run.exception.YmlValidationError import java.nio.file.Path fun processValidation(validationResult: String, shouldFix: Boolean, ymlPath: Path) { when { - validationResult.isBlank() -> println("Valid yml file") + validationResult.isBlank() -> logLn("Valid yml file") !shouldFix -> { - println(validationResult) + logLn(validationResult) throw YmlValidationError("Invalid yml file, use --fix for automatically fix yml") } else -> { - println(validationResult) - println("Trying to fix yml file") + logLn(validationResult) + logLn("Trying to fix yml file") if (YamlDeprecated.modify(ymlPath)) { throw YmlValidationError("Invalid yml file, unable to fix yml file") } 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 7da4f7478c..d9a04839f3 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.setupLogLevel import ftl.args.validate import ftl.cli.firebase.test.CommonRunCommand import ftl.config.FtlConstants @@ -45,6 +46,7 @@ class AndroidRunCommand : CommonRunCommand(), Runnable { } AndroidArgs.load(Paths.get(configPath), cli = this).validate().run { + setupLogLevel() runBlocking { if (dumpShards) dumpShards() else newTestRun() diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/AndroidTestEnvironmentCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/AndroidTestEnvironmentCommand.kt index 4b7796e5bc..f4a742ecbc 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/AndroidTestEnvironmentCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/AndroidTestEnvironmentCommand.kt @@ -9,6 +9,7 @@ import ftl.config.FtlConstants import ftl.environment.ipBlocksListAsTable import ftl.environment.networkConfigurationAsTable import ftl.environment.providedSoftwareAsTable +import ftl.log.logLn import picocli.CommandLine import java.nio.file.Paths @@ -28,13 +29,13 @@ import java.nio.file.Paths class AndroidTestEnvironmentCommand : Runnable { override fun run() { val projectId = AndroidArgs.loadOrDefault(Paths.get(configPath)).project - println(devicesCatalogAsTable(projectId)) - println(supportedVersionsAsTable(projectId)) - println(localesAsTable(projectId)) - println(providedSoftwareAsTable()) - println(networkConfigurationAsTable()) - println(supportedOrientationsAsTable(projectId)) - println(ipBlocksListAsTable()) + logLn(devicesCatalogAsTable(projectId)) + logLn(supportedVersionsAsTable(projectId)) + logLn(localesAsTable(projectId)) + logLn(providedSoftwareAsTable()) + logLn(networkConfigurationAsTable()) + logLn(supportedOrientationsAsTable(projectId)) + logLn(ipBlocksListAsTable()) } @CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"]) diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/configuration/AndroidLocalesDescribeCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/configuration/AndroidLocalesDescribeCommand.kt index 9c588d3add..be7ecf5e7a 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/configuration/AndroidLocalesDescribeCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/configuration/AndroidLocalesDescribeCommand.kt @@ -3,6 +3,7 @@ package ftl.cli.firebase.test.android.configuration import ftl.android.AndroidCatalog.getLocaleDescription import ftl.args.AndroidArgs import ftl.config.FtlConstants +import ftl.log.log import ftl.run.exception.FlankConfigurationError import picocli.CommandLine import java.nio.file.Paths @@ -20,7 +21,7 @@ import java.nio.file.Paths class AndroidLocalesDescribeCommand : Runnable { override fun run() { if (locale.isBlank()) throw FlankConfigurationError("Argument LOCALE must be specified.") - print(getLocaleDescription(AndroidArgs.loadOrDefault(Paths.get(configPath)).project, locale)) + log(getLocaleDescription(AndroidArgs.loadOrDefault(Paths.get(configPath)).project, locale)) } @CommandLine.Parameters( diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/configuration/AndroidLocalesListCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/configuration/AndroidLocalesListCommand.kt index a7d8c31247..840caa3f13 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/configuration/AndroidLocalesListCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/configuration/AndroidLocalesListCommand.kt @@ -3,6 +3,7 @@ package ftl.cli.firebase.test.android.configuration import ftl.android.AndroidCatalog import ftl.args.AndroidArgs import ftl.config.FtlConstants +import ftl.log.logLn import picocli.CommandLine import java.nio.file.Paths @@ -19,7 +20,7 @@ import java.nio.file.Paths ) class AndroidLocalesListCommand : Runnable { override fun run() { - println(AndroidCatalog.localesAsTable(projectId = AndroidArgs.loadOrDefault(Paths.get(configPath)).project)) + logLn(AndroidCatalog.localesAsTable(projectId = AndroidArgs.loadOrDefault(Paths.get(configPath)).project)) } @CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"]) diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/models/AndroidModelDescribeCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/models/AndroidModelDescribeCommand.kt index b036af4f25..69233d5591 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/models/AndroidModelDescribeCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/models/AndroidModelDescribeCommand.kt @@ -3,6 +3,7 @@ package ftl.cli.firebase.test.android.models import ftl.android.AndroidCatalog import ftl.args.AndroidArgs import ftl.config.FtlConstants +import ftl.log.logLn import ftl.run.exception.FlankConfigurationError import picocli.CommandLine import java.nio.file.Paths @@ -20,7 +21,7 @@ import java.nio.file.Paths class AndroidModelDescribeCommand : Runnable { override fun run() { if (modelId.isBlank()) throw FlankConfigurationError("Argument MODEL_ID must be specified.") - println(AndroidCatalog.describeModel(AndroidArgs.loadOrDefault(Paths.get(configPath)).project, modelId)) + logLn(AndroidCatalog.describeModel(AndroidArgs.loadOrDefault(Paths.get(configPath)).project, modelId)) } @CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"]) diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/models/AndroidModelsListCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/models/AndroidModelsListCommand.kt index 60ea398f3a..21c0cb7d0d 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/models/AndroidModelsListCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/models/AndroidModelsListCommand.kt @@ -3,6 +3,7 @@ package ftl.cli.firebase.test.android.models import ftl.android.AndroidCatalog import ftl.args.AndroidArgs import ftl.config.FtlConstants +import ftl.log.logLn import picocli.CommandLine import java.nio.file.Paths @@ -19,7 +20,7 @@ import java.nio.file.Paths ) class AndroidModelsListCommand : Runnable { override fun run() { - println(AndroidCatalog.devicesCatalogAsTable(AndroidArgs.loadOrDefault(Paths.get(configPath)).project)) + logLn(AndroidCatalog.devicesCatalogAsTable(AndroidArgs.loadOrDefault(Paths.get(configPath)).project)) } @CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"]) diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/orientations/AndroidOrientationsListCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/orientations/AndroidOrientationsListCommand.kt index 50a8f0200f..402c1face0 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/orientations/AndroidOrientationsListCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/orientations/AndroidOrientationsListCommand.kt @@ -3,6 +3,7 @@ package ftl.cli.firebase.test.android.orientations import ftl.android.AndroidCatalog import ftl.args.AndroidArgs import ftl.config.FtlConstants +import ftl.log.logLn import picocli.CommandLine import java.nio.file.Paths @@ -19,7 +20,7 @@ import java.nio.file.Paths ) class AndroidOrientationsListCommand : Runnable { override fun run() { - println(AndroidCatalog.supportedOrientationsAsTable(AndroidArgs.loadOrDefault(Paths.get(configPath)).project)) + logLn(AndroidCatalog.supportedOrientationsAsTable(AndroidArgs.loadOrDefault(Paths.get(configPath)).project)) } @CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"]) diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/versions/AndroidVersionsDescribeCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/versions/AndroidVersionsDescribeCommand.kt index 6d27d74009..8b2a9eec8b 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/versions/AndroidVersionsDescribeCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/versions/AndroidVersionsDescribeCommand.kt @@ -3,6 +3,7 @@ package ftl.cli.firebase.test.android.versions import ftl.android.AndroidCatalog import ftl.args.AndroidArgs import ftl.config.FtlConstants +import ftl.log.logLn import ftl.run.exception.FlankConfigurationError import picocli.CommandLine import java.nio.file.Paths @@ -21,7 +22,7 @@ import java.nio.file.Paths class AndroidVersionsDescribeCommand : Runnable { override fun run() { if (versionId.isBlank()) throw FlankConfigurationError("Argument VERSION_ID must be specified.") - println(AndroidCatalog.describeSoftwareVersion(AndroidArgs.loadOrDefault(Paths.get(configPath)).project, versionId)) + logLn(AndroidCatalog.describeSoftwareVersion(AndroidArgs.loadOrDefault(Paths.get(configPath)).project, versionId)) } @CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"]) diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/versions/AndroidVersionsListCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/versions/AndroidVersionsListCommand.kt index 086c5a6cba..e5ca46abef 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/versions/AndroidVersionsListCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/android/versions/AndroidVersionsListCommand.kt @@ -3,6 +3,7 @@ package ftl.cli.firebase.test.android.versions import ftl.android.AndroidCatalog.supportedVersionsAsTable import ftl.args.AndroidArgs import ftl.config.FtlConstants +import ftl.log.logLn import picocli.CommandLine import java.nio.file.Paths @@ -19,7 +20,7 @@ import java.nio.file.Paths ) class AndroidVersionsListCommand : Runnable { override fun run() { - println(supportedVersionsAsTable(AndroidArgs.loadOrDefault(Paths.get(configPath)).project)) + logLn(supportedVersionsAsTable(AndroidArgs.loadOrDefault(Paths.get(configPath)).project)) } @CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"]) 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 ef478fac98..f41a7855b2 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 @@ -1,6 +1,7 @@ package ftl.cli.firebase.test.ios import ftl.args.IosArgs +import ftl.args.setupLogLevel import ftl.args.validate import ftl.cli.firebase.test.CommonRunCommand import ftl.config.FtlConstants @@ -45,6 +46,7 @@ class IosRunCommand : CommonRunCommand(), Runnable { } IosArgs.load(Paths.get(configPath), cli = this).validate().run { + setupLogLevel() if (dumpShards) dumpShards() else runBlocking { newTestRun() } } diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/IosTestEnvironmentCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/IosTestEnvironmentCommand.kt index 296b48ffe7..4c8f468b63 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/IosTestEnvironmentCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/IosTestEnvironmentCommand.kt @@ -9,6 +9,7 @@ import ftl.ios.IosCatalog.devicesCatalogAsTable import ftl.ios.IosCatalog.localesAsTable import ftl.ios.IosCatalog.softwareVersionsAsTable import ftl.ios.IosCatalog.supportedOrientationsAsTable +import ftl.log.logLn import picocli.CommandLine import java.nio.file.Paths @@ -28,13 +29,13 @@ import java.nio.file.Paths class IosTestEnvironmentCommand : Runnable { override fun run() { val projectId = IosArgs.loadOrDefault(Paths.get(configPath)).project - println(devicesCatalogAsTable(projectId)) - println(softwareVersionsAsTable(projectId)) - println(localesAsTable(projectId)) - println(providedSoftwareAsTable()) - println(networkConfigurationAsTable()) - println(supportedOrientationsAsTable(projectId)) - println(ipBlocksListAsTable()) + logLn(devicesCatalogAsTable(projectId)) + logLn(softwareVersionsAsTable(projectId)) + logLn(localesAsTable(projectId)) + logLn(providedSoftwareAsTable()) + logLn(networkConfigurationAsTable()) + logLn(supportedOrientationsAsTable(projectId)) + logLn(ipBlocksListAsTable()) } @CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"]) diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesDescribeCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesDescribeCommand.kt index 0becec25c6..af607f11e6 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesDescribeCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesDescribeCommand.kt @@ -3,6 +3,7 @@ package ftl.cli.firebase.test.ios.configuration import ftl.args.IosArgs import ftl.config.FtlConstants import ftl.ios.IosCatalog.getLocaleDescription +import ftl.log.log import ftl.run.exception.FlankConfigurationError import picocli.CommandLine import java.nio.file.Paths @@ -20,7 +21,7 @@ import java.nio.file.Paths class IosLocalesDescribeCommand : Runnable { override fun run() { if (locale.isBlank()) throw FlankConfigurationError("Argument LOCALE must be specified.") - print(getLocaleDescription(IosArgs.loadOrDefault(Paths.get(configPath)).project, locale)) + log(getLocaleDescription(IosArgs.loadOrDefault(Paths.get(configPath)).project, locale)) } @CommandLine.Parameters( diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesListCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesListCommand.kt index 7d6364dbcc..e040a4f009 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesListCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/configuration/IosLocalesListCommand.kt @@ -3,6 +3,7 @@ package ftl.cli.firebase.test.ios.configuration import ftl.args.IosArgs import ftl.config.FtlConstants import ftl.ios.IosCatalog.localesAsTable +import ftl.log.logLn import picocli.CommandLine import java.nio.file.Paths @@ -19,7 +20,7 @@ import java.nio.file.Paths ) class IosLocalesListCommand : Runnable { override fun run() { - println(localesAsTable(projectId = IosArgs.loadOrDefault(Paths.get(configPath)).project)) + logLn(localesAsTable(projectId = IosArgs.loadOrDefault(Paths.get(configPath)).project)) } @CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"]) diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/models/IosModelDescribeCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/models/IosModelDescribeCommand.kt index 721d438a1f..e917c5cdd7 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/models/IosModelDescribeCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/models/IosModelDescribeCommand.kt @@ -3,6 +3,7 @@ package ftl.cli.firebase.test.ios.models import ftl.args.IosArgs import ftl.config.FtlConstants import ftl.ios.IosCatalog +import ftl.log.logLn import ftl.run.exception.FlankConfigurationError import picocli.CommandLine import java.nio.file.Paths @@ -20,7 +21,7 @@ import java.nio.file.Paths class IosModelDescribeCommand : Runnable { override fun run() { if (modelId.isBlank()) throw FlankConfigurationError("Argument MODEL_ID must be specified.") - println(IosCatalog.describeModel(IosArgs.loadOrDefault(Paths.get(configPath)).project, modelId)) + logLn(IosCatalog.describeModel(IosArgs.loadOrDefault(Paths.get(configPath)).project, modelId)) } @CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"]) diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/models/IosModelsListCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/models/IosModelsListCommand.kt index bc17c0920d..f06ef2d60d 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/models/IosModelsListCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/models/IosModelsListCommand.kt @@ -3,6 +3,7 @@ package ftl.cli.firebase.test.ios.models import ftl.args.IosArgs import ftl.config.FtlConstants import ftl.ios.IosCatalog.devicesCatalogAsTable +import ftl.log.logLn import picocli.CommandLine import java.nio.file.Paths @@ -19,7 +20,7 @@ import java.nio.file.Paths ) class IosModelsListCommand : Runnable { override fun run() { - println(devicesCatalogAsTable(IosArgs.loadOrDefault(Paths.get(configPath)).project)) + logLn(devicesCatalogAsTable(IosArgs.loadOrDefault(Paths.get(configPath)).project)) } @CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"]) diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/orientations/IosOrientationsListCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/orientations/IosOrientationsListCommand.kt index 8780b6f45c..19c06fc332 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/orientations/IosOrientationsListCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/orientations/IosOrientationsListCommand.kt @@ -3,6 +3,7 @@ package ftl.cli.firebase.test.ios.orientations import ftl.args.IosArgs import ftl.config.FtlConstants import ftl.ios.IosCatalog +import ftl.log.logLn import picocli.CommandLine import java.nio.file.Paths @@ -19,7 +20,7 @@ import java.nio.file.Paths ) class IosOrientationsListCommand : Runnable { override fun run() { - println(IosCatalog.supportedOrientationsAsTable(IosArgs.loadOrDefault(Paths.get(configPath)).project)) + logLn(IosCatalog.supportedOrientationsAsTable(IosArgs.loadOrDefault(Paths.get(configPath)).project)) } @CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"]) diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/versions/IosVersionsDescribeCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/versions/IosVersionsDescribeCommand.kt index 29dae3ff8c..f66c895853 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/versions/IosVersionsDescribeCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/versions/IosVersionsDescribeCommand.kt @@ -3,6 +3,7 @@ package ftl.cli.firebase.test.ios.versions import ftl.args.IosArgs import ftl.config.FtlConstants import ftl.ios.IosCatalog +import ftl.log.logLn import ftl.run.exception.FlankConfigurationError import picocli.CommandLine import java.nio.file.Paths @@ -21,7 +22,7 @@ import java.nio.file.Paths class IosVersionsDescribeCommand : Runnable { override fun run() { if (versionId.isBlank()) throw FlankConfigurationError("Argument VERSION_ID must be specified.") - println(IosCatalog.describeSoftwareVersion(IosArgs.loadOrDefault(Paths.get(configPath)).project, versionId)) + logLn(IosCatalog.describeSoftwareVersion(IosArgs.loadOrDefault(Paths.get(configPath)).project, versionId)) } @CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"]) diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/versions/IosVersionsListCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/versions/IosVersionsListCommand.kt index 1a79c59177..6a0dab5f0b 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/versions/IosVersionsListCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ios/versions/IosVersionsListCommand.kt @@ -3,6 +3,7 @@ package ftl.cli.firebase.test.ios.versions import ftl.args.IosArgs import ftl.config.FtlConstants import ftl.ios.IosCatalog.softwareVersionsAsTable +import ftl.log.logLn import picocli.CommandLine import java.nio.file.Paths @@ -19,7 +20,7 @@ import java.nio.file.Paths ) class IosVersionsListCommand : Runnable { override fun run() { - println(softwareVersionsAsTable(IosArgs.loadOrDefault(Paths.get(configPath)).project)) + logLn(softwareVersionsAsTable(IosArgs.loadOrDefault(Paths.get(configPath)).project)) } @CommandLine.Option(names = ["-c", "--config"], description = ["YAML config file path"]) diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ipblocks/IPBlocksListCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ipblocks/IPBlocksListCommand.kt index 7e303ff3e8..e6745a58a4 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/ipblocks/IPBlocksListCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/ipblocks/IPBlocksListCommand.kt @@ -1,6 +1,7 @@ package ftl.cli.firebase.test.ipblocks import ftl.environment.ipBlocksListAsTable +import ftl.log.logLn import picocli.CommandLine @CommandLine.Command( @@ -16,6 +17,6 @@ import picocli.CommandLine ) class IPBlocksListCommand : Runnable { override fun run() { - println(ipBlocksListAsTable()) + logLn(ipBlocksListAsTable()) } } diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/networkprofiles/NetworkProfilesDescribeCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/networkprofiles/NetworkProfilesDescribeCommand.kt index 03be98325a..42ba00ee66 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/networkprofiles/NetworkProfilesDescribeCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/networkprofiles/NetworkProfilesDescribeCommand.kt @@ -1,6 +1,7 @@ package ftl.cli.firebase.test.networkprofiles import ftl.environment.networkProfileDescription +import ftl.log.logLn import ftl.run.exception.FlankConfigurationError import picocli.CommandLine @@ -18,7 +19,7 @@ import picocli.CommandLine class NetworkProfilesDescribeCommand : Runnable { override fun run() { if (profileId.isBlank()) throw FlankConfigurationError("Argument PROFILE_ID must be specified.") - println(networkProfileDescription(profileId)) + logLn(networkProfileDescription(profileId)) } @CommandLine.Parameters( diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/networkprofiles/NetworkProfilesListCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/networkprofiles/NetworkProfilesListCommand.kt index c9e3ba008f..a62880ce2f 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/networkprofiles/NetworkProfilesListCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/networkprofiles/NetworkProfilesListCommand.kt @@ -1,6 +1,7 @@ package ftl.cli.firebase.test.networkprofiles import ftl.environment.networkConfigurationAsTable +import ftl.log.logLn import picocli.CommandLine @CommandLine.Command( @@ -16,7 +17,7 @@ import picocli.CommandLine ) class NetworkProfilesListCommand : Runnable { override fun run() { - println("fetching available network profiles...") - println(networkConfigurationAsTable()) + logLn("fetching available network profiles...") + logLn(networkConfigurationAsTable()) } } diff --git a/test_runner/src/main/kotlin/ftl/cli/firebase/test/providedsoftware/ProvidedSoftwareListCommand.kt b/test_runner/src/main/kotlin/ftl/cli/firebase/test/providedsoftware/ProvidedSoftwareListCommand.kt index d81bc9c9ff..91f6883947 100644 --- a/test_runner/src/main/kotlin/ftl/cli/firebase/test/providedsoftware/ProvidedSoftwareListCommand.kt +++ b/test_runner/src/main/kotlin/ftl/cli/firebase/test/providedsoftware/ProvidedSoftwareListCommand.kt @@ -1,6 +1,7 @@ package ftl.cli.firebase.test.providedsoftware import ftl.environment.providedSoftwareAsTable +import ftl.log.logLn import picocli.CommandLine @CommandLine.Command( @@ -16,6 +17,6 @@ import picocli.CommandLine ) class ProvidedSoftwareListCommand : Runnable { override fun run() { - println(providedSoftwareAsTable()) + logLn(providedSoftwareAsTable()) } } diff --git a/test_runner/src/main/kotlin/ftl/config/FtlConstants.kt b/test_runner/src/main/kotlin/ftl/config/FtlConstants.kt index 2ab263c055..191ffbaab8 100644 --- a/test_runner/src/main/kotlin/ftl/config/FtlConstants.kt +++ b/test_runner/src/main/kotlin/ftl/config/FtlConstants.kt @@ -8,6 +8,7 @@ import com.google.api.client.json.JsonFactory import ftl.args.AndroidArgs import ftl.args.IArgs import ftl.args.IosArgs +import ftl.log.logLn import ftl.util.BugsnagInitHelper.initBugsnag import ftl.run.exception.FlankConfigurationError import ftl.run.exception.FlankGeneralError @@ -24,7 +25,7 @@ object FtlConstants { val isMacOS: Boolean by lazy { val isMacOS = osName.indexOf("mac") >= 0 - println("isMacOS = $isMacOS ($osName)") + logLn("isMacOS = $isMacOS ($osName)") isMacOS } diff --git a/test_runner/src/main/kotlin/ftl/filter/TestFilters.kt b/test_runner/src/main/kotlin/ftl/filter/TestFilters.kt index 530f696f76..9a7c54ff4c 100644 --- a/test_runner/src/main/kotlin/ftl/filter/TestFilters.kt +++ b/test_runner/src/main/kotlin/ftl/filter/TestFilters.kt @@ -3,6 +3,7 @@ package ftl.filter import com.linkedin.dex.parser.TestMethod import ftl.args.ShardChunks import ftl.config.FtlConstants +import ftl.log.logLn import ftl.run.exception.FlankConfigurationError import ftl.run.exception.FlankGeneralError import java.io.IOException @@ -91,7 +92,7 @@ object TestFilters { val include = otherFilters.filterNot { it.describe.startsWith("not") }.toTypedArray() val result = allOf(*annotationFilters, *exclude, anyOf(*include)) - if (FtlConstants.useMock) println(result.describe) + if (FtlConstants.useMock) logLn(result.describe) return result } @@ -199,7 +200,7 @@ object TestFilters { private fun allOf(vararg filters: TestFilter): TestFilter = TestFilter( describe = "allOf ${filters.map { it.describe }}", shouldRun = { testMethod -> - if (FtlConstants.useMock) println(":: ${testMethod.testName} @${testMethod.annotations.firstOrNull()}") + if (FtlConstants.useMock) logLn(":: ${testMethod.testName} @${testMethod.annotations.firstOrNull()}") filters.isEmpty() || filters.all { filter -> filter.shouldRun(testMethod).also { result -> if (FtlConstants.useMock) println(" $result ${filter.describe}") diff --git a/test_runner/src/main/kotlin/ftl/gc/GcStorage.kt b/test_runner/src/main/kotlin/ftl/gc/GcStorage.kt index 246dd16949..e5e1d15619 100644 --- a/test_runner/src/main/kotlin/ftl/gc/GcStorage.kt +++ b/test_runner/src/main/kotlin/ftl/gc/GcStorage.kt @@ -14,6 +14,7 @@ import ftl.args.IosArgs import ftl.config.FtlConstants import ftl.config.FtlConstants.GCS_PREFIX import ftl.config.credential +import ftl.log.logLn import ftl.reports.xml.model.JUnitTestResult import ftl.reports.xml.parseAllSuitesXml import ftl.reports.xml.xmlToString @@ -89,7 +90,7 @@ object GcStorage { resultDir ) }.onFailure { - println("Cannot upload performance metrics ${it.message}") + logLn("Cannot upload performance metrics ${it.message}") }.getOrNull() fun uploadReportResult(testResult: String, args: IArgs, fileName: String) { diff --git a/test_runner/src/main/kotlin/ftl/gc/UserAuth.kt b/test_runner/src/main/kotlin/ftl/gc/UserAuth.kt index a8f8c8f465..6558eaa299 100644 --- a/test_runner/src/main/kotlin/ftl/gc/UserAuth.kt +++ b/test_runner/src/main/kotlin/ftl/gc/UserAuth.kt @@ -6,6 +6,7 @@ import com.google.auth.oauth2.UserAuthorizer import com.google.auth.oauth2.UserCredentials import ftl.config.FtlConstants import ftl.config.FtlConstants.userHome +import ftl.log.logLn import ftl.run.exception.FlankGeneralError import io.ktor.application.call import io.ktor.response.respondText @@ -89,8 +90,8 @@ class UserAuth { private fun printAuthorizationUrl() { val url = authorizer.getAuthorizationUrl(userId, null, uri) - println("Visit the following URL in your browser:") - println(url) + logLn("Visit the following URL in your browser:") + logLn(url) } fun request() { @@ -115,7 +116,7 @@ class UserAuth { dotFlank.toFile().mkdirs() ObjectOutputStream(FileOutputStream(userToken.toFile())).writeObject(userCredential) - println() - println("User token saved to $userToken") + logLn() + logLn("User token saved to $userToken") } } diff --git a/test_runner/src/main/kotlin/ftl/gc/android/CreateAndroidInstrumentationTest.kt b/test_runner/src/main/kotlin/ftl/gc/android/CreateAndroidInstrumentationTest.kt index 3948f5a5c2..e5375511fb 100644 --- a/test_runner/src/main/kotlin/ftl/gc/android/CreateAndroidInstrumentationTest.kt +++ b/test_runner/src/main/kotlin/ftl/gc/android/CreateAndroidInstrumentationTest.kt @@ -7,6 +7,7 @@ import com.google.testing.model.ShardingOption import com.google.testing.model.TestTargetsForShard import com.google.testing.model.UniformSharding import ftl.args.ShardChunks +import ftl.log.logLn import ftl.run.platform.android.AndroidTestConfig internal fun createAndroidInstrumentationTest( @@ -43,7 +44,7 @@ internal fun AndroidInstrumentationTest.setupTestTargets( if (numUniformShards != null) { testTargets = testShards.flatten() val safeNumUniformShards = if (testTargets.size > numUniformShards) numUniformShards else { - println("WARNING: num-uniform-shards ($numUniformShards) is higher than number of test cases (${testTargets.size}) from ${testApk.gcsPath}") + logLn("WARNING: num-uniform-shards ($numUniformShards) is higher than number of test cases (${testTargets.size}) from ${testApk.gcsPath}") testTargets.size } uniformSharding = UniformSharding().setNumShards(safeNumUniformShards) diff --git a/test_runner/src/main/kotlin/ftl/ios/xctest/common/FindTestsForTarget.kt b/test_runner/src/main/kotlin/ftl/ios/xctest/common/FindTestsForTarget.kt index d7a569fdad..1e21808ade 100644 --- a/test_runner/src/main/kotlin/ftl/ios/xctest/common/FindTestsForTarget.kt +++ b/test_runner/src/main/kotlin/ftl/ios/xctest/common/FindTestsForTarget.kt @@ -5,6 +5,7 @@ import com.dd.plist.NSDictionary import com.dd.plist.NSObject import com.dd.plist.NSString import com.google.common.annotations.VisibleForTesting +import ftl.log.logLn import ftl.run.exception.FlankGeneralError import java.io.File import java.nio.file.Paths @@ -28,7 +29,7 @@ private fun NSDictionary.findXcTestTargets( private fun NSObject.findBinaryTests(testRoot: String): List { val binaryRoot = toString().replace("__TESTROOT__/", testRoot) - println("Found xctest: $binaryRoot") + logLn("Found xctest: $binaryRoot") val binaryName = File(binaryRoot).nameWithoutExtension val binaryPath = Paths.get(binaryRoot, binaryName).toString() diff --git a/test_runner/src/main/kotlin/ftl/log/OutputLogger.kt b/test_runner/src/main/kotlin/ftl/log/OutputLogger.kt new file mode 100644 index 0000000000..63cc72592b --- /dev/null +++ b/test_runner/src/main/kotlin/ftl/log/OutputLogger.kt @@ -0,0 +1,20 @@ +package ftl.log + +fun setLogLevel(logLevel: OutputLogLevel) { + minimumLogLevel = logLevel +} + +fun log(message: Any, level: OutputLogLevel = OutputLogLevel.SIMPLE) { + if (minimumLogLevel >= level) print(message) +} + +fun logLn(message: Any = "", level: OutputLogLevel = OutputLogLevel.SIMPLE) { + if (minimumLogLevel >= level) println(message) +} + +private var minimumLogLevel: OutputLogLevel = OutputLogLevel.DETAILED + +enum class OutputLogLevel { + SIMPLE, + DETAILED +} diff --git a/test_runner/src/main/kotlin/ftl/reports/FullJUnitReport.kt b/test_runner/src/main/kotlin/ftl/reports/FullJUnitReport.kt index 4d64e16f99..6c4a0d3c6d 100644 --- a/test_runner/src/main/kotlin/ftl/reports/FullJUnitReport.kt +++ b/test_runner/src/main/kotlin/ftl/reports/FullJUnitReport.kt @@ -3,6 +3,7 @@ package ftl.reports import ftl.args.IArgs import ftl.gc.GcStorage import ftl.json.MatrixMap +import ftl.log.log import ftl.reports.util.IReport import ftl.reports.xml.model.JUnitTestResult import ftl.reports.xml.xmlToString @@ -13,7 +14,7 @@ object FullJUnitReport : IReport { override fun run(matrices: MatrixMap, result: JUnitTestResult?, printToStdout: Boolean, args: IArgs) { val output = result.xmlToString() if (printToStdout) { - print(output) + log(output) } else { write(matrices, output, args) } diff --git a/test_runner/src/main/kotlin/ftl/reports/JUnitReport.kt b/test_runner/src/main/kotlin/ftl/reports/JUnitReport.kt index d3bafeaf7e..20f80e8296 100644 --- a/test_runner/src/main/kotlin/ftl/reports/JUnitReport.kt +++ b/test_runner/src/main/kotlin/ftl/reports/JUnitReport.kt @@ -3,6 +3,7 @@ package ftl.reports import ftl.args.IArgs import ftl.gc.GcStorage import ftl.json.MatrixMap +import ftl.log.log import ftl.reports.util.IReport import ftl.reports.xml.model.JUnitTestResult import ftl.reports.xml.xmlToString @@ -16,7 +17,7 @@ object JUnitReport : IReport { val output = result.xmlToString() if (printToStdout) { - print(output) + log(output) } else { write(matrices, output, args) } diff --git a/test_runner/src/main/kotlin/ftl/reports/MatrixResultsReport.kt b/test_runner/src/main/kotlin/ftl/reports/MatrixResultsReport.kt index 5a34c6a81c..93379f38bf 100644 --- a/test_runner/src/main/kotlin/ftl/reports/MatrixResultsReport.kt +++ b/test_runner/src/main/kotlin/ftl/reports/MatrixResultsReport.kt @@ -9,6 +9,7 @@ import ftl.json.isFailed import ftl.reports.util.IReport import ftl.reports.xml.model.JUnitTestResult import ftl.json.asPrintableTable +import ftl.log.log import ftl.util.println import java.io.StringWriter import java.text.DecimalFormat @@ -70,7 +71,7 @@ object MatrixResultsReport : IReport { override fun run(matrices: MatrixMap, result: JUnitTestResult?, printToStdout: Boolean, args: IArgs) { val output = generate(matrices) - if (printToStdout) print(output) + if (printToStdout) log(output) write(matrices, output, args) GcStorage.uploadReportResult(output, args, fileName()) } diff --git a/test_runner/src/main/kotlin/ftl/reports/outcome/CreateMatrixOutcomeSummary.kt b/test_runner/src/main/kotlin/ftl/reports/outcome/CreateMatrixOutcomeSummary.kt index d24bf2baf2..bf6bf38ac4 100644 --- a/test_runner/src/main/kotlin/ftl/reports/outcome/CreateMatrixOutcomeSummary.kt +++ b/test_runner/src/main/kotlin/ftl/reports/outcome/CreateMatrixOutcomeSummary.kt @@ -1,6 +1,7 @@ package ftl.reports.outcome import com.google.api.services.toolresults.model.Environment +import ftl.log.logLn fun TestOutcomeContext.createMatrixOutcomeSummary() = billableMinutes() to outcomeSummary() @@ -10,7 +11,7 @@ private fun TestOutcomeContext.outcomeSummary() = if (environments.hasOutcome()) createMatrixOutcomeSummaryUsingEnvironments() else { - if (steps.isEmpty()) println("No test results found, something went wrong. Try re-running the tests.") + if (steps.isEmpty()) logLn("No test results found, something went wrong. Try re-running the tests.") createMatrixOutcomeSummaryUsingSteps() } diff --git a/test_runner/src/main/kotlin/ftl/reports/util/ReportManager.kt b/test_runner/src/main/kotlin/ftl/reports/util/ReportManager.kt index 931ebe530e..ba412537a4 100644 --- a/test_runner/src/main/kotlin/ftl/reports/util/ReportManager.kt +++ b/test_runner/src/main/kotlin/ftl/reports/util/ReportManager.kt @@ -10,6 +10,7 @@ import ftl.args.ShardChunks import ftl.gc.GcStorage import ftl.json.MatrixMap import ftl.json.isAllSuccessful +import ftl.log.logLn import ftl.reports.CostReport import ftl.reports.FullJUnitReport import ftl.reports.HtmlErrorReport @@ -43,7 +44,7 @@ object ReportManager { private fun getWebLink(matrices: MatrixMap, xmlFile: File): String = xmlFile.getMatrixPath(matrices.runPath) ?.findMatrixPath(matrices) - ?: "".also { println("WARNING: Matrix path not found in JSON.") } + ?: "".also { logLn("WARNING: Matrix path not found in JSON.") } private val deviceStringRgx = Regex("([^-]+-[^-]+-[^-]+-[^-]+).*") @@ -213,7 +214,7 @@ object ReportManager { ) { val list = createShardEfficiencyList(oldResult, newResult, args, testShardChunks) - println( + logLn( "Actual shard times:\n" + list.joinToString("\n") { " ${it.shard}: Expected: ${it.expectedTime.roundToInt()}s, Actual: ${it.finalTime.roundToInt()}s, Diff: ${it.timeDiff.roundToInt()}s" } + "\n" @@ -244,7 +245,7 @@ object ReportManager { private fun String.findMatrixPath(matrices: MatrixMap) = matrices.map.values .firstOrNull { savedMatrix -> savedMatrix.gcsPath.endsWithTextWithOptionalSlashAtTheEnd(this) } ?.webLink - ?: "".also { println("WARNING: Matrix path not found in JSON. $this") } + ?: "".also { logLn("WARNING: Matrix path not found in JSON. $this") } @VisibleForTesting internal fun String.endsWithTextWithOptionalSlashAtTheEnd(text: String) = "($text)/*$".toRegex().containsMatchIn(this) diff --git a/test_runner/src/main/kotlin/ftl/run/CancelLastRun.kt b/test_runner/src/main/kotlin/ftl/run/CancelLastRun.kt index d4ccaef61b..2a0ce05106 100644 --- a/test_runner/src/main/kotlin/ftl/run/CancelLastRun.kt +++ b/test_runner/src/main/kotlin/ftl/run/CancelLastRun.kt @@ -4,6 +4,7 @@ import ftl.args.IArgs import ftl.config.FtlConstants import ftl.gc.GcTestMatrix import ftl.json.SavedMatrix +import ftl.log.logLn import ftl.run.common.getLastArgs import ftl.run.common.getLastMatrices import ftl.util.MatrixState @@ -23,7 +24,7 @@ fun cancelLastRun(args: IArgs) { /** Cancel all in progress matrices in parallel **/ suspend fun cancelMatrices(matrixMap: Map, project: String) = coroutineScope { - println("CancelMatrices") + logLn("CancelMatrices") var matrixCount = 0 @@ -36,10 +37,10 @@ suspend fun cancelMatrices(matrixMap: Map, project: String) } if (matrixCount == 0) { - println(FtlConstants.indent + "No matrices to cancel") + logLn(FtlConstants.indent + "No matrices to cancel") } else { - println(FtlConstants.indent + "Cancelling ${matrixCount}x matrices") + logLn(FtlConstants.indent + "Cancelling ${matrixCount}x matrices") } - println() + logLn() } diff --git a/test_runner/src/main/kotlin/ftl/run/DumpShards.kt b/test_runner/src/main/kotlin/ftl/run/DumpShards.kt index 8a16d84178..63f2e8b823 100644 --- a/test_runner/src/main/kotlin/ftl/run/DumpShards.kt +++ b/test_runner/src/main/kotlin/ftl/run/DumpShards.kt @@ -3,6 +3,8 @@ package ftl.run import ftl.args.AndroidArgs import ftl.args.IosArgs import ftl.args.isInstrumentationTest +import ftl.log.OutputLogLevel +import ftl.log.logLn import ftl.run.common.prettyPrint import ftl.run.exception.FlankConfigurationError import ftl.run.model.AndroidMatrixTestShards @@ -50,7 +52,7 @@ fun saveShardChunks( Paths.get(shardFilePath), getGson(obfuscatedOutput).toJson(shards).toByteArray() ) - println("Saved $size shards to $shardFilePath") + logLn("Saved $size shards to $shardFilePath", OutputLogLevel.DETAILED) } private fun getGson(obfuscatedOutput: Boolean) = if (obfuscatedOutput) obfuscatePrettyPrinter else prettyPrint diff --git a/test_runner/src/main/kotlin/ftl/run/NewTestRun.kt b/test_runner/src/main/kotlin/ftl/run/NewTestRun.kt index db360bc220..624f25e5d1 100644 --- a/test_runner/src/main/kotlin/ftl/run/NewTestRun.kt +++ b/test_runner/src/main/kotlin/ftl/run/NewTestRun.kt @@ -6,6 +6,7 @@ import ftl.args.IosArgs import ftl.json.SavedMatrix import ftl.json.updateMatrixMap import ftl.json.validate +import ftl.log.logLn import ftl.reports.util.ReportManager import ftl.run.common.fetchArtifacts import ftl.run.common.pollMatrices @@ -20,7 +21,7 @@ import kotlinx.coroutines.withTimeoutOrNull suspend fun IArgs.newTestRun() = withTimeoutOrNull(parsedTimeout) { val args: IArgs = this@newTestRun - println(args) + logLn(args) val (matrixMap, testShardChunks, ignoredTests) = cancelTestsOnTimeout(project) { runTests() } @@ -29,7 +30,7 @@ suspend fun IArgs.newTestRun() = withTimeoutOrNull(parsedTimeout) { ReportManager.generate(matrixMap, args, testShardChunks, ignoredTests) cancelTestsOnTimeout(args.project, matrixMap.map) { fetchArtifacts(matrixMap, args) } - println() + logLn() matrixMap.printMatricesWebLinks(project) matrixMap.validate(ignoreFailedTests) diff --git a/test_runner/src/main/kotlin/ftl/run/RefreshLastRun.kt b/test_runner/src/main/kotlin/ftl/run/RefreshLastRun.kt index 0d33fbd74e..4b0d0e21c9 100644 --- a/test_runner/src/main/kotlin/ftl/run/RefreshLastRun.kt +++ b/test_runner/src/main/kotlin/ftl/run/RefreshLastRun.kt @@ -16,6 +16,7 @@ import ftl.args.ShardChunks import ftl.json.needsUpdate import ftl.json.updateWithMatrix import ftl.json.validate +import ftl.log.logLn import ftl.util.MatrixState import kotlinx.coroutines.Deferred import kotlinx.coroutines.Dispatchers @@ -40,7 +41,7 @@ suspend fun refreshLastRun(currentArgs: IArgs, testShardChunks: ShardChunks) { /** Refresh all in progress matrices in parallel **/ private suspend fun refreshMatrices(matrixMap: MatrixMap, args: IArgs) = coroutineScope { - println("RefreshMatrices") + logLn("RefreshMatrices") val jobs = arrayListOf>() val map = matrixMap.map @@ -54,14 +55,14 @@ private suspend fun refreshMatrices(matrixMap: MatrixMap, args: IArgs) = corouti } if (matrixCount != 0) { - println(FtlConstants.indent + "Refreshing ${matrixCount}x matrices") + logLn(FtlConstants.indent + "Refreshing ${matrixCount}x matrices") } var dirty = false jobs.awaitAll().forEach { matrix -> val matrixId = matrix.testMatrixId - println(FtlConstants.indent + "${matrix.state} $matrixId") + logLn(FtlConstants.indent + "${matrix.state} $matrixId") if (map[matrixId]?.needsUpdate(matrix) == true) { map[matrixId]?.updateWithMatrix(matrix)?.let { @@ -72,8 +73,8 @@ private suspend fun refreshMatrices(matrixMap: MatrixMap, args: IArgs) = corouti } if (dirty) { - println(FtlConstants.indent + "Updating matrix file") + logLn(FtlConstants.indent + "Updating matrix file") args.updateMatrixFile(matrixMap) } - println() + logLn() } diff --git a/test_runner/src/main/kotlin/ftl/run/common/FetchArtifacts.kt b/test_runner/src/main/kotlin/ftl/run/common/FetchArtifacts.kt index 84c93a14ef..cf2ebd4a20 100644 --- a/test_runner/src/main/kotlin/ftl/run/common/FetchArtifacts.kt +++ b/test_runner/src/main/kotlin/ftl/run/common/FetchArtifacts.kt @@ -5,6 +5,9 @@ import ftl.args.IArgs import ftl.config.FtlConstants import ftl.gc.GcStorage import ftl.json.MatrixMap +import ftl.log.OutputLogLevel +import ftl.log.log +import ftl.log.logLn import ftl.util.Artifacts import ftl.util.MatrixState import kotlinx.coroutines.Dispatchers @@ -17,7 +20,7 @@ import java.nio.file.Paths // TODO needs refactor internal suspend fun fetchArtifacts(matrixMap: MatrixMap, args: IArgs) = coroutineScope { - println("FetchArtifacts") + logLn("FetchArtifacts", OutputLogLevel.DETAILED) val fields = Storage.BlobListOption.fields(Storage.BlobField.NAME) var dirty = false @@ -27,7 +30,7 @@ internal suspend fun fetchArtifacts(matrixMap: MatrixMap, args: IArgs) = corouti finished && notDownloaded }.toMutableList() - print(FtlConstants.indent) + log(FtlConstants.indent) filtered.flatMapIndexed { index, matrix -> val prefix = Storage.BlobListOption.prefix(matrix.gcsPathWithoutRootBucket) val result = GcStorage.storage.list(matrix.gcsRootBucket, prefix, fields) @@ -40,7 +43,7 @@ internal suspend fun fetchArtifacts(matrixMap: MatrixMap, args: IArgs) = corouti if (matched) { val downloadFile = getDownloadPath(args, blobPath) - print(".") + log(".", OutputLogLevel.DETAILED) if (!downloadFile.toFile().exists()) { val parentFile = downloadFile.parent.toFile() parentFile.mkdirs() @@ -53,12 +56,12 @@ internal suspend fun fetchArtifacts(matrixMap: MatrixMap, args: IArgs) = corouti filtered[index] = matrix.copy(downloaded = true) jobs }.joinAll() - println() + logLn(level = OutputLogLevel.DETAILED) if (dirty) { - println(FtlConstants.indent + "Updating matrix file") + logLn(FtlConstants.indent + "Updating matrix file", level = OutputLogLevel.DETAILED) args.updateMatrixFile(matrixMap) - println() + logLn(level = OutputLogLevel.DETAILED) } } diff --git a/test_runner/src/main/kotlin/ftl/run/common/GetLastMatrices.kt b/test_runner/src/main/kotlin/ftl/run/common/GetLastMatrices.kt index 50f8d58fd2..2b9b277cd1 100644 --- a/test_runner/src/main/kotlin/ftl/run/common/GetLastMatrices.kt +++ b/test_runner/src/main/kotlin/ftl/run/common/GetLastMatrices.kt @@ -4,6 +4,7 @@ import ftl.args.IArgs import ftl.config.FtlConstants import ftl.json.MatrixMap import ftl.json.SavedMatrix +import ftl.log.logLn import ftl.run.exception.FlankGeneralError import java.nio.file.Paths @@ -11,7 +12,7 @@ import java.nio.file.Paths internal fun getLastMatrices(args: IArgs): MatrixMap { val lastRun = args.getLastGcsPath() ?: throw FlankGeneralError("no runs found in results/ folder") - println("Loading run $lastRun") + logLn("Loading run $lastRun") return matrixPathToObj(lastRun, args) } diff --git a/test_runner/src/main/kotlin/ftl/run/common/PollMatrices.kt b/test_runner/src/main/kotlin/ftl/run/common/PollMatrices.kt index fd7ba40b2a..e834b8ed1c 100644 --- a/test_runner/src/main/kotlin/ftl/run/common/PollMatrices.kt +++ b/test_runner/src/main/kotlin/ftl/run/common/PollMatrices.kt @@ -5,6 +5,7 @@ package ftl.run.common import com.google.testing.model.TestMatrix import ftl.args.IArgs import ftl.gc.GcTestMatrix +import ftl.log.logLn import ftl.run.status.TestMatrixStatusPrinter import ftl.util.MatrixState import kotlinx.coroutines.coroutineScope @@ -34,7 +35,7 @@ suspend fun pollMatrices( }.fold(emptyMap()) { matrices, next -> matrices + (next.testMatrixId to next) }.values.also { - println() + logLn() } } diff --git a/test_runner/src/main/kotlin/ftl/run/exception/ExceptionHandler.kt b/test_runner/src/main/kotlin/ftl/run/exception/ExceptionHandler.kt index 47c3c3dae4..eb696cdb7a 100644 --- a/test_runner/src/main/kotlin/ftl/run/exception/ExceptionHandler.kt +++ b/test_runner/src/main/kotlin/ftl/run/exception/ExceptionHandler.kt @@ -2,6 +2,7 @@ package ftl.run.exception import ftl.config.FtlConstants import ftl.json.SavedMatrix +import ftl.log.logLn import ftl.run.cancelMatrices import kotlinx.coroutines.runBlocking import kotlin.system.exitProcess @@ -77,5 +78,5 @@ private val FlankException.messageOrUnavailable: String private fun printError(string: String?) = System.err.println(string) private fun SavedMatrix.logError() { - println("Matrix is $state") + logLn("Matrix is $state") } diff --git a/test_runner/src/main/kotlin/ftl/run/platform/RunAndroidTests.kt b/test_runner/src/main/kotlin/ftl/run/platform/RunAndroidTests.kt index 0020e5708b..dd5458ea11 100644 --- a/test_runner/src/main/kotlin/ftl/run/platform/RunAndroidTests.kt +++ b/test_runner/src/main/kotlin/ftl/run/platform/RunAndroidTests.kt @@ -9,6 +9,7 @@ import ftl.gc.GcAndroidTestMatrix import ftl.gc.GcStorage import ftl.gc.GcToolResults import ftl.http.executeWithRetry +import ftl.log.logLn import ftl.run.ANDROID_SHARD_FILE import ftl.run.model.InstrumentationTestContext import ftl.run.model.TestResult @@ -71,7 +72,7 @@ internal suspend fun AndroidArgs.runAndroidTests(): TestResult = coroutineScope if (testMatrices.isEmpty()) throw FlankGeneralError("There are no tests to run.") - println(beforeRunMessage(allTestShardChunks)) + logLn(beforeRunMessage(allTestShardChunks)) TestResult( matrixMap = afterRunTests(testMatrices.awaitAll(), stopwatch), diff --git a/test_runner/src/main/kotlin/ftl/run/platform/RunIosTests.kt b/test_runner/src/main/kotlin/ftl/run/platform/RunIosTests.kt index 16a8d33efb..44beb0952e 100644 --- a/test_runner/src/main/kotlin/ftl/run/platform/RunIosTests.kt +++ b/test_runner/src/main/kotlin/ftl/run/platform/RunIosTests.kt @@ -8,6 +8,7 @@ import ftl.gc.GcStorage import ftl.gc.GcToolResults import ftl.http.executeWithRetry import ftl.ios.xctest.common.parseToNSDictionary +import ftl.log.logLn import ftl.run.IOS_SHARD_FILE import ftl.run.dumpShards import ftl.run.model.TestResult @@ -50,7 +51,7 @@ internal suspend fun IosArgs.runIosTests(): TestResult = coroutineScope { // Upload only after parsing shards to detect missing methods early. val xcTestGcsPath = uploadIfNeeded(xctestrunZip.asFileReference()).gcs - println(beforeRunMessage(testShardChunks)) + logLn(beforeRunMessage(testShardChunks)) repeat(runCount) { jobs += testShardChunks.map { testTargets -> diff --git a/test_runner/src/main/kotlin/ftl/run/platform/android/CreateAndroidTestContext.kt b/test_runner/src/main/kotlin/ftl/run/platform/android/CreateAndroidTestContext.kt index 4df8e9678a..5d6d384519 100644 --- a/test_runner/src/main/kotlin/ftl/run/platform/android/CreateAndroidTestContext.kt +++ b/test_runner/src/main/kotlin/ftl/run/platform/android/CreateAndroidTestContext.kt @@ -16,6 +16,7 @@ import ftl.args.CalculateShardsResult import ftl.config.FtlConstants import ftl.filter.TestFilter import ftl.filter.TestFilters +import ftl.log.logLn import ftl.run.model.AndroidTestContext import ftl.run.model.InstrumentationTestContext import ftl.shard.createShardsByTestForShards @@ -145,6 +146,6 @@ private fun List.dropEmptyInstrumentationTest(): List) { val testApkNames = testApks.joinToString(", ") { pathname -> File(pathname.test.local).name } - println("${FtlConstants.indent}No tests for $testApkNames") - println() + logLn("${FtlConstants.indent}No tests for $testApkNames") + logLn() } diff --git a/test_runner/src/main/kotlin/ftl/run/platform/common/AfterRunTests.kt b/test_runner/src/main/kotlin/ftl/run/platform/common/AfterRunTests.kt index 4a59108841..6d628e512f 100644 --- a/test_runner/src/main/kotlin/ftl/run/platform/common/AfterRunTests.kt +++ b/test_runner/src/main/kotlin/ftl/run/platform/common/AfterRunTests.kt @@ -6,6 +6,7 @@ import ftl.config.FtlConstants import ftl.gc.GcTestMatrix import ftl.json.MatrixMap import ftl.json.createSavedMatrix +import ftl.log.logLn import ftl.run.common.updateMatrixFile import ftl.util.StopWatch import ftl.util.isInvalid @@ -27,11 +28,11 @@ internal suspend fun IArgs.afterRunTests( updateMatrixFile(matrixMap) saveConfigFile(matrixMap) - println(FtlConstants.indent + "${matrixMap.map.size} matrix ids created in ${stopwatch.check()}") + logLn(FtlConstants.indent + "${matrixMap.map.size} matrix ids created in ${stopwatch.check()}") val gcsBucket = "https://console.developers.google.com/storage/browser/" + resultsBucket + "/" + matrixMap.runPath - println(FtlConstants.indent + gcsBucket) - println() + logLn(FtlConstants.indent + gcsBucket) + logLn() matrixMap.printMatricesWebLinks(project) } @@ -48,13 +49,13 @@ private fun IArgs.saveConfigFile(matrixMap: MatrixMap) { } internal suspend inline fun MatrixMap.printMatricesWebLinks(project: String) = coroutineScope { - println("Matrices webLink") + logLn("Matrices webLink") map.values.map { launch(Dispatchers.IO) { - println("${FtlConstants.indent}${it.matrixId} ${getOrUpdateWebLink(it.webLink, project, it.matrixId)}") + logLn("${FtlConstants.indent}${it.matrixId} ${getOrUpdateWebLink(it.webLink, project, it.matrixId)}") } }.joinAll() - println() + logLn() } private tailrec suspend fun getOrUpdateWebLink(link: String, project: String, matrixId: String): String = diff --git a/test_runner/src/main/kotlin/ftl/run/platform/common/BeforeRunTests.kt b/test_runner/src/main/kotlin/ftl/run/platform/common/BeforeRunTests.kt index 7716ad1117..b71015eaca 100644 --- a/test_runner/src/main/kotlin/ftl/run/platform/common/BeforeRunTests.kt +++ b/test_runner/src/main/kotlin/ftl/run/platform/common/BeforeRunTests.kt @@ -5,12 +5,13 @@ import ftl.config.FtlConstants import ftl.gc.GcStorage import ftl.gc.GcTesting import ftl.gc.GcToolResults +import ftl.log.logLn import ftl.run.exception.FlankGeneralError import ftl.util.StopWatch import java.io.File internal fun IArgs.beforeRunTests() = StopWatch().also { watch -> - println("\nRunTests") + logLn("\nRunTests") assertMockUrl() watch.start() diff --git a/test_runner/src/main/kotlin/ftl/run/status/ExecutionStatusPrinter.kt b/test_runner/src/main/kotlin/ftl/run/status/ExecutionStatusPrinter.kt index 31a364836c..f3308d0b7e 100644 --- a/test_runner/src/main/kotlin/ftl/run/status/ExecutionStatusPrinter.kt +++ b/test_runner/src/main/kotlin/ftl/run/status/ExecutionStatusPrinter.kt @@ -3,6 +3,9 @@ package ftl.run.status import com.google.common.annotations.VisibleForTesting import ftl.args.IArgs import ftl.config.FtlConstants +import ftl.log.OutputLogLevel +import ftl.log.log +import ftl.log.logLn import org.fusesource.jansi.Ansi import org.fusesource.jansi.AnsiConsole @@ -12,6 +15,7 @@ fun createExecutionStatusPrinter( OutputStyle.Multi -> MultiLinePrinter() OutputStyle.Single -> SingleLinePrinter() OutputStyle.Verbose -> VerbosePrinter + OutputStyle.Compact -> VerbosePrinter } @VisibleForTesting @@ -32,7 +36,7 @@ internal class SingleLinePrinter : (List) -> Unit { print("\r" + (0..previousLineSize).joinToString("") { " " }) val output = "${FtlConstants.indent}$time Test executions status: $statusCounts" previousLineSize = output.length - print("\r$output") + log("\r$output") } } } @@ -48,7 +52,7 @@ internal class MultiLinePrinter( private val output = LinkedHashMap() override fun invoke(changes: List) { repeat(output.size) { - print(ansi().cursorUpLine().eraseLine().toString()) + log(ansi().cursorUpLine().eraseLine().toString()) } output += changes.map { change -> change.views.takeLast(1) @@ -62,7 +66,7 @@ internal class MultiLinePrinter( @VisibleForTesting internal object VerbosePrinter : (List) -> Unit { override fun invoke(changes: List) { - changes.map(ExecutionStatus.Change::views).flatten().forEach(::println) + changes.map(ExecutionStatus.Change::views).flatten().forEach { logLn(it, OutputLogLevel.DETAILED) } } } diff --git a/test_runner/src/main/kotlin/ftl/run/status/OutputStyle.kt b/test_runner/src/main/kotlin/ftl/run/status/OutputStyle.kt index b23e4b3320..5e4eccef6f 100644 --- a/test_runner/src/main/kotlin/ftl/run/status/OutputStyle.kt +++ b/test_runner/src/main/kotlin/ftl/run/status/OutputStyle.kt @@ -2,7 +2,7 @@ package ftl.run.status import ftl.run.exception.FlankConfigurationError -enum class OutputStyle { Verbose, Single, Multi } +enum class OutputStyle { Verbose, Single, Multi, Compact } fun String.asOutputStyle() = capitalize().let { capitalized -> OutputStyle.values().find { style -> style.name == capitalized } diff --git a/test_runner/src/main/kotlin/ftl/run/status/TestMatrixStatusPrinter.kt b/test_runner/src/main/kotlin/ftl/run/status/TestMatrixStatusPrinter.kt index ffb41bb611..fdea904b7c 100644 --- a/test_runner/src/main/kotlin/ftl/run/status/TestMatrixStatusPrinter.kt +++ b/test_runner/src/main/kotlin/ftl/run/status/TestMatrixStatusPrinter.kt @@ -4,6 +4,7 @@ import com.google.testing.model.TestExecution import com.google.testing.model.TestMatrix import ftl.args.IArgs import ftl.config.FtlConstants +import ftl.log.logLn import ftl.util.MatrixState import ftl.util.StopWatch @@ -29,10 +30,10 @@ class TestMatrixStatusPrinter( private fun printTestMatrixStatusList(time: String) { if (args.outputStyle == OutputStyle.Single) { - println() + logLn() } cache.forEach { (id, state) -> - println("${FtlConstants.indent}$time $id $state") + logLn("${FtlConstants.indent}$time $id $state") } } } diff --git a/test_runner/src/main/kotlin/ftl/shard/CacheReport.kt b/test_runner/src/main/kotlin/ftl/shard/CacheReport.kt index f47c933969..de9ca73f13 100644 --- a/test_runner/src/main/kotlin/ftl/shard/CacheReport.kt +++ b/test_runner/src/main/kotlin/ftl/shard/CacheReport.kt @@ -1,5 +1,6 @@ package ftl.shard +import ftl.log.logLn import ftl.util.FlankTestMethod import kotlin.math.roundToInt @@ -7,8 +8,8 @@ fun printCacheInfo(testsToRun: List, previousMethodDurations: M val allTestCount = testsToRun.size val cacheHit = cacheHit(allTestCount, calculateCacheMiss(testsToRun, previousMethodDurations)) val cachePercent = cachePercent(allTestCount, cacheHit) - println() - println(" Smart Flank cache hit: ${cachePercent.roundToInt()}% ($cacheHit / $allTestCount)") + logLn() + logLn(" Smart Flank cache hit: ${cachePercent.roundToInt()}% ($cacheHit / $allTestCount)") } private fun cacheHit(allTestCount: Int, cacheMiss: Int) = allTestCount - cacheMiss diff --git a/test_runner/src/main/kotlin/ftl/shard/Shard.kt b/test_runner/src/main/kotlin/ftl/shard/Shard.kt index 72430e5935..57394281b7 100644 --- a/test_runner/src/main/kotlin/ftl/shard/Shard.kt +++ b/test_runner/src/main/kotlin/ftl/shard/Shard.kt @@ -3,6 +3,7 @@ package ftl.shard import ftl.args.AndroidArgs import ftl.args.IArgs import ftl.args.IosArgs +import ftl.log.logLn import ftl.reports.xml.model.JUnitTestResult import ftl.run.exception.FlankConfigurationError import ftl.util.FlankTestMethod @@ -100,7 +101,7 @@ private fun matchNumberOfShardsWithTestCount(maxShards: Int, testCount: Int) = private val IArgs.platformName get() = if (this is IosArgs) "ios" else "android" private fun printShardsInfo(shards: List) { - println(" Shard times: " + shards.joinToString(", ") { "${it.time.roundToInt()}s" } + "\n") + logLn(" Shard times: " + shards.joinToString(", ") { "${it.time.roundToInt()}s" } + "\n") } private fun createShardsForTestCases( diff --git a/test_runner/src/main/kotlin/ftl/util/Bash.kt b/test_runner/src/main/kotlin/ftl/util/Bash.kt index e51a35eb03..0810a05e09 100644 --- a/test_runner/src/main/kotlin/ftl/util/Bash.kt +++ b/test_runner/src/main/kotlin/ftl/util/Bash.kt @@ -1,13 +1,14 @@ package ftl.util import ftl.config.FtlConstants +import ftl.log.logLn import ftl.run.exception.FlankGeneralError import java.lang.ProcessBuilder.Redirect.PIPE object Bash { fun execute(cmd: String): String { - println(cmd) + logLn(cmd) val bashPath = if (FtlConstants.isWindows) "bash.exe" else "/bin/bash" diff --git a/test_runner/src/main/kotlin/ftl/util/ProgressBar.kt b/test_runner/src/main/kotlin/ftl/util/ProgressBar.kt index 0d5734396e..d674ba9a0a 100644 --- a/test_runner/src/main/kotlin/ftl/util/ProgressBar.kt +++ b/test_runner/src/main/kotlin/ftl/util/ProgressBar.kt @@ -1,5 +1,8 @@ package ftl.util +import ftl.log.OutputLogLevel +import ftl.log.log +import ftl.log.logLn import java.util.Timer import java.util.TimerTask @@ -8,12 +11,12 @@ class ProgressBar { private val timer = Timer(true) fun start(msg: String) { - print(" $msg ") + log(" $msg ", OutputLogLevel.DETAILED) timer.scheduleAtFixedRate(task, 0, 10_000) } fun stop() { - println() + logLn(level = OutputLogLevel.DETAILED) timer.cancel() task.cancel() } @@ -21,7 +24,7 @@ class ProgressBar { private class ProgressBarTask : TimerTask() { override fun run() { - print(".") + log(".", OutputLogLevel.DETAILED) } } diff --git a/test_runner/src/main/kotlin/ftl/util/StopWatchMatrix.kt b/test_runner/src/main/kotlin/ftl/util/StopWatchMatrix.kt index a6a6764ac1..b29e1a6372 100644 --- a/test_runner/src/main/kotlin/ftl/util/StopWatchMatrix.kt +++ b/test_runner/src/main/kotlin/ftl/util/StopWatchMatrix.kt @@ -1,11 +1,12 @@ package ftl.util import ftl.config.FtlConstants +import ftl.log.logLn class StopWatchMatrix(private val stopwatch: StopWatch, private val matrixId: String) { fun puts(msg: String) { val timestamp = stopwatch.check(alignSeconds = true) - println("${FtlConstants.indent}$timestamp $matrixId $msg") + logLn("${FtlConstants.indent}$timestamp $matrixId $msg") } } diff --git a/test_runner/src/test/kotlin/Debug.kt b/test_runner/src/test/kotlin/Debug.kt index 09a77cf576..8dd5cdefbf 100644 --- a/test_runner/src/test/kotlin/Debug.kt +++ b/test_runner/src/test/kotlin/Debug.kt @@ -14,7 +14,7 @@ fun main() { ?: "YOUR PROJECT ID" val quantity = "single" - val type = "gameloop" + val type = "success" val extra = "ios" // Bugsnag keeps the process alive so we must call exitProcess @@ -24,7 +24,7 @@ fun main() { // "--debug", "firebase", "test", - "ios", + "android", "run", // "--dry", // "--dump-shards", diff --git a/test_runner/src/test/kotlin/ftl/log/OutputLoggerTest.kt b/test_runner/src/test/kotlin/ftl/log/OutputLoggerTest.kt new file mode 100644 index 0000000000..a8852ba7d9 --- /dev/null +++ b/test_runner/src/test/kotlin/ftl/log/OutputLoggerTest.kt @@ -0,0 +1,45 @@ +package ftl.log + +import com.google.common.truth.Truth +import ftl.test.util.TestHelper.normalizeLineEnding +import org.junit.After +import org.junit.Rule +import org.junit.Test +import org.junit.contrib.java.lang.system.SystemOutRule + +class OutputLoggerTest { + + @Rule + @JvmField + val systemOutRule: SystemOutRule = SystemOutRule().enableLog().muteForSuccessfulTests() + + private val simpleMessage = "print for simple" + private val detailedMessage = "print for detailed" + + @After + fun afterTest() { + setLogLevel(OutputLogLevel.DETAILED) + } + + @Test + fun `should print messages from all output levels if log level set to detailed`() { + setLogLevel(OutputLogLevel.DETAILED) + + logLn(simpleMessage) + logLn(detailedMessage, OutputLogLevel.DETAILED) + + Truth.assertThat(systemOutRule.log.normalizeLineEnding()).contains(simpleMessage) + Truth.assertThat(systemOutRule.log.normalizeLineEnding()).contains(detailedMessage) + } + + @Test + fun `should print messages only simple output level if log level not set`() { + setLogLevel(OutputLogLevel.SIMPLE) + + logLn(simpleMessage) + logLn(detailedMessage, OutputLogLevel.DETAILED) + + Truth.assertThat(systemOutRule.log.normalizeLineEnding()).contains(simpleMessage) + Truth.assertThat(systemOutRule.log.normalizeLineEnding()).doesNotContain(detailedMessage) + } +} diff --git a/test_runner/src/test/kotlin/ftl/util/ProgressBarTest.kt b/test_runner/src/test/kotlin/ftl/util/ProgressBarTest.kt index d839d4a34a..0b7dadba1d 100644 --- a/test_runner/src/test/kotlin/ftl/util/ProgressBarTest.kt +++ b/test_runner/src/test/kotlin/ftl/util/ProgressBarTest.kt @@ -1,10 +1,13 @@ package ftl.util import com.google.common.truth.Truth.assertThat +import ftl.log.OutputLogLevel +import ftl.log.setLogLevel import ftl.test.util.TestHelper.normalizeLineEnding import io.mockk.every import io.mockk.mockk import io.mockk.verify +import org.junit.Before import org.junit.Rule import org.junit.Test import org.junit.contrib.java.lang.system.SystemOutRule @@ -15,6 +18,11 @@ class ProgressBarTest { @JvmField val systemOutRule: SystemOutRule = SystemOutRule().enableLog().muteForSuccessfulTests() + @Before + fun beforeTest() { + setLogLevel(OutputLogLevel.DETAILED) + } + @Test fun `progress start stop`() { val progress = ProgressBar()