|
15 | 15 | /// - Parameters: |
16 | 16 | /// - condition: The condition to be evaluated. |
17 | 17 | /// - comment: A comment describing the expectation. |
| 18 | +/// - sourceLocation: The source location to which recorded expectations and |
| 19 | +/// issues should be attributed. |
18 | 20 | /// |
19 | 21 | /// If `condition` evaluates to `false`, an ``Issue`` is recorded for the test |
20 | 22 | /// that is running in the current task. |
21 | 23 | @freestanding(expression) public macro expect( |
22 | 24 | _ condition: Bool, |
23 | | - _ comment: @autoclosure () -> Comment? = nil |
| 25 | + _ comment: @autoclosure () -> Comment? = nil, |
| 26 | + sourceLocation: SourceLocation = SourceLocation() |
24 | 27 | ) = #externalMacro(module: "TestingMacros", type: "ExpectMacro") |
25 | 28 |
|
26 | 29 | /// Check that an expectation has passed after a condition has been evaluated |
|
29 | 32 | /// - Parameters: |
30 | 33 | /// - condition: The condition to be evaluated. |
31 | 34 | /// - comment: A comment describing the expectation. |
| 35 | +/// - sourceLocation: The source location to which recorded expectations and |
| 36 | +/// issues should be attributed. |
32 | 37 | /// |
33 | 38 | /// - Throws: An instance of ``ExpectationFailedError`` if `condition` evaluates |
34 | 39 | /// to `false`. |
|
38 | 43 | /// ``ExpectationFailedError`` is thrown. |
39 | 44 | @freestanding(expression) public macro require( |
40 | 45 | _ condition: Bool, |
41 | | - _ comment: @autoclosure () -> Comment? = nil |
| 46 | + _ comment: @autoclosure () -> Comment? = nil, |
| 47 | + sourceLocation: SourceLocation = SourceLocation() |
42 | 48 | ) = #externalMacro(module: "TestingMacros", type: "RequireMacro") |
43 | 49 |
|
44 | 50 | // MARK: - Optional checking |
|
48 | 54 | /// - Parameters: |
49 | 55 | /// - optionalValue: The optional value to be unwrapped. |
50 | 56 | /// - comment: A comment describing the expectation. |
| 57 | +/// - sourceLocation: The source location to which recorded expectations and |
| 58 | +/// issues should be attributed. |
51 | 59 | /// |
52 | 60 | /// - Returns: The unwrapped value of `value`. |
53 | 61 | /// |
|
57 | 65 | /// in the current task and an instance of ``ExpectationFailedError`` is thrown. |
58 | 66 | @freestanding(expression) public macro require<T>( |
59 | 67 | _ optionalValue: T?, |
60 | | - _ comment: @autoclosure () -> Comment? = nil |
| 68 | + _ comment: @autoclosure () -> Comment? = nil, |
| 69 | + sourceLocation: SourceLocation = SourceLocation() |
61 | 70 | ) -> T = #externalMacro(module: "TestingMacros", type: "RequireMacro") |
62 | 71 |
|
63 | 72 | // MARK: - Matching errors by type |
|
69 | 78 | /// `expression` could throw _any_ error, or the specific type of thrown |
70 | 79 | /// error is unimportant, pass `any Error.self`. |
71 | 80 | /// - comment: A comment describing the expectation. |
| 81 | +/// - sourceLocation: The source location to which recorded expectations and |
| 82 | +/// issues should be attributed. |
72 | 83 | /// - expression: The expression to be evaluated. |
73 | 84 | /// |
74 | 85 | /// Use this overload of `#expect()` when the expression `expression` _should_ |
|
87 | 98 | /// discarded. |
88 | 99 | /// |
89 | 100 | /// If the thrown error need only equal another instance of [`Error`](https://developer.apple.com/documentation/swift/error), |
90 | | -/// use ``expect(throws:_:performing:)-1s3lx`` instead. If `expression` should |
91 | | -/// _never_ throw any error, use ``expect(throws:_:performing:)-jtjw`` instead. |
| 101 | +/// use ``expect(throws:_:sourceLocation:performing:)-1xr34`` instead. If |
| 102 | +/// `expression` should _never_ throw any error, use |
| 103 | +/// ``expect(throws:_:sourceLocation:performing:)-5lzjz`` instead. |
92 | 104 | @freestanding(expression) public macro expect<E, R>( |
93 | 105 | throws errorType: E.Type, |
94 | 106 | _ comment: @autoclosure () -> Comment? = nil, |
| 107 | + sourceLocation: SourceLocation = SourceLocation(), |
95 | 108 | performing expression: () async throws -> R |
96 | 109 | ) = #externalMacro(module: "TestingMacros", type: "ExpectMacro") where E: Error |
97 | 110 |
|
98 | 111 | /// Check that an expression never throws an error. |
99 | 112 | /// |
100 | 113 | /// - Parameters: |
101 | 114 | /// - comment: A comment describing the expectation. |
| 115 | +/// - sourceLocation: The source location to which recorded expectations and |
| 116 | +/// issues should be attributed. |
102 | 117 | /// - expression: The expression to be evaluated. |
103 | 118 | /// |
104 | 119 | /// Use this overload of `#expect()` when the expression `expression` should |
|
123 | 138 | /// naturally. |
124 | 139 | /// |
125 | 140 | /// If the thrown error need only be an instance of a particular type, use |
126 | | -/// ``expect(throws:_:performing:)-2j0od`` instead. If the thrown error need |
127 | | -/// only equal another instance of [`Error`](https://developer.apple.com/documentation/swift/error), |
128 | | -/// use ``expect(throws:_:performing:)-1s3lx`` instead. |
| 141 | +/// ``expect(throws:_:sourceLocation:performing:)-79piu`` instead. If the thrown |
| 142 | +/// error need only equal another instance of [`Error`](https://developer.apple.com/documentation/swift/error), |
| 143 | +/// use ``expect(throws:_:sourceLocation:performing:)-1xr34`` instead. |
129 | 144 | @freestanding(expression) public macro expect<R>( |
130 | 145 | throws _: Never.Type, |
131 | 146 | _ comment: @autoclosure () -> Comment? = nil, |
| 147 | + sourceLocation: SourceLocation = SourceLocation(), |
132 | 148 | performing expression: () async throws -> R |
133 | 149 | ) = #externalMacro(module: "TestingMacros", type: "ExpectMacro") |
134 | 150 |
|
|
140 | 156 | /// `expression` could throw _any_ error, or the specific type of thrown |
141 | 157 | /// error is unimportant, pass `any Error.self`. |
142 | 158 | /// - comment: A comment describing the expectation. |
| 159 | +/// - sourceLocation: The source location to which recorded expectations and |
| 160 | +/// issues should be attributed. |
143 | 161 | /// - expression: The expression to be evaluated. |
144 | 162 | /// |
145 | 163 | /// - Throws: An instance of ``ExpectationFailedError`` if `expression` does not |
|
161 | 179 | /// is thrown. Any value returned by `expression` is discarded. |
162 | 180 | /// |
163 | 181 | /// If the thrown error need only equal another instance of [`Error`](https://developer.apple.com/documentation/swift/error), |
164 | | -/// use ``require(throws:_:performing:)-84jir`` instead. |
| 182 | +/// use ``require(throws:_:sourceLocation:performing:)-7v83e`` instead. |
165 | 183 | /// |
166 | 184 | /// If `expression` should _never_ throw, simply invoke the code without using |
167 | 185 | /// this macro. The test will then fail if an error is thrown. |
168 | 186 | @freestanding(expression) public macro require<E, R>( |
169 | 187 | throws errorType: E.Type, |
170 | 188 | _ comment: @autoclosure () -> Comment? = nil, |
| 189 | + sourceLocation: SourceLocation = SourceLocation(), |
171 | 190 | performing expression: () async throws -> R |
172 | 191 | ) = #externalMacro(module: "TestingMacros", type: "RequireMacro") where E: Error |
173 | 192 |
|
|
176 | 195 | /// |
177 | 196 | /// - Parameters: |
178 | 197 | /// - comment: A comment describing the expectation. |
| 198 | +/// - sourceLocation: The source location to which recorded expectations and |
| 199 | +/// issues should be attributed. |
179 | 200 | /// - expression: The expression to be evaluated. |
180 | 201 | /// |
181 | 202 | /// - Throws: An instance of ``ExpectationFailedError`` if `expression` throws |
|
184 | 205 | @freestanding(expression) public macro require<R>( |
185 | 206 | throws _: Never.Type, |
186 | 207 | _ comment: @autoclosure () -> Comment? = nil, |
| 208 | + sourceLocation: SourceLocation = SourceLocation(), |
187 | 209 | performing expression: () async throws -> R |
188 | 210 | ) = #externalMacro(module: "TestingMacros", type: "RequireMacro") |
189 | 211 |
|
|
194 | 216 | /// - Parameters: |
195 | 217 | /// - error: The error that is expected to be thrown. |
196 | 218 | /// - comment: A comment describing the expectation. |
| 219 | +/// - sourceLocation: The source location to which recorded expectations and |
| 220 | +/// issues should be attributed. |
197 | 221 | /// - expression: The expression to be evaluated. |
198 | 222 | /// |
199 | 223 | /// Use this overload of `#expect()` when the expression `expression` _should_ |
|
211 | 235 | /// in the current task. Any value returned by `expression` is discarded. |
212 | 236 | /// |
213 | 237 | /// If the thrown error need only be an instance of a particular type, use |
214 | | -/// ``expect(throws:_:performing:)-2j0od`` instead. If `expression` should |
215 | | -/// _never_ throw any error, use ``expect(throws:_:performing:)-jtjw`` instead. |
| 238 | +/// ``expect(throws:_:sourceLocation:performing:)-79piu`` instead. If |
| 239 | +/// `expression` should _never_ throw any error, use |
| 240 | +/// ``expect(throws:_:sourceLocation:performing:)-5lzjz`` instead. |
216 | 241 | @freestanding(expression) public macro expect<E, R>( |
217 | 242 | throws error: E, |
218 | 243 | _ comment: @autoclosure () -> Comment? = nil, |
| 244 | + sourceLocation: SourceLocation = SourceLocation(), |
219 | 245 | performing expression: () async throws -> R |
220 | 246 | ) = #externalMacro(module: "TestingMacros", type: "ExpectMacro") where E: Error & Equatable |
221 | 247 |
|
|
225 | 251 | /// - Parameters: |
226 | 252 | /// - error: The error that is expected to be thrown. |
227 | 253 | /// - comment: A comment describing the expectation. |
| 254 | +/// - sourceLocation: The source location to which recorded expectations and |
| 255 | +/// issues should be attributed. |
228 | 256 | /// - expression: The expression to be evaluated. |
229 | 257 | /// |
230 | 258 | /// - Throws: An instance of ``ExpectationFailedError`` if `expression` does not |
|
246 | 274 | /// Any value returned by `expression` is discarded. |
247 | 275 | /// |
248 | 276 | /// If the thrown error need only be an instance of a particular type, use |
249 | | -/// ``require(throws:_:performing:)-8762f`` instead. |
| 277 | +/// ``require(throws:_:sourceLocation:performing:)-76bjn`` instead. |
250 | 278 | @freestanding(expression) public macro require<E, R>( |
251 | 279 | throws error: E, |
252 | 280 | _ comment: @autoclosure () -> Comment? = nil, |
| 281 | + sourceLocation: SourceLocation = SourceLocation(), |
253 | 282 | performing expression: () async throws -> R |
254 | 283 | ) = #externalMacro(module: "TestingMacros", type: "RequireMacro") where E: Error & Equatable |
255 | 284 |
|
|
259 | 288 | /// |
260 | 289 | /// - Parameters: |
261 | 290 | /// - comment: A comment describing the expectation. |
| 291 | +/// - sourceLocation: The source location to which recorded expectations and |
| 292 | +/// issues should be attributed. |
262 | 293 | /// - expression: The expression to be evaluated. |
263 | 294 | /// - errorMatcher: A closure to invoke when `expression` throws an error that |
264 | 295 | /// indicates if it matched or not. |
|
283 | 314 | /// discarded. |
284 | 315 | /// |
285 | 316 | /// If the thrown error need only be an instance of a particular type, use |
286 | | -/// ``expect(throws:_:performing:)-2j0od`` instead. If the thrown error need |
287 | | -/// only equal another instance of [`Error`](https://developer.apple.com/documentation/swift/error), |
288 | | -/// use ``expect(throws:_:performing:)-1s3lx`` instead. If an error should |
289 | | -/// _never_ be thrown, use ``expect(throws:_:performing:)-jtjw`` instead. |
| 317 | +/// ``expect(throws:_:sourceLocation:performing:)-79piu`` instead. If the thrown |
| 318 | +/// error need only equal another instance of [`Error`](https://developer.apple.com/documentation/swift/error), |
| 319 | +/// use ``expect(throws:_:sourceLocation:performing:)-1xr34`` instead. If an |
| 320 | +/// error should _never_ be thrown, use |
| 321 | +/// ``expect(throws:_:sourceLocation:performing:)-5lzjz`` instead. |
290 | 322 | @freestanding(expression) public macro expect<R>( |
291 | 323 | _ comment: @autoclosure () -> Comment? = nil, |
| 324 | + sourceLocation: SourceLocation = SourceLocation(), |
292 | 325 | performing expression: () async throws -> R, |
293 | 326 | throws errorMatcher: (any Error) async throws -> Bool |
294 | 327 | ) = #externalMacro(module: "TestingMacros", type: "ExpectMacro") |
|
298 | 331 | /// |
299 | 332 | /// - Parameters: |
300 | 333 | /// - comment: A comment describing the expectation. |
| 334 | +/// - sourceLocation: The source location to which recorded expectations and |
| 335 | +/// issues should be attributed. |
301 | 336 | /// - expression: The expression to be evaluated. |
302 | 337 | /// - errorMatcher: A closure to invoke when `expression` throws an error that |
303 | 338 | /// indicates if it matched or not. |
|
326 | 361 | /// discarded. |
327 | 362 | /// |
328 | 363 | /// If the thrown error need only be an instance of a particular type, use |
329 | | -/// ``require(throws:_:performing:)-8762f`` instead. If the thrown error need |
| 364 | +/// ``require(throws:_:sourceLocation:performing:)-76bjn`` instead. If the thrown error need |
330 | 365 | /// only equal another instance of [`Error`](https://developer.apple.com/documentation/swift/error), |
331 | | -/// use ``require(throws:_:performing:)-84jir`` instead. |
| 366 | +/// use ``require(throws:_:sourceLocation:performing:)-7v83e`` instead. |
332 | 367 | /// |
333 | 368 | /// If `expression` should _never_ throw, simply invoke the code without using |
334 | 369 | /// this macro. The test will then fail if an error is thrown. |
335 | 370 | @freestanding(expression) public macro require<R>( |
336 | 371 | _ comment: @autoclosure () -> Comment? = nil, |
| 372 | + sourceLocation: SourceLocation = SourceLocation(), |
337 | 373 | performing expression: () async throws -> R, |
338 | 374 | throws errorMatcher: (any Error) async throws -> Bool |
339 | 375 | ) = #externalMacro(module: "TestingMacros", type: "RequireMacro") |
0 commit comments