Commit e5fd9103 authored by Drew's avatar Drew

Assert for non-throwing

parent 35fb0c96
Pipeline #2396 failed with stage
in 42 seconds
......@@ -132,6 +132,20 @@ extension CarolineTest {
}
#endif
///Assert that the passed closure doesn't throw
///- returns: nil if the calling closure throws, otherwise the return value.
///It's not okay to force-unwrap this, use a construction like
///guard let a = self.dontThrow(closure: { /* */ }) else { return }
public final func dontThrow<T>(_ message: @autoclosure () -> String = "Unexpectedly threw", file: String = #file, line: Int = #line, closure: () throws -> T) -> T? {
do {
return try closure()
}
catch {
self.fail(message() + "\(error)", file: file, line: line)
return nil
}
}
}
private func cdump(_ t: Any) -> String {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment