crypto2/src/commonTest/kotlin/assertThrows.kt

13 lines
358 B
Kotlin

import kotlin.test.fail
inline fun <reified T: Throwable>assertThrows(f: ()->Unit): T {
val name = T::class.simpleName
try {
f()
fail("expected to throw $name but threw nothing")
}
catch(x: Throwable) {
if( x is T ) return x
fail("expected to throw $name but instead threw ${x::class.simpleName}: $x")
}
}