Fix fails() assertion which was silently swallowing exceptions.
This commit is contained in:
committed by
Evgeny Gerashchenko
parent
0b7699b844
commit
d4db837dec
@@ -81,14 +81,15 @@ public inline fun <T> expect(expected: T, message: String, block: ()-> T) {
|
|||||||
|
|
||||||
/** Asserts that given function block fails by throwing an exception */
|
/** Asserts that given function block fails by throwing an exception */
|
||||||
public fun fails(block: ()-> Unit): Throwable? {
|
public fun fails(block: ()-> Unit): Throwable? {
|
||||||
|
var thrown : Throwable? = null
|
||||||
try {
|
try {
|
||||||
block()
|
block()
|
||||||
asserter.fail("Expected an exception to be thrown")
|
|
||||||
return null
|
|
||||||
} catch (e: Throwable) {
|
} catch (e: Throwable) {
|
||||||
//println("Caught expected exception: $e")
|
thrown = e
|
||||||
return e
|
|
||||||
}
|
}
|
||||||
|
if (thrown == null)
|
||||||
|
asserter.fail("Expected an exception to be thrown")
|
||||||
|
return thrown
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user