[Gradle][Minor] runLifecycleAwareTest: Prefer re-throwing AssertionError

^KT-58255 Verification Pending
This commit is contained in:
Sebastian Sellmair
2023-05-04 10:03:10 +02:00
committed by Space Team
parent 0ab0788763
commit b53bf4b148
@@ -8,8 +8,17 @@ package org.jetbrains.kotlin.gradle.util
import org.gradle.api.Project
import org.gradle.api.internal.project.ProjectInternal
import org.jetbrains.kotlin.gradle.plugin.kotlinPluginLifecycle
import org.jetbrains.kotlin.tooling.core.withLinearClosure
import java.lang.AssertionError
fun Project.runLifecycleAwareTest(block: suspend Project.() -> Unit) {
kotlinPluginLifecycle.launch { block() }
(this as ProjectInternal).evaluate()
try {
(this as ProjectInternal).evaluate()
} catch (t: Throwable) {
/* Prefer throwing AssertionError directly, if possible */
val allCauses = t.withLinearClosure { it.cause }
allCauses.find { it is AssertionError }?.let { throw it }
throw t
}
}