Generalize test exception catching to Throwable so that you can test for RuntimeExceptions.
This commit is contained in:
@@ -84,19 +84,19 @@ 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 */
|
||||||
fun fails(block: ()-> Unit): Exception? {
|
fun fails(block: ()-> Unit): Throwable? {
|
||||||
try {
|
try {
|
||||||
block()
|
block()
|
||||||
asserter().fail("Expected an exception to be thrown")
|
asserter().fail("Expected an exception to be thrown")
|
||||||
return null
|
return null
|
||||||
} catch (e: Exception) {
|
} catch (e: Throwable) {
|
||||||
println("Caught excepted exception: $e")
|
println("Caught excepted exception: $e")
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Asserts that a block fails with a specific exception being thrown */
|
/** Asserts that a block fails with a specific exception being thrown */
|
||||||
fun <T: Exception> failsWith(block: ()-> Unit) {
|
fun <T: Throwable> failsWith(block: ()-> Unit) {
|
||||||
try {
|
try {
|
||||||
block()
|
block()
|
||||||
asserter().fail("Expected an exception to be thrown")
|
asserter().fail("Expected an exception to be thrown")
|
||||||
|
|||||||
Reference in New Issue
Block a user