@@ -12,22 +12,19 @@ import Foundation
1212/// nil arguments indicates that the matcher should not attempt to match against
1313/// that parameter.
1414public func throwError( ) -> Predicate < Any > {
15- return Predicate . fromDeprecatedClosure { actualExpression, failureMessage in
16-
15+ return Predicate { actualExpression in
1716 var actualError : Error ?
1817 do {
1918 _ = try actualExpression. evaluate ( )
20- } catch let catchedError {
21- actualError = catchedError
19+ } catch {
20+ actualError = error
2221 }
2322
24- failureMessage. postfixMessage = " throw any error "
2523 if let actualError = actualError {
26- failureMessage . actualValue = " < \( actualError) > "
24+ return PredicateResult ( bool : true , message : . expectedCustomValueTo ( " throw any error " , " < \( actualError) > " ) )
2725 } else {
28- failureMessage . actualValue = " no error "
26+ return PredicateResult ( bool : false , message : . expectedCustomValueTo ( " throw any error " , " no error " ) )
2927 }
30- return actualError != nil
3128 }
3229}
3330
@@ -43,36 +40,39 @@ public func throwError() -> Predicate<Any> {
4340/// nil arguments indicates that the matcher should not attempt to match against
4441/// that parameter.
4542public func throwError< T: Error > ( _ error: T , closure: ( ( Error ) -> Void ) ? = nil ) -> Predicate < Any > {
46- return Predicate . fromDeprecatedClosure { actualExpression, failureMessage in
47-
43+ return Predicate { actualExpression in
4844 var actualError : Error ?
4945 do {
5046 _ = try actualExpression. evaluate ( )
51- } catch let catchedError {
52- actualError = catchedError
47+ } catch {
48+ actualError = error
5349 }
5450
51+ let failureMessage = FailureMessage ( )
5552 setFailureMessageForError (
5653 failureMessage,
5754 actualError: actualError,
5855 error: error,
5956 errorType: nil ,
6057 closure: closure
6158 )
59+
6260 var matches = false
6361 if let actualError = actualError, errorMatchesExpectedError ( actualError, expectedError: error) {
6462 matches = true
63+
6564 if let closure = closure {
6665 let assertions = gatherFailingExpectations {
6766 closure ( actualError)
6867 }
6968 let messages = assertions. map { $0. message }
70- if messages. count > 0 {
69+ if ! messages. isEmpty {
7170 matches = false
7271 }
7372 }
7473 }
75- return matches
74+
75+ return PredicateResult ( bool: matches, message: failureMessage. toExpectationMessage ( ) )
7676 }
7777}
7878
@@ -88,22 +88,23 @@ public func throwError<T: Error>(_ error: T, closure: ((Error) -> Void)? = nil)
8888/// nil arguments indicates that the matcher should not attempt to match against
8989/// that parameter.
9090public func throwError< T: Error & Equatable > ( _ error: T , closure: ( ( T ) -> Void ) ? = nil ) -> Predicate < Any > {
91- return Predicate . fromDeprecatedClosure { actualExpression, failureMessage in
92-
91+ return Predicate { actualExpression in
9392 var actualError : Error ?
9493 do {
9594 _ = try actualExpression. evaluate ( )
96- } catch let catchedError {
97- actualError = catchedError
95+ } catch {
96+ actualError = error
9897 }
9998
99+ let failureMessage = FailureMessage ( )
100100 setFailureMessageForError (
101101 failureMessage,
102102 actualError: actualError,
103103 error: error,
104104 errorType: nil ,
105105 closure: closure
106106 )
107+
107108 var matches = false
108109 if let actualError = actualError as? T , error == actualError {
109110 matches = true
@@ -113,12 +114,13 @@ public func throwError<T: Error & Equatable>(_ error: T, closure: ((T) -> Void)?
113114 closure ( actualError)
114115 }
115116 let messages = assertions. map { $0. message }
116- if messages. count > 0 {
117+ if ! messages. isEmpty {
117118 matches = false
118119 }
119120 }
120121 }
121- return matches
122+
123+ return PredicateResult ( bool: matches, message: failureMessage. toExpectationMessage ( ) )
122124 }
123125}
124126
@@ -136,32 +138,34 @@ public func throwError<T: Error & Equatable>(_ error: T, closure: ((T) -> Void)?
136138public func throwError< T: Error > (
137139 errorType: T . Type ,
138140 closure: ( ( T ) -> Void ) ? = nil ) -> Predicate < Any > {
139- return Predicate . fromDeprecatedClosure { actualExpression, failureMessage in
140-
141+ return Predicate { actualExpression in
141142 var actualError : Error ?
142143 do {
143144 _ = try actualExpression. evaluate ( )
144- } catch let catchedError {
145- actualError = catchedError
145+ } catch {
146+ actualError = error
146147 }
147148
149+ let failureMessage = FailureMessage ( )
148150 setFailureMessageForError (
149151 failureMessage,
150152 actualError: actualError,
151153 error: nil ,
152154 errorType: errorType,
153155 closure: closure
154156 )
157+
155158 var matches = false
156159 if let actualError = actualError {
157160 matches = true
161+
158162 if let actualError = actualError as? T {
159163 if let closure = closure {
160164 let assertions = gatherFailingExpectations {
161165 closure ( actualError)
162166 }
163167 let messages = assertions. map { $0. message }
164- if messages. count > 0 {
168+ if ! messages. isEmpty {
165169 matches = false
166170 }
167171 }
@@ -176,14 +180,14 @@ public func throwError<T: Error>(
176180 }
177181 }
178182 let messages = assertions. map { $0. message }
179- if messages. count > 0 {
183+ if ! messages. isEmpty {
180184 matches = false
181185 }
182186 }
183187 }
184188 }
185189
186- return matches
190+ return PredicateResult ( bool : matches, message : failureMessage . toExpectationMessage ( ) )
187191 }
188192}
189193
@@ -195,15 +199,15 @@ public func throwError<T: Error>(
195199///
196200/// The closure only gets called when an error was thrown.
197201public func throwError( closure: @escaping ( ( Error ) -> Void ) ) -> Predicate < Any > {
198- return Predicate . fromDeprecatedClosure { actualExpression, failureMessage in
199-
202+ return Predicate { actualExpression in
200203 var actualError : Error ?
201204 do {
202205 _ = try actualExpression. evaluate ( )
203- } catch let catchedError {
204- actualError = catchedError
206+ } catch {
207+ actualError = error
205208 }
206209
210+ let failureMessage = FailureMessage ( )
207211 setFailureMessageForError ( failureMessage, actualError: actualError, closure: closure)
208212
209213 var matches = false
@@ -214,11 +218,12 @@ public func throwError(closure: @escaping ((Error) -> Void)) -> Predicate<Any> {
214218 closure ( actualError)
215219 }
216220 let messages = assertions. map { $0. message }
217- if messages. count > 0 {
221+ if ! messages. isEmpty {
218222 matches = false
219223 }
220224 }
221- return matches
225+
226+ return PredicateResult ( bool: matches, message: failureMessage. toExpectationMessage ( ) )
222227 }
223228}
224229
@@ -230,15 +235,15 @@ public func throwError(closure: @escaping ((Error) -> Void)) -> Predicate<Any> {
230235///
231236/// The closure only gets called when an error was thrown.
232237public func throwError< T: Error > ( closure: @escaping ( ( T ) -> Void ) ) -> Predicate < Any > {
233- return Predicate . fromDeprecatedClosure { actualExpression, failureMessage in
234-
238+ return Predicate { actualExpression in
235239 var actualError : Error ?
236240 do {
237241 _ = try actualExpression. evaluate ( )
238- } catch let catchedError {
239- actualError = catchedError
242+ } catch {
243+ actualError = error
240244 }
241245
246+ let failureMessage = FailureMessage ( )
242247 setFailureMessageForError ( failureMessage, actualError: actualError, closure: closure)
243248
244249 var matches = false
@@ -249,10 +254,11 @@ public func throwError<T: Error>(closure: @escaping ((T) -> Void)) -> Predicate<
249254 closure ( actualError)
250255 }
251256 let messages = assertions. map { $0. message }
252- if messages. count > 0 {
257+ if ! messages. isEmpty {
253258 matches = false
254259 }
255260 }
256- return matches
261+
262+ return PredicateResult ( bool: matches, message: failureMessage. toExpectationMessage ( ) )
257263 }
258264}
0 commit comments