@@ -1030,6 +1030,39 @@ public func XCTAssertThrowsError<T>(_ expression: @autoclosure () throws -> T, _
1030
1030
}
1031
1031
}
1032
1032
1033
+ public func XCTAssertNoThrow< T> ( _ expression: @autoclosure ( ) throws -> T , _ message: @autoclosure ( ) -> String = " " , file: StaticString = #file, line: UInt = #line, _ errorHandler: ( _ error: Error ) -> Void = { _ in } ) {
1034
+ let assertionType = _XCTAssertionType. assertion_NoThrow
1035
+
1036
+ // evaluate expression exactly once
1037
+ var caughtErrorOptional : Error ?
1038
+
1039
+ let result = _XCTRunThrowableBlock {
1040
+ do {
1041
+ _ = try expression
1042
+ } catch {
1043
+ caughtErrorOptional = error
1044
+ }
1045
+ }
1046
+
1047
+ switch result {
1048
+ case . success:
1049
+ guard let caughtError = caughtErrorOptional else {
1050
+ return
1051
+ }
1052
+
1053
+ _XCTRegisterFailure ( true , " XCTAssertNoThrow failed: threw error \" \( error) \" " , message, file, line)
1054
+
1055
+ case . failedWithError( let error) :
1056
+ _XCTRegisterFailure ( false , " XCTAssertNoThrow failed: threw error \" \( error) \" " , message, file, line)
1057
+
1058
+ case . failedWithException( _, _, let reason) :
1059
+ _XCTRegisterFailure ( true , " XCTAssertNoThrow failed: throwing \( reason) " , message, file, line)
1060
+
1061
+ case . failedWithUnknownException:
1062
+ _XCTRegisterFailure ( true , " XCTAssertNoThrow failed: throwing an unknown exception " , message, file, line)
1063
+ }
1064
+ }
1065
+
1033
1066
#if XCTEST_ENABLE_EXCEPTION_ASSERTIONS
1034
1067
// --- Currently-Unsupported Assertions ---
1035
1068
@@ -1051,12 +1084,6 @@ public func XCTAssertThrowsSpecificNamed(_ expression: @autoclosure () -> Any?,
1051
1084
// FIXME: Unsupported
1052
1085
}
1053
1086
1054
- public func XCTAssertNoThrow( _ expression: @autoclosure ( ) -> Any ? , _ message: @autoclosure ( ) -> String = " " , file: StaticString = #file, line: UInt = #line) {
1055
- let assertionType = _XCTAssertionType. assertion_NoThrow
1056
-
1057
- // FIXME: Unsupported
1058
- }
1059
-
1060
1087
public func XCTAssertNoThrowSpecific( _ expression: @autoclosure ( ) -> Any ? , _ exception: Any , _ message: @autoclosure ( ) -> String = " " , file: StaticString = #file, line: UInt = #line) {
1061
1088
let assertionType = _XCTAssertionType. assertion_NoThrowSpecific
1062
1089
0 commit comments