diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/LoggedData.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/LoggedData.kt index a7cdbab02af..404f080bf52 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/LoggedData.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/LoggedData.kt @@ -98,9 +98,7 @@ internal abstract class LoggedData { appendLine("- Exit code: ${exitCode.code} (${exitCode.name})") appendDuration(duration) appendLine() - appendLine("========== BEGIN: RAW COMPILER OUTPUT ==========") - if (compilerOutput.isNotEmpty()) appendLine(compilerOutput.trimEnd()) - appendLine("========== END: RAW COMPILER OUTPUT ==========") + appendPotentiallyLargeOutput(compilerOutput, "RAW COMPILER OUTPUT", truncateLargeOutput = false) appendLine() appendLine(parameters) } @@ -223,16 +221,24 @@ internal abstract class LoggedData { appendLine("- Exit code: ${runResult.exitCode ?: ""}") appendDuration(runResult.duration) appendLine() - appendLine("========== BEGIN: STDOUT ==========") - val stdOut = runResult.processOutput.stdOut.filteredOutput - if (stdOut.isNotEmpty()) appendLine(stdOut.trimEnd()) - appendLine("========== END: STDOUT ==========") + appendPotentiallyLargeOutput(runResult.processOutput.stdOut.filteredOutput, "STDOUT", truncateLargeOutput = true) appendLine() - appendLine("========== BEGIN: STDERR ==========") - val stdErr = runResult.processOutput.stdErr - if (stdErr.isNotEmpty()) appendLine(stdErr.trimEnd()) - appendLine("========== END: STDERR ==========") + appendPotentiallyLargeOutput(runResult.processOutput.stdErr, "STDERR", truncateLargeOutput = true) return this } + + private fun StringBuilder.appendPotentiallyLargeOutput(output: String, subject: String, truncateLargeOutput: Boolean) { + appendLine("========== BEGIN: $subject ==========") + if (output.length > MAX_PRINTED_OUTPUT_LENGTH && truncateLargeOutput) { + append(output.substring(0, MAX_PRINTED_OUTPUT_LENGTH).trimEnd()).appendLine("...") + appendLine() + appendLine("********** The output is too large (${output.length} characters in total), it has been truncated to avoid excessive logs **********") + } else if (output.isNotEmpty()) { + appendLine(output.trimEnd()) + } + appendLine("========== END: $subject ==========") + } + + private const val MAX_PRINTED_OUTPUT_LENGTH = 8 * 1024 } } diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/AbstractLocalProcessRunner.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/AbstractLocalProcessRunner.kt index 09da973bdfc..848426eabe5 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/AbstractLocalProcessRunner.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/AbstractLocalProcessRunner.kt @@ -75,7 +75,7 @@ internal abstract class AbstractLocalProcessRunner(private val executionTimeo abstract inner class ResultHandler(runResult: RunResult.Completed) : AbstractRunner.ResultHandler(runResult) { override fun handle(): R { - verifyExpectation(0, runResult.exitCode) { "$visibleProcessName exited with non-zero code." } + verifyExpectation(runResult.exitCode == 0) { "$visibleProcessName exited with non-zero code." } return doHandle() } diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/AbstractRunner.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/AbstractRunner.kt index 52dfdc5bdd6..f424512d3e9 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/AbstractRunner.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/AbstractRunner.kt @@ -6,7 +6,6 @@ package org.jetbrains.kotlin.konan.blackboxtest.support.runner import org.jetbrains.kotlin.konan.blackboxtest.support.LoggedData -import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertEquals import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertTrue import org.jetbrains.kotlin.test.services.JUnit5Assertions.fail import org.opentest4j.TestAbortedException @@ -47,10 +46,6 @@ internal abstract class AbstractRunner { abstract fun getLoggedRun(): LoggedData abstract fun handle(): R - protected inline fun verifyExpectation(expected: T, actual: T, crossinline errorMessage: () -> String) { - assertEquals(expected, actual) { getLoggedRun().withErrorMessage(errorMessage()) } - } - protected inline fun verifyExpectation(shouldBeTrue: Boolean, crossinline errorMessage: () -> String) { assertTrue(shouldBeTrue) { getLoggedRun().withErrorMessage(errorMessage()) } } diff --git a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/LocalTestRunner.kt b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/LocalTestRunner.kt index 5400ddd815e..906a5c92abd 100644 --- a/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/LocalTestRunner.kt +++ b/native/native.tests/tests/org/jetbrains/kotlin/konan/blackboxtest/support/runner/LocalTestRunner.kt @@ -91,7 +91,9 @@ internal class LocalTestRunner( private fun verifyNonTestOutput(nonTestOutput: String) { testRun.runParameters.get { - verifyExpectation(convertLineSeparators(expectedOutputDataFile.readText()), convertLineSeparators(nonTestOutput)) { + // Don't use verifyExpectation(expected, actual) to avoid exposing potentially large test output in exception message + // and blowing up test logs. + verifyExpectation(convertLineSeparators(expectedOutputDataFile.readText()) == convertLineSeparators(nonTestOutput)) { "Tested process output mismatch. See \"TEST STDOUT\" and \"EXPECTED OUTPUT DATA FILE\" below." } }