Skip to content

Commit 6286750

Browse files
committed
Overloaded XCTAssertThrowsError function to alllow to rethrow when the error handler throws
1 parent dd599d0 commit 6286750

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

Sources/XCTest/Public/XCTAssert.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,6 +377,12 @@ public func XCTFail(_ message: String = "", file: StaticString = #file, line: UI
377377
}
378378

379379
public func XCTAssertThrowsError<T>(_ expression: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line, _ errorHandler: (_ error: Swift.Error) -> Void = { _ in }) {
380+
let rethrowsOverload: (() throws -> T, () -> String, StaticString, UInt, (Swift.Error) throws -> Void) throws -> Void = XCTAssertThrowsError
381+
382+
try? rethrowsOverload(expression, message, file, line, errorHandler)
383+
}
384+
385+
public func XCTAssertThrowsError<T>(_ expression: @autoclosure () throws -> T, _ message: @autoclosure () -> String = "", file: StaticString = #file, line: UInt = #line, _ errorHandler: (_ error: Swift.Error) throws -> Void = { _ in }) rethrows {
380386
_XCTEvaluateAssertion(.throwsError, message: message(), file: file, line: line) {
381387
var caughtErrorOptional: Swift.Error?
382388
do {
@@ -386,7 +392,7 @@ public func XCTAssertThrowsError<T>(_ expression: @autoclosure () throws -> T, _
386392
}
387393

388394
if let caughtError = caughtErrorOptional {
389-
errorHandler(caughtError)
395+
try errorHandler(caughtError)
390396
return .success
391397
} else {
392398
return .expectedFailure("did not throw error")

0 commit comments

Comments
 (0)