org.jetbrains.spek.engine.ThrowableCollector.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of spek-junit-platform-engine Show documentation
Show all versions of spek-junit-platform-engine Show documentation
Spek TestEngine for the JUnit Platform
package org.jetbrains.spek.engine
/**
* @author Ranie Jade Ramiso
*/
class ThrowableCollector {
private var throwable: Throwable? = null
fun add(throwable: Throwable) {
if (this.throwable == null) {
this.throwable = throwable
} else {
(this.throwable as java.lang.Throwable).addSuppressed(throwable)
}
}
inline fun executeSafely(block: () -> Unit) {
try {
block.invoke()
} catch (e: Throwable) {
add(e)
}
}
fun isEmpty() = throwable == null
fun assertEmpty() {
throwable?.let {
if (it !is AssertionError) it.printStackTrace()
throw it
}
}
}