From d8f839a7e40ea69c58cbe93a1b1bf3fa4903a1a8 Mon Sep 17 00:00:00 2001 From: Mikhael Bogdanov Date: Wed, 21 Jul 2021 13:27:21 +0200 Subject: [PATCH] Properly process separate process inputStream/outputStream --- .../ProgramWithDependencyOnCompiler.kt | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/compiler/tests/org/jetbrains/kotlin/integration/ProgramWithDependencyOnCompiler.kt b/compiler/tests/org/jetbrains/kotlin/integration/ProgramWithDependencyOnCompiler.kt index 4e9cdcc7d99..3313fddd10f 100644 --- a/compiler/tests/org/jetbrains/kotlin/integration/ProgramWithDependencyOnCompiler.kt +++ b/compiler/tests/org/jetbrains/kotlin/integration/ProgramWithDependencyOnCompiler.kt @@ -48,15 +48,20 @@ class ProgramWithDependencyOnCompiler( private fun runJava(workingDirectory: File, vararg arguments: String): String { val pb = ProcessBuilder() .directory(workingDirectory) - .command(KotlinIntegrationTestBase.getJavaRuntime().absolutePath, *arguments) + .command(KotlinIntegrationTestBase.getJavaRuntime().absolutePath, *arguments).redirectErrorStream(true) val process = pb.start() - val stdout = String(process.inputStream.readBytes()) - val stderr = String(process.errorStream.readBytes()) + val stdout = StringBuilder() + + process.inputStream.bufferedReader().useLines { + it.forEach { string -> + stdout.appendLine(string) + } + } + process.waitFor() - TestCase.assertEquals("Exit code should be 0.", 0, process.exitValue()) - TestCase.assertEquals("Stderr should be empty.", "", stderr) + TestCase.assertEquals("Exit code should be 0, but $stdout", 0, process.exitValue()) - return stdout.trimEnd() + return stdout.toString().trimEnd() } }