From 43c64525750c2a1bb809e0fae0c87bdf3ff0e2eb Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Wed, 10 Apr 2019 12:17:54 +0700 Subject: [PATCH] Test runner: Add a flag to ignore failures in the exit code Kotlin/Native test runner sets the exit code to a non-zero value if there are failing tests. This patch adds a flag allowing a user to disable this feature and make the runner to always return 0. Note the exit code is still returned using the `exitProcess` call. --- .../kotlin/native/internal/test/TestRunner.kt | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/runtime/src/main/kotlin/kotlin/native/internal/test/TestRunner.kt b/runtime/src/main/kotlin/kotlin/native/internal/test/TestRunner.kt index d66a5a0f1f4..6ca30decc49 100644 --- a/runtime/src/main/kotlin/kotlin/native/internal/test/TestRunner.kt +++ b/runtime/src/main/kotlin/kotlin/native/internal/test/TestRunner.kt @@ -15,6 +15,7 @@ internal class TestRunner(val suites: List, args: Array) { private val listeners = mutableSetOf() private var logger: TestLogger = GTestLogger() private var runTests = true + private var useExitCode = true var iterations = 1 private set var exitCode = 0 @@ -35,6 +36,7 @@ internal class TestRunner(val suites: List, args: Array) { "--help" -> { logger.log(help); runTests = false } + "--ktest_no_exit_code" -> useExitCode = false else -> throw IllegalArgumentException("Unknown option: $it\n$help") } 2 -> { @@ -50,9 +52,7 @@ internal class TestRunner(val suites: List, args: Array) { "--ktest_negative_gradle_filter" -> setGradleFilterFromArg(value, false) "--ktest_repeat", "--gtest_repeat" -> iterations = value.toIntOrNull() ?: throw IllegalArgumentException("Cannot parse number: $value") - else -> if (key.startsWith("--ktest_")) { - throw IllegalArgumentException("Unknown option: $it\n$help") - } + else -> throw IllegalArgumentException("Unknown option: $it\n$help") } } else -> throw IllegalArgumentException("Unknown option: $it\n$help") @@ -101,6 +101,8 @@ internal class TestRunner(val suites: List, args: Array) { * Use a negative count to repeat forever. * * --ktest_logger=GTEST|TEAMCITY|SIMPLE|SILENT - Use the specified output format. The default one is GTEST. + * + * --ktest_no_exit_code - Don't return a non-zero exit code if there are failing tests. */ private fun String.substringEscaped(range: IntRange) = @@ -213,6 +215,8 @@ internal class TestRunner(val suites: List, args: Array) { | Use a negative count to repeat forever. | |--ktest_logger=GTEST|TEAMCITY|SIMPLE|SILENT - Use the specified output format. The default one is GTEST. + | + |--ktest_no_exit_code - Don't return a non-zero exit code if there are failing tests. """.trimMargin() private inline fun sendToListeners(event: TestListener.() -> Unit) { @@ -233,7 +237,9 @@ internal class TestRunner(val suites: List, args: Array) { sendToListeners { pass(testCase, getTimeMillis() - startTime) } } catch (e: Throwable) { sendToListeners { fail(testCase, e, getTimeMillis() - startTime) } - exitCode = 1 + if (useExitCode) { + exitCode = 1 + } } } } @@ -270,6 +276,5 @@ internal class TestRunner(val suites: List, args: Array) { } sendToListeners { finishTesting(this@TestRunner, totalTime) } return exitCode - } }