scoop:scoop.test:0.1.0
src/exceptions.scoop
Selected production source · src/exceptions.scoop
1
package scoop.test3
/**4
* Runs the block and returns the thrown exception if it has the requested type. Normal return or5
* another exception type produces [AssertionFailure]; a mismatched exception is retained as its6
* cause.7
*/8
public fun <E : Throwable> assertFailsWith(9
message: String? = None,10
location: SourceLocation = currentSourceLocation(),11
block: () -> Unit12
): E {13
val caught: Throwable? = try {14
block()15
None16
} catch (error: Throwable) {17
Some(error)18
}19
when (caught) {20
case Some(val error) -> {21
if (error is E) return error22
throw AssertionFailure("assertFailsWith", message, location, cause = Some(error))23
}24
case None -> throw AssertionFailure("assertFailsWith", message, location)25
}26
}