import kotlin.test.fail inline fun 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 println("expected to throw $name but instead threw ${x::class.simpleName}: $x\b\n${x.stackTraceToString()}") fail("expected to throw $name but instead threw ${x::class.simpleName}: $x\b\n${x.stackTraceToString()}") } }