@@ -3,8 +3,8 @@ import Foundation
33#if os(macOS) || os(iOS) || os(tvOS) || os(watchOS)
44
55// swiftlint:disable line_length
6- public typealias MatcherBlock = ( _ actualExpression: Expression < NSObject > , _ failureMessage: FailureMessage ) -> Bool
7- public typealias FullMatcherBlock = ( _ actualExpression: Expression < NSObject > , _ failureMessage: FailureMessage , _ shouldNotMatch: Bool ) -> Bool
6+ public typealias MatcherBlock = ( _ actualExpression: Expression < NSObject > , _ failureMessage: FailureMessage ) throws -> Bool
7+ public typealias FullMatcherBlock = ( _ actualExpression: Expression < NSObject > , _ failureMessage: FailureMessage , _ shouldNotMatch: Bool ) throws -> Bool
88// swiftlint:enable line_length
99
1010public class NMBObjCMatcher : NSObject , NMBMatcher {
@@ -26,7 +26,7 @@ public class NMBObjCMatcher: NSObject, NMBMatcher {
2626
2727 public convenience init ( canMatchNil: Bool , matcher: @escaping MatcherBlock ) {
2828 self . init ( canMatchNil: canMatchNil, matcher: matcher, notMatcher: ( { actualExpression, failureMessage in
29- return !matcher( actualExpression, failureMessage)
29+ return try ! matcher( actualExpression, failureMessage)
3030 } ) )
3131 }
3232
@@ -36,9 +36,9 @@ public class NMBObjCMatcher: NSObject, NMBMatcher {
3636
3737 public convenience init ( canMatchNil: Bool , matcher: @escaping FullMatcherBlock ) {
3838 self . init ( canMatchNil: canMatchNil, matcher: ( { actualExpression, failureMessage in
39- return matcher ( actualExpression, failureMessage, false )
39+ return try matcher ( actualExpression, failureMessage, false )
4040 } ) , notMatcher: ( { actualExpression, failureMessage in
41- return matcher ( actualExpression, failureMessage, true )
41+ return try matcher ( actualExpression, failureMessage, true )
4242 } ) )
4343 }
4444
@@ -59,9 +59,14 @@ public class NMBObjCMatcher: NSObject, NMBMatcher {
5959
6060 public func matches( _ actualBlock: @escaping ( ) -> NSObject ? , failureMessage: FailureMessage , location: SourceLocation ) -> Bool {
6161 let expr = Expression ( expression: actualBlock, location: location)
62- let result = _match (
63- expr,
64- failureMessage)
62+ let result : Bool
63+ do {
64+ result = try _match ( expr, failureMessage)
65+ } catch let error {
66+ failureMessage. stringValue = " unexpected error thrown: < \( error) > "
67+ return false
68+ }
69+
6570 if self . canMatch ( Expression ( expression: actualBlock, location: location) , failureMessage: failureMessage) {
6671 return result
6772 } else {
@@ -71,9 +76,14 @@ public class NMBObjCMatcher: NSObject, NMBMatcher {
7176
7277 public func doesNotMatch( _ actualBlock: @escaping ( ) -> NSObject ? , failureMessage: FailureMessage , location: SourceLocation ) -> Bool {
7378 let expr = Expression ( expression: actualBlock, location: location)
74- let result = _doesNotMatch (
75- expr,
76- failureMessage)
79+ let result : Bool
80+ do {
81+ result = try _doesNotMatch ( expr, failureMessage)
82+ } catch let error {
83+ failureMessage. stringValue = " unexpected error thrown: < \( error) > "
84+ return false
85+ }
86+
7787 if self . canMatch ( Expression ( expression: actualBlock, location: location) , failureMessage: failureMessage) {
7888 return result
7989 } else {
0 commit comments