@@ -142,6 +142,9 @@ public macro require<T>(
142
142
/// issues should be attributed.
143
143
/// - expression: The expression to be evaluated.
144
144
///
145
+ /// - Returns: If the expectation passes, the instance of `errorType` that was
146
+ /// thrown by `expression`. If the expectation fails, the result is `nil`.
147
+ ///
145
148
/// Use this overload of `#expect()` when the expression `expression` _should_
146
149
/// throw an error of a given type:
147
150
///
@@ -158,7 +161,7 @@ public macro require<T>(
158
161
/// discarded.
159
162
///
160
163
/// If the thrown error need only equal another instance of [`Error`](https://developer.apple.com/documentation/swift/error),
161
- /// use ``expect(throws:_:sourceLocation:performing:)-1xr34 `` instead.
164
+ /// use ``expect(throws:_:sourceLocation:performing:)-7du1h `` instead.
162
165
///
163
166
/// ## Expressions that should never throw
164
167
///
@@ -181,12 +184,13 @@ public macro require<T>(
181
184
/// fail when an error is thrown by `expression`, rather than to explicitly
182
185
/// check that an error is _not_ thrown by it, do not use this macro. Instead,
183
186
/// simply call the code in question and allow it to throw an error naturally.
187
+ @discardableResult
184
188
@freestanding ( expression) public macro expect< E, R> (
185
189
throws errorType: E . Type ,
186
190
_ comment: @autoclosure ( ) -> Comment ? = nil ,
187
191
sourceLocation: SourceLocation = #_sourceLocation,
188
192
performing expression: ( ) async throws -> R
189
- ) = #externalMacro( module: " TestingMacros " , type: " ExpectMacro " ) where E: Error
193
+ ) -> E ? = #externalMacro( module: " TestingMacros " , type: " ExpectMacro " ) where E: Error
190
194
191
195
/// Check that an expression always throws an error of a given type, and throw
192
196
/// an error if it does not.
@@ -200,6 +204,8 @@ public macro require<T>(
200
204
/// issues should be attributed.
201
205
/// - expression: The expression to be evaluated.
202
206
///
207
+ /// - Returns: The instance of `errorType` that was thrown by `expression`.
208
+ ///
203
209
/// - Throws: An instance of ``ExpectationFailedError`` if `expression` does not
204
210
/// throw a matching error. The error thrown by `expression` is not rethrown.
205
211
///
@@ -219,16 +225,17 @@ public macro require<T>(
219
225
/// is thrown. Any value returned by `expression` is discarded.
220
226
///
221
227
/// If the thrown error need only equal another instance of [`Error`](https://developer.apple.com/documentation/swift/error),
222
- /// use ``require(throws:_:sourceLocation:performing:)-7v83e `` instead.
228
+ /// use ``require(throws:_:sourceLocation:performing:)-4djuw `` instead.
223
229
///
224
230
/// If `expression` should _never_ throw, simply invoke the code without using
225
231
/// this macro. The test will then fail if an error is thrown.
232
+ @discardableResult
226
233
@freestanding ( expression) public macro require< E, R> (
227
234
throws errorType: E . Type ,
228
235
_ comment: @autoclosure ( ) -> Comment ? = nil ,
229
236
sourceLocation: SourceLocation = #_sourceLocation,
230
237
performing expression: ( ) async throws -> R
231
- ) = #externalMacro( module: " TestingMacros " , type: " RequireMacro " ) where E: Error
238
+ ) -> E = #externalMacro( module: " TestingMacros " , type: " RequireMacro " ) where E: Error
232
239
233
240
/// Check that an expression never throws an error, and throw an error if it
234
241
/// does.
@@ -261,6 +268,10 @@ public macro require<R>(
261
268
/// issues should be attributed.
262
269
/// - expression: The expression to be evaluated.
263
270
///
271
+ /// - Returns: If the expectation passes, the instance of `E` that was thrown by
272
+ /// `expression` and is equal to `error`. If the expectation fails, the result
273
+ /// is `nil`.
274
+ ///
264
275
/// Use this overload of `#expect()` when the expression `expression` _should_
265
276
/// throw a specific error:
266
277
///
@@ -276,13 +287,14 @@ public macro require<R>(
276
287
/// in the current task. Any value returned by `expression` is discarded.
277
288
///
278
289
/// If the thrown error need only be an instance of a particular type, use
279
- /// ``expect(throws:_:sourceLocation:performing:)-79piu`` instead.
290
+ /// ``expect(throws:_:sourceLocation:performing:)-1hfms`` instead.
291
+ @discardableResult
280
292
@freestanding ( expression) public macro expect< E, R> (
281
293
throws error: E ,
282
294
_ comment: @autoclosure ( ) -> Comment ? = nil ,
283
295
sourceLocation: SourceLocation = #_sourceLocation,
284
296
performing expression: ( ) async throws -> R
285
- ) = #externalMacro( module: " TestingMacros " , type: " ExpectMacro " ) where E: Error & Equatable
297
+ ) -> E ? = #externalMacro( module: " TestingMacros " , type: " ExpectMacro " ) where E: Error & Equatable
286
298
287
299
/// Check that an expression always throws a specific error, and throw an error
288
300
/// if it does not.
@@ -293,6 +305,9 @@ public macro require<R>(
293
305
/// - sourceLocation: The source location to which recorded expectations and
294
306
/// issues should be attributed.
295
307
/// - expression: The expression to be evaluated.
308
+
309
+ /// - Returns: The instance of `E` that was thrown by `expression` and is equal
310
+ /// to `error`.
296
311
///
297
312
/// - Throws: An instance of ``ExpectationFailedError`` if `expression` does not
298
313
/// throw a matching error. The error thrown by `expression` is not rethrown.
@@ -313,13 +328,14 @@ public macro require<R>(
313
328
/// Any value returned by `expression` is discarded.
314
329
///
315
330
/// If the thrown error need only be an instance of a particular type, use
316
- /// ``require(throws:_:sourceLocation:performing:)-76bjn`` instead.
331
+ /// ``require(throws:_:sourceLocation:performing:)-7n34r`` instead.
332
+ @discardableResult
317
333
@freestanding ( expression) public macro require< E, R> (
318
334
throws error: E ,
319
335
_ comment: @autoclosure ( ) -> Comment ? = nil ,
320
336
sourceLocation: SourceLocation = #_sourceLocation,
321
337
performing expression: ( ) async throws -> R
322
- ) = #externalMacro( module: " TestingMacros " , type: " RequireMacro " ) where E: Error & Equatable
338
+ ) -> E = #externalMacro( module: " TestingMacros " , type: " RequireMacro " ) where E: Error & Equatable
323
339
324
340
// MARK: - Arbitrary error matching
325
341
@@ -333,6 +349,9 @@ public macro require<R>(
333
349
/// - errorMatcher: A closure to invoke when `expression` throws an error that
334
350
/// indicates if it matched or not.
335
351
///
352
+ /// - Returns: If the expectation passes, the error that was thrown by
353
+ /// `expression`. If the expectation fails, the result is `nil`.
354
+ ///
336
355
/// Use this overload of `#expect()` when the expression `expression` _should_
337
356
/// throw an error, but the logic to determine if the error matches is complex:
338
357
///
@@ -353,15 +372,16 @@ public macro require<R>(
353
372
/// discarded.
354
373
///
355
374
/// If the thrown error need only be an instance of a particular type, use
356
- /// ``expect(throws:_:sourceLocation:performing:)-79piu `` instead. If the thrown
375
+ /// ``expect(throws:_:sourceLocation:performing:)-1hfms `` instead. If the thrown
357
376
/// error need only equal another instance of [`Error`](https://developer.apple.com/documentation/swift/error),
358
- /// use ``expect(throws:_:sourceLocation:performing:)-1xr34`` instead.
377
+ /// use ``expect(throws:_:sourceLocation:performing:)-7du1h`` instead.
378
+ @discardableResult
359
379
@freestanding ( expression) public macro expect< R> (
360
380
_ comment: @autoclosure ( ) -> Comment ? = nil ,
361
381
sourceLocation: SourceLocation = #_sourceLocation,
362
382
performing expression: ( ) async throws -> R ,
363
383
throws errorMatcher: ( any Error ) async throws -> Bool
364
- ) = #externalMacro( module: " TestingMacros " , type: " ExpectMacro " )
384
+ ) -> ( any Error ) ? = #externalMacro( module: " TestingMacros " , type: " ExpectMacro " )
365
385
366
386
/// Check that an expression always throws an error matching some condition, and
367
387
/// throw an error if it does not.
@@ -374,6 +394,8 @@ public macro require<R>(
374
394
/// - errorMatcher: A closure to invoke when `expression` throws an error that
375
395
/// indicates if it matched or not.
376
396
///
397
+ /// - Returns: The error that was thrown by `expression`.
398
+ ///
377
399
/// - Throws: An instance of ``ExpectationFailedError`` if `expression` does not
378
400
/// throw a matching error. The error thrown by `expression` is not rethrown.
379
401
///
@@ -398,18 +420,19 @@ public macro require<R>(
398
420
/// discarded.
399
421
///
400
422
/// If the thrown error need only be an instance of a particular type, use
401
- /// ``require(throws:_:sourceLocation:performing:)-76bjn `` instead. If the thrown error need
423
+ /// ``require(throws:_:sourceLocation:performing:)-7n34r `` instead. If the thrown error need
402
424
/// only equal another instance of [`Error`](https://developer.apple.com/documentation/swift/error),
403
- /// use ``require(throws:_:sourceLocation:performing:)-7v83e `` instead.
425
+ /// use ``require(throws:_:sourceLocation:performing:)-4djuw `` instead.
404
426
///
405
427
/// If `expression` should _never_ throw, simply invoke the code without using
406
428
/// this macro. The test will then fail if an error is thrown.
429
+ @discardableResult
407
430
@freestanding ( expression) public macro require< R> (
408
431
_ comment: @autoclosure ( ) -> Comment ? = nil ,
409
432
sourceLocation: SourceLocation = #_sourceLocation,
410
433
performing expression: ( ) async throws -> R ,
411
434
throws errorMatcher: ( any Error ) async throws -> Bool
412
- ) = #externalMacro( module: " TestingMacros " , type: " RequireMacro " )
435
+ ) -> any Error = #externalMacro( module: " TestingMacros " , type: " RequireMacro " )
413
436
414
437
// MARK: - Exit tests
415
438
@@ -425,7 +448,7 @@ public macro require<R>(
425
448
/// issues should be attributed.
426
449
/// - expression: The expression to be evaluated.
427
450
///
428
- /// - Returns: If the exit test passed , an instance of ``ExitTestArtifacts``
451
+ /// - Returns: If the exit test passes , an instance of ``ExitTestArtifacts``
429
452
/// describing the state of the exit test when it exited. If the exit test
430
453
/// fails, the result is `nil`.
431
454
///
0 commit comments