Scripting: refactor test infrastructure - add missing stderr handling
This commit is contained in:
committed by
Space Team
parent
e927ac5fc3
commit
a47ee44e65
+4
-2
@@ -163,12 +163,13 @@ class MainKtsIT {
|
||||
fun runWithKotlincAndMainKts(
|
||||
scriptPath: String,
|
||||
expectedOutPatterns: List<String> = emptyList(),
|
||||
expectedErrPatterns: List<String> = emptyList(),
|
||||
expectedExitCode: Int = 0,
|
||||
cacheDir: Path? = null
|
||||
) {
|
||||
val paths = PathUtil.kotlinPathsForDistDirectory
|
||||
runWithKotlinc(
|
||||
scriptPath, expectedOutPatterns, expectedExitCode,
|
||||
scriptPath, expectedOutPatterns, expectedErrPatterns, expectedExitCode,
|
||||
classpath = listOf(
|
||||
paths.jar(KotlinPaths.Jar.MainKts).also {
|
||||
Assert.assertTrue("kotlin-main-kts.jar not found, run dist task: ${it.absolutePath}", it.exists())
|
||||
@@ -181,12 +182,13 @@ fun runWithKotlincAndMainKts(
|
||||
fun runWithKotlinRunner(
|
||||
scriptPath: String,
|
||||
expectedOutPatterns: List<String> = emptyList(),
|
||||
expectedErrPatterns: List<String> = emptyList(),
|
||||
expectedExitCode: Int = 0,
|
||||
cacheDir: Path? = null,
|
||||
expectErrorOnK2: Boolean = false
|
||||
) {
|
||||
runWithKotlinLauncherScript(
|
||||
"kotlin", listOf(scriptPath), expectedOutPatterns, expectedExitCode,
|
||||
"kotlin", listOf(scriptPath), expectedOutPatterns, expectedErrPatterns, expectedExitCode,
|
||||
additionalEnvVars = listOf(COMPILED_SCRIPTS_CACHE_DIR_ENV_VAR to (cacheDir?.toAbsolutePath()?.toString() ?: "")),
|
||||
expectErrorOnK2 = expectErrorOnK2
|
||||
)
|
||||
|
||||
+9
-2
@@ -403,17 +403,24 @@ class CacheDirectoryDetectorTest {
|
||||
private val directories = Directories(systemProperties, environment)
|
||||
}
|
||||
|
||||
internal fun captureOut(body: () -> Unit): String {
|
||||
internal fun captureOut(body: () -> Unit): String = captureOutAndErr(body).first
|
||||
|
||||
internal fun captureOutAndErr(body: () -> Unit): Pair<String, String> {
|
||||
val outStream = ByteArrayOutputStream()
|
||||
val errStream = ByteArrayOutputStream()
|
||||
val prevOut = System.out
|
||||
val prevErr = System.err
|
||||
System.setOut(PrintStream(outStream))
|
||||
System.setErr(PrintStream(errStream))
|
||||
try {
|
||||
body()
|
||||
} finally {
|
||||
System.out.flush()
|
||||
System.err.flush()
|
||||
System.setOut(prevOut)
|
||||
System.setErr(prevErr)
|
||||
}
|
||||
return outStream.toString().trim()
|
||||
return outStream.toString().trim() to errStream.toString().trim()
|
||||
}
|
||||
|
||||
internal fun <T> withProperty(name: String, value: String?, body: () -> T): T {
|
||||
|
||||
Reference in New Issue
Block a user