Provide a way to force stdout output in Gradle tests
This commit is contained in:
+7
-3
@@ -73,7 +73,8 @@ abstract class BaseGradleIT {
|
|||||||
val daemonOptionSupported: Boolean = true,
|
val daemonOptionSupported: Boolean = true,
|
||||||
val incremental: Boolean? = null,
|
val incremental: Boolean? = null,
|
||||||
val androidHome: File? = null,
|
val androidHome: File? = null,
|
||||||
val androidGradlePluginVersion: String? = null)
|
val androidGradlePluginVersion: String? = null,
|
||||||
|
val forceOutputToStdout: Boolean = false)
|
||||||
|
|
||||||
open inner class Project(
|
open inner class Project(
|
||||||
val projectName: String,
|
val projectName: String,
|
||||||
@@ -141,12 +142,15 @@ abstract class BaseGradleIT {
|
|||||||
setupWorkingDir()
|
setupWorkingDir()
|
||||||
}
|
}
|
||||||
|
|
||||||
val result = runProcess(cmd, projectDir, env)
|
val result = runProcess(cmd, projectDir, env, options)
|
||||||
try {
|
try {
|
||||||
CompiledProject(this, result.output, result.exitCode).check()
|
CompiledProject(this, result.output, result.exitCode).check()
|
||||||
}
|
}
|
||||||
catch (t: Throwable) {
|
catch (t: Throwable) {
|
||||||
System.out.println(result.output)
|
// to prevent duplication of output
|
||||||
|
if (!options.forceOutputToStdout) {
|
||||||
|
System.out.println(result.output)
|
||||||
|
}
|
||||||
throw t
|
throw t
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-5
@@ -1,7 +1,7 @@
|
|||||||
package org.jetbrains.kotlin.gradle.util
|
package org.jetbrains.kotlin.gradle.util
|
||||||
|
|
||||||
|
import org.jetbrains.kotlin.gradle.BaseGradleIT
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.StringWriter
|
|
||||||
|
|
||||||
class ProcessRunResult(
|
class ProcessRunResult(
|
||||||
private val cmd: List<String>,
|
private val cmd: List<String>,
|
||||||
@@ -20,7 +20,12 @@ Executing process was ${if (isSuccessful) "successful" else "unsuccessful"}
|
|||||||
"""
|
"""
|
||||||
}
|
}
|
||||||
|
|
||||||
fun runProcess(cmd: List<String>, workingDir: File, environmentVariables: Map<String, String> = mapOf()): ProcessRunResult {
|
fun runProcess(
|
||||||
|
cmd: List<String>,
|
||||||
|
workingDir: File,
|
||||||
|
environmentVariables: Map<String, String> = mapOf(),
|
||||||
|
options: BaseGradleIT.BuildOptions? = null
|
||||||
|
): ProcessRunResult {
|
||||||
val builder = ProcessBuilder(cmd)
|
val builder = ProcessBuilder(cmd)
|
||||||
builder.environment().putAll(environmentVariables)
|
builder.environment().putAll(environmentVariables)
|
||||||
builder.directory(workingDir)
|
builder.directory(workingDir)
|
||||||
@@ -29,11 +34,16 @@ fun runProcess(cmd: List<String>, workingDir: File, environmentVariables: Map<St
|
|||||||
|
|
||||||
val process = builder.start()
|
val process = builder.start()
|
||||||
// important to read inputStream, otherwise the process may hang on some systems
|
// important to read inputStream, otherwise the process may hang on some systems
|
||||||
val sw = StringWriter()
|
val sb = StringBuilder()
|
||||||
process.inputStream!!.bufferedReader().copyTo(sw)
|
process.inputStream!!.bufferedReader().forEachLine {
|
||||||
|
if (options?.forceOutputToStdout ?: false) {
|
||||||
|
System.out.println(it)
|
||||||
|
}
|
||||||
|
sb.appendln(it)
|
||||||
|
}
|
||||||
val exitCode = process.waitFor()
|
val exitCode = process.waitFor()
|
||||||
|
|
||||||
return ProcessRunResult(cmd, workingDir, exitCode, sw.toString())
|
return ProcessRunResult(cmd, workingDir, exitCode, sb.toString())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun createGradleCommand(tailParameters: List<String>): List<String> {
|
fun createGradleCommand(tailParameters: List<String>): List<String> {
|
||||||
|
|||||||
Reference in New Issue
Block a user