Properly process separate process inputStream/outputStream
This commit is contained in:
@@ -48,15 +48,20 @@ class ProgramWithDependencyOnCompiler(
|
|||||||
private fun runJava(workingDirectory: File, vararg arguments: String): String {
|
private fun runJava(workingDirectory: File, vararg arguments: String): String {
|
||||||
val pb = ProcessBuilder()
|
val pb = ProcessBuilder()
|
||||||
.directory(workingDirectory)
|
.directory(workingDirectory)
|
||||||
.command(KotlinIntegrationTestBase.getJavaRuntime().absolutePath, *arguments)
|
.command(KotlinIntegrationTestBase.getJavaRuntime().absolutePath, *arguments).redirectErrorStream(true)
|
||||||
val process = pb.start()
|
val process = pb.start()
|
||||||
val stdout = String(process.inputStream.readBytes())
|
val stdout = StringBuilder()
|
||||||
val stderr = String(process.errorStream.readBytes())
|
|
||||||
|
process.inputStream.bufferedReader().useLines {
|
||||||
|
it.forEach { string ->
|
||||||
|
stdout.appendLine(string)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
process.waitFor()
|
process.waitFor()
|
||||||
|
|
||||||
TestCase.assertEquals("Exit code should be 0.", 0, process.exitValue())
|
TestCase.assertEquals("Exit code should be 0, but $stdout", 0, process.exitValue())
|
||||||
TestCase.assertEquals("Stderr should be empty.", "", stderr)
|
|
||||||
|
|
||||||
return stdout.trimEnd()
|
return stdout.toString().trimEnd()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user