Commit 02cc12d3 authored by Drew's avatar Drew

Merge branch 'dontThrow' into 'master'

Dont throw



See merge request !3
parents 37f46822 ff3401a4
Pipeline #2399 passed with stages
in 2 minutes and 53 seconds
......@@ -132,6 +132,33 @@ extension CarolineTest {
}
#endif
#if swift(>=3.0)
///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
}
}
#else
///- noindex: true
public final func dontThrow<T>(@autoclosure _ message: () -> 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
}
}
#endif
}
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