From d4db837decd62242d81670fd22945f627e17575f Mon Sep 17 00:00:00 2001 From: Ilya Ryzhenkov Date: Tue, 15 Jul 2014 20:56:23 +0400 Subject: [PATCH] Fix fails() assertion which was silently swallowing exceptions. --- libraries/stdlib/src/kotlin/test/Test.kt | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/libraries/stdlib/src/kotlin/test/Test.kt b/libraries/stdlib/src/kotlin/test/Test.kt index e76a0710c9a..446757e0a72 100644 --- a/libraries/stdlib/src/kotlin/test/Test.kt +++ b/libraries/stdlib/src/kotlin/test/Test.kt @@ -81,14 +81,15 @@ public inline fun expect(expected: T, message: String, block: ()-> T) { /** Asserts that given function block fails by throwing an exception */ public fun fails(block: ()-> Unit): Throwable? { + var thrown : Throwable? = null try { block() - asserter.fail("Expected an exception to be thrown") - return null } catch (e: Throwable) { - //println("Caught expected exception: $e") - return e + thrown = e } + if (thrown == null) + asserter.fail("Expected an exception to be thrown") + return thrown } /**