Commit a46df3f
authored
Fixes to exit tests. (#615)
This PR supersedes #603, #613, and #614. Exit tests remain an
experimental feature.
## Clarify that 8-bit exit codes aren't a problem on macOS and Windows.
(#603)
The documentation for the experimental exit tests feature currently says
that on POSIX-like systems, only the low 8 bits of a process' exit code
are preserved. This would be true if we used `wait()`, `wait4()`, etc.
and `WEXITSTATUS()`, but we use `waitid()` instead which is [supposed
to](https://pubs.opengroup.org/onlinepubs/9699919799/functions/exit.html)
preserve the full exit code. It does so on Darwin, but not on Linux;
Windows doesn't use `waitid()` but does report the full exit code.
Now, we're not currently building for any other POSIX-like systems that
support processes (WASI/Wasm doesn't count here), so I've left in some
weasel words and added a canary unit test. It will let us know if/when
we add a platform that where `waitid()` doesn't preserve all the bits of
the exit code, and we can amend the documentation in that case.
## Implement an equality operator for ExitCondition. (#613)
This PR implements `==` and `===` for `ExitCondition`, part of the
experimental exit tests feature. These operators are necessary in order
to allow for exit tests to support more complex matching by trailing
closure (e.g. to support inspecting `stdout`.) Because `.failure` is a
fuzzy case, `==` fuzzy-matches while `===` exactly matches. `Hashable`
conformance is unavailable.
Example usage:
```swift
let lhs: ExitCondition = .failure
let rhs: ExitCondition = .signal(SIGTERM)
print(lhs == rhs) // prints "true"
print(lhs === rhs) // prints "false"
```
## Allow throwing an error from an exit test's body. (#614)
This PR amends the signatures of the exit test macros
(`#expect(exitsWith:) {}` and `try #require(exitsWith:) {}`) to allow
bodies to throw errors. If they do, they are treated as uncaught errors
and the child process terminates abnormally (in the same way it does if
an error is thrown from the main function of a Swift program.)
### 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.1 parent d01c406 commit a46df3f
File tree
7 files changed
+224
-34
lines changed- Sources
- TestingMacros
- Testing
- ExitTests
- Expectations
- Tests/TestingTests
- Support
7 files changed
+224
-34
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
47 | | - | |
48 | | - | |
49 | | - | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| |||
62 | 62 | | |
63 | 63 | | |
64 | 64 | | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
65 | 70 | | |
66 | 71 | | |
67 | 72 | | |
68 | 73 | | |
69 | 74 | | |
70 | 75 | | |
71 | | - | |
| 76 | + | |
72 | 77 | | |
73 | 78 | | |
74 | 79 | | |
75 | 80 | | |
76 | 81 | | |
77 | | - | |
| 82 | + | |
78 | 83 | | |
79 | 84 | | |
80 | | - | |
| 85 | + | |
| 86 | + | |
81 | 87 | | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
88 | 109 | | |
89 | 110 | | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
90 | 180 | | |
91 | 181 | | |
92 | 182 | | |
93 | 183 | | |
94 | 184 | | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
100 | | - | |
101 | 185 | | |
| 186 | + | |
| 187 | + | |
102 | 188 | | |
103 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
104 | 220 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
24 | | - | |
| 24 | + | |
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| |||
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | | - | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
41 | 45 | | |
42 | 46 | | |
43 | 47 | | |
44 | 48 | | |
45 | | - | |
| 49 | + | |
46 | 50 | | |
47 | 51 | | |
48 | 52 | | |
| |||
63 | 67 | | |
64 | 68 | | |
65 | 69 | | |
66 | | - | |
| 70 | + | |
67 | 71 | | |
68 | 72 | | |
69 | 73 | | |
| |||
118 | 122 | | |
119 | 123 | | |
120 | 124 | | |
121 | | - | |
| 125 | + | |
122 | 126 | | |
123 | 127 | | |
124 | 128 | | |
| |||
150 | 154 | | |
151 | 155 | | |
152 | 156 | | |
153 | | - | |
| 157 | + | |
154 | 158 | | |
155 | 159 | | |
156 | 160 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
440 | 440 | | |
441 | 441 | | |
442 | 442 | | |
443 | | - | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
444 | 446 | | |
445 | 447 | | |
446 | 448 | | |
| |||
488 | 490 | | |
489 | 491 | | |
490 | 492 | | |
491 | | - | |
492 | | - | |
| 493 | + | |
| 494 | + | |
493 | 495 | | |
494 | 496 | | |
495 | 497 | | |
| |||
515 | 517 | | |
516 | 518 | | |
517 | 519 | | |
518 | | - | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
519 | 523 | | |
520 | 524 | | |
521 | 525 | | |
| |||
550 | 554 | | |
551 | 555 | | |
552 | 556 | | |
553 | | - | |
| 557 | + | |
554 | 558 | | |
Lines changed: 2 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1103 | 1103 | | |
1104 | 1104 | | |
1105 | 1105 | | |
1106 | | - | |
| 1106 | + | |
1107 | 1107 | | |
1108 | 1108 | | |
1109 | 1109 | | |
1110 | 1110 | | |
1111 | 1111 | | |
1112 | 1112 | | |
1113 | 1113 | | |
1114 | | - | |
| 1114 | + | |
1115 | 1115 | | |
1116 | 1116 | | |
1117 | 1117 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
362 | 362 | | |
363 | 363 | | |
364 | 364 | | |
365 | | - | |
| 365 | + | |
366 | 366 | | |
367 | 367 | | |
368 | 368 | | |
369 | 369 | | |
370 | 370 | | |
371 | 371 | | |
372 | 372 | | |
373 | | - | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
374 | 382 | | |
375 | 383 | | |
376 | 384 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
35 | 38 | | |
36 | 39 | | |
37 | 40 | | |
| |||
197 | 200 | | |
198 | 201 | | |
199 | 202 | | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
200 | 248 | | |
201 | 249 | | |
202 | 250 | | |
| |||
0 commit comments