You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Avoid reassigning task-local runtime state in a Runner's event handler unless it's nested (#339)
This is a mitigation for a bug in which an expectation inside a
`withTaskGroup` closure can cause a crash if it fails.
### Motivation:
It can sometimes be useful to perform expectations (e.g. `#expect`)
within the body of the closure passed to `withTaskGroup` or similar
APIs. However, doing so currently causes a crash if the expectation
fails, illustrated by this small example:
```swift
@test func example() async {
await withTaskGroup(of: Void.self) { _ in
#expect("abc" == "123") // 💥
}
}
```
### Modifications:
This change avoids wrapping the event handler of a runner's
configuration with one that reassigns a TaskLocal (potentially
triggering the crash) unless that runner is running during the run
operation of another runner. In other words, only mutate the TaskLocal
for nested runners. Nesting, or running one runner in the context of
another, is something which is only done in practice when performing
tests of the testing library itself. Ordinary usage of the testing
library only has one “outer“ runner.
### Result:
The above example code no longer crashes, verified by the new unit test.
### 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.
Resolves rdar://126132392
0 commit comments