Skip to content

Conversation

@stmontgomery
Copy link
Contributor

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:

@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:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

…ors of type ExpectationFailedError. And add a proper test
@stmontgomery stmontgomery added this to the Swift 6.3.0 milestone Dec 8, 2025
@stmontgomery stmontgomery self-assigned this Dec 8, 2025
@stmontgomery stmontgomery added bug 🪲 Something isn't working issue-handling Related to Issue handling within the testing library labels Dec 8, 2025
Copy link
Contributor

@briancroom briancroom left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great, thanks!

@stmontgomery stmontgomery merged commit 1d60944 into swiftlang:main Dec 9, 2025
27 checks passed
@stmontgomery stmontgomery deleted the expectedfailederror-known-issue branch December 9, 2025 21:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug 🪲 Something isn't working issue-handling Related to Issue handling within the testing library

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants