Commit 46afc15
authored
Don't capture arguments to
Other than the body closure, the arguments to `#expect(exitsWith:)` are
not guaranteed to be literals or otherwise context-free, but we capture
them during macro expansion. This can result in obscure errors if the
developer writes an exit test with an argument that is computed:
```swift
let foo = ...
await #expect(exitsWith: self.exitCondition(for: foo)) {
// 🛑 error: closure captures 'foo' before it is declared
// 🛑 error: enum declaration cannot close over value 'self' defined in outer scope
// (and other possible errors)
...
}
```
This PR removes the macro's compile-time dependency on its
`exitCondition` and `sourceLocation` arguments and introduces an `ID`
type to identify exit tests (instead of using their source locations as
unique IDs.) The `ID` type is meant to be a UUID, but for the moment
I've just strung together two 64-bit integers instead to avoid a
dependency on Foundation or platform API.
### Checklist:
- [x] Code and documentation should follow the style of the [Style
Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md).
- [x] If public symbols are renamed or modified, DocC references should
be updated.#expect(exitsWith:) during macro expansion. (#912)1 parent 5494982 commit 46afc15
File tree
7 files changed
+84
-58
lines changed- Documentation/ABI
- Sources
- TestingMacros
- Testing
- ExitTests
- Expectations
- Tests/TestingTests
7 files changed
+84
-58
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
121 | | - | |
122 | | - | |
123 | | - | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
124 | 132 | | |
125 | 133 | | |
126 | 134 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
55 | | - | |
56 | | - | |
57 | | - | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
58 | 71 | | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
| 72 | + | |
| 73 | + | |
65 | 74 | | |
66 | 75 | | |
67 | 76 | | |
| |||
110 | 119 | | |
111 | 120 | | |
112 | 121 | | |
113 | | - | |
114 | | - | |
| 122 | + | |
115 | 123 | | |
116 | 124 | | |
117 | | - | |
118 | | - | |
| 125 | + | |
119 | 126 | | |
120 | 127 | | |
121 | 128 | | |
| |||
222 | 229 | | |
223 | 230 | | |
224 | 231 | | |
225 | | - | |
| 232 | + | |
226 | 233 | | |
227 | 234 | | |
228 | 235 | | |
229 | 236 | | |
230 | 237 | | |
231 | 238 | | |
232 | 239 | | |
233 | | - | |
| 240 | + | |
234 | 241 | | |
235 | 242 | | |
236 | 243 | | |
237 | | - | |
| 244 | + | |
238 | 245 | | |
239 | 246 | | |
240 | | - | |
241 | | - | |
242 | | - | |
243 | | - | |
244 | | - | |
245 | | - | |
246 | | - | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
247 | 250 | | |
248 | 251 | | |
249 | 252 | | |
| |||
252 | 255 | | |
253 | 256 | | |
254 | 257 | | |
255 | | - | |
256 | | - | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
| 258 | + | |
| 259 | + | |
263 | 260 | | |
264 | 261 | | |
265 | 262 | | |
| |||
272 | 269 | | |
273 | 270 | | |
274 | 271 | | |
| 272 | + | |
275 | 273 | | |
276 | 274 | | |
277 | 275 | | |
| |||
290 | 288 | | |
291 | 289 | | |
292 | 290 | | |
| 291 | + | |
293 | 292 | | |
294 | 293 | | |
295 | 294 | | |
| |||
304 | 303 | | |
305 | 304 | | |
306 | 305 | | |
307 | | - | |
| 306 | + | |
308 | 307 | | |
309 | 308 | | |
310 | 309 | | |
| |||
424 | 423 | | |
425 | 424 | | |
426 | 425 | | |
427 | | - | |
428 | | - | |
429 | | - | |
430 | | - | |
431 | | - | |
432 | | - | |
433 | | - | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
434 | 431 | | |
435 | 432 | | |
436 | | - | |
| 433 | + | |
437 | 434 | | |
438 | 435 | | |
439 | 436 | | |
440 | 437 | | |
441 | 438 | | |
442 | 439 | | |
443 | | - | |
| 440 | + | |
444 | 441 | | |
445 | 442 | | |
446 | 443 | | |
| |||
560 | 557 | | |
561 | 558 | | |
562 | 559 | | |
563 | | - | |
564 | | - | |
| 560 | + | |
| 561 | + | |
565 | 562 | | |
566 | 563 | | |
567 | 564 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
546 | 546 | | |
547 | 547 | | |
548 | 548 | | |
549 | | - | |
| 549 | + | |
550 | 550 | | |
551 | 551 | | |
552 | 552 | | |
| |||
658 | 658 | | |
659 | 659 | | |
660 | 660 | | |
661 | | - | |
| 661 | + | |
662 | 662 | | |
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1147 | 1147 | | |
1148 | 1148 | | |
1149 | 1149 | | |
| 1150 | + | |
1150 | 1151 | | |
1151 | 1152 | | |
1152 | 1153 | | |
| |||
1157 | 1158 | | |
1158 | 1159 | | |
1159 | 1160 | | |
| 1161 | + | |
1160 | 1162 | | |
1161 | 1163 | | |
1162 | 1164 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 35 | + | |
| 36 | + | |
40 | 37 | | |
41 | 38 | | |
42 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
416 | 416 | | |
417 | 417 | | |
418 | 418 | | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
419 | 423 | | |
420 | 424 | | |
421 | 425 | | |
| |||
436 | 440 | | |
437 | 441 | | |
438 | 442 | | |
439 | | - | |
440 | | - | |
| 443 | + | |
| 444 | + | |
441 | 445 | | |
442 | 446 | | |
443 | 447 | | |
444 | 448 | | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | 449 | | |
449 | 450 | | |
450 | 451 | | |
| |||
458 | 459 | | |
459 | 460 | | |
460 | 461 | | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
461 | 472 | | |
462 | 473 | | |
463 | 474 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
405 | 405 | | |
406 | 406 | | |
407 | 407 | | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
408 | 419 | | |
409 | 420 | | |
410 | 421 | | |
| |||
0 commit comments