Commit 1d60944
authored
Ignore ExpectationFailedError when thrown by the body closure passed to withKnownIssue (#1441)
This fixes an issue where a redundant, second known issue is recorded
when `try #require()` fails within the body closure of `withKnownIssue`.
For example, in the following example code:
```swift
@test func example() {
withKnownIssue {
try #require(Bool(false))
}
}
```
two (known) issues are recorded:
> ✘ Test example() recorded a known issue at
KnownIssueTests.swift:641:9: Expectation failed: Bool(false)
> ✘ Test example() recorded a known issue at
KnownIssueTests.swift:640:18: An API was misused
> ↳ Recorded an error of type ExpectationFailedError representing an
expectation that failed and was already recorded: ...
Of these, only the first should be recorded and the second should be
suppressed.
Fixes rdar://153550847
### Motivation:
It should be possible to use `try #require()` in the body closure passed
to `withKnownIssue`, and _matching_ failures should only cause a single
known issue to be recorded. The second issue shown above describes an
infrastructural `Error`-conforming type which is not generally intended
to be included in the results test authors see, and can cause confusion.
### Modifications:
- When attempting to match an error thrown by a `withKnownIssue` body
closure, ignore the error if it's of type `ExpectationFailedError.
- Add a new unit test validating this, which fails prior to the fix.
### 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 00c0b1b commit 1d60944
File tree
2 files changed
+27
-0
lines changed- Sources/Testing/Issues
- Tests/TestingTests
2 files changed
+27
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
80 | 87 | | |
81 | 88 | | |
82 | 89 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
574 | 574 | | |
575 | 575 | | |
576 | 576 | | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
| 587 | + | |
| 588 | + | |
| 589 | + | |
| 590 | + | |
| 591 | + | |
| 592 | + | |
| 593 | + | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
577 | 597 | | |
578 | 598 | | |
579 | 599 | | |
| |||
0 commit comments