Print build output on build result assertion failure.
^KT-45745 In Progress
This commit is contained in:
+20
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.gradle.testbase
|
||||
|
||||
import org.gradle.testkit.runner.BuildResult
|
||||
|
||||
internal fun BuildResult.printBuildOutput() {
|
||||
println(
|
||||
"""
|
||||
|Failed assertion build output:
|
||||
|#######################
|
||||
|$output
|
||||
|#######################
|
||||
|
|
||||
""".trimMargin()
|
||||
)
|
||||
}
|
||||
+7
@@ -14,6 +14,7 @@ fun BuildResult.assertOutputContains(
|
||||
expectedSubString: String
|
||||
) {
|
||||
assert(output.contains(expectedSubString)) {
|
||||
printBuildOutput()
|
||||
"Build output does not contain \"$expectedSubString\""
|
||||
}
|
||||
}
|
||||
@@ -28,6 +29,8 @@ fun BuildResult.assertOutputDoesNotContain(
|
||||
wrappingCharsCount: Int = 100,
|
||||
) {
|
||||
assert(!output.contains(notExpectedSubString)) {
|
||||
printBuildOutput()
|
||||
|
||||
// In case if notExpectedSubString is multiline string
|
||||
val occurrences = mutableListOf<Pair<Int, Int>>()
|
||||
var startIndex = output.indexOf(notExpectedSubString)
|
||||
@@ -64,6 +67,8 @@ fun BuildResult.assertOutputContains(
|
||||
expected: Regex
|
||||
) {
|
||||
assert(output.contains(expected)) {
|
||||
printBuildOutput()
|
||||
|
||||
"Build output does not contain any line matching '$expected' regex."
|
||||
}
|
||||
}
|
||||
@@ -75,6 +80,8 @@ fun BuildResult.assertOutputDoesNotContain(
|
||||
regexToCheck: Regex
|
||||
) {
|
||||
assert(!output.contains(regexToCheck)) {
|
||||
printBuildOutput()
|
||||
|
||||
val matchedStrings = regexToCheck
|
||||
.findAll(output)
|
||||
.map { it.value }
|
||||
|
||||
+6
@@ -14,6 +14,7 @@ import org.gradle.testkit.runner.TaskOutcome
|
||||
fun BuildResult.assertTasksExecuted(vararg tasks: String) {
|
||||
tasks.forEach { task ->
|
||||
assert(task(task)?.outcome == TaskOutcome.SUCCESS) {
|
||||
printBuildOutput()
|
||||
"Task $task didn't have 'SUCCESS' state: ${task(task)?.outcome}"
|
||||
}
|
||||
}
|
||||
@@ -25,6 +26,7 @@ fun BuildResult.assertTasksExecuted(vararg tasks: String) {
|
||||
fun BuildResult.assertTasksFailed(vararg tasks: String) {
|
||||
tasks.forEach { task ->
|
||||
assert(task(task)?.outcome == TaskOutcome.FAILED) {
|
||||
printBuildOutput()
|
||||
"Task $task didn't have 'FAILED' state: ${task(task)?.outcome}"
|
||||
}
|
||||
}
|
||||
@@ -36,6 +38,7 @@ fun BuildResult.assertTasksFailed(vararg tasks: String) {
|
||||
fun BuildResult.assertTasksUpToDate(vararg tasks: String) {
|
||||
tasks.forEach { task ->
|
||||
assert(task(task)?.outcome == TaskOutcome.UP_TO_DATE) {
|
||||
printBuildOutput()
|
||||
"Task $task didn't have 'UP-TO-DATE' state: ${task(task)?.outcome}"
|
||||
}
|
||||
}
|
||||
@@ -47,6 +50,7 @@ fun BuildResult.assertTasksUpToDate(vararg tasks: String) {
|
||||
fun BuildResult.assertTasksSkipped(vararg tasks: String) {
|
||||
tasks.forEach { task ->
|
||||
assert(task(task)?.outcome == TaskOutcome.SKIPPED) {
|
||||
printBuildOutput()
|
||||
"Task $task didn't have 'SKIPPED' state: ${task(task)?.outcome}"
|
||||
}
|
||||
}
|
||||
@@ -58,6 +62,7 @@ fun BuildResult.assertTasksSkipped(vararg tasks: String) {
|
||||
fun BuildResult.assertTasksFromCache(vararg tasks: String) {
|
||||
tasks.forEach { task ->
|
||||
assert(task(task)?.outcome == TaskOutcome.FROM_CACHE) {
|
||||
printBuildOutput()
|
||||
"Task $task didn't have 'FROM_CACHE' state: ${task(task)?.outcome}"
|
||||
}
|
||||
}
|
||||
@@ -69,6 +74,7 @@ fun BuildResult.assertTasksFromCache(vararg tasks: String) {
|
||||
fun BuildResult.assertTasksNoSource(vararg tasks: String) {
|
||||
tasks.forEach { task ->
|
||||
assert(task(task)?.outcome == TaskOutcome.NO_SOURCE) {
|
||||
printBuildOutput()
|
||||
"Task $task didn't have 'NO_SOURCE' state: ${task(task)?.outcome}"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user