From 3c548d370e4448f457188981d8d61b43ad6b7fe0 Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Mon, 29 Jun 2020 19:52:45 +0300 Subject: [PATCH] Check exit code when running compiled binary in coverage tests --- .../org/jetbrains/kotlin/CoverageTest.kt | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/build-tools/src/main/kotlin/org/jetbrains/kotlin/CoverageTest.kt b/build-tools/src/main/kotlin/org/jetbrains/kotlin/CoverageTest.kt index f87535592a9..371a8342213 100644 --- a/build-tools/src/main/kotlin/org/jetbrains/kotlin/CoverageTest.kt +++ b/build-tools/src/main/kotlin/org/jetbrains/kotlin/CoverageTest.kt @@ -73,6 +73,7 @@ open class CoverageTest : DefaultTask() { val suffix = target.family.exeSuffix val pathToBinary = "$outputDir/$binaryName/$target/$binaryName.$suffix" runProcess(localExecutor(project), pathToBinary) + .ensureSuccessful(pathToBinary) exec("llvm-profdata", "merge", profrawFile, "-o", profdataFile) val llvmCovResult = exec("llvm-cov", "export", pathToBinary, "-instr-profile", profdataFile) val jsonReport = llvmCovResult.stdOut @@ -93,19 +94,23 @@ open class CoverageTest : DefaultTask() { private fun exec(llvmTool: String, vararg args: String): ProcessOutput { val executable = "$llvmToolsDir/$llvmTool" val result = runProcess(localExecutor(project), executable, args.toList()) - if (result.exitCode != 0) { - println(""" - $llvmTool failed. - exitCode: ${result.exitCode} - stdout: - ${result.stdOut} - stderr: - ${result.stdErr} - """.trimIndent()) - error("$llvmTool failed") - } + result.ensureSuccessful(llvmTool) return result } + + private fun ProcessOutput.ensureSuccessful(executable: String) { + if (exitCode != 0) { + println(""" + $executable failed. + exitCode: $exitCode + stdout: + $stdOut + stderr: + $stdErr + """.trimIndent()) + error("$executable failed") + } + } } private class CoverageValidator(