From 719ed4c795c86648302a773c58b449c0d92a0a14 Mon Sep 17 00:00:00 2001 From: Evgeny Gerashchenko Date: Tue, 29 Jan 2013 20:43:26 +0400 Subject: [PATCH] failsWith is really checking for exception class. --- libraries/stdlib/src/kotlin/test/TestJVM.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) 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 } }