diff --git a/libraries/stdlib/src/kotlin/test/TestJVM.kt b/libraries/stdlib/src/kotlin/test/TestJVM.kt index 484938966a9..44c230dd119 100644 --- a/libraries/stdlib/src/kotlin/test/TestJVM.kt +++ b/libraries/stdlib/src/kotlin/test/TestJVM.kt @@ -3,15 +3,16 @@ package kotlin.test import java.util.ServiceLoader /** Asserts that a block fails with a specific exception being thrown */ -public fun failsWith(block: ()-> Any): T { +public fun failsWith(exceptionClass: Class, block: ()-> Any): T { try { block() asserter.fail("Expected an exception to be thrown") throw IllegalStateException("Should have failed") } catch (e: T) { - //println("Caught expected exception: $e") - // OK - return e + if (exceptionClass.isInstance(e)) { + return e + } + throw e } }