Skip to content

Remove the Confirmation.ExpectedCount marker protocol. #689

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 2 commits into from
Sep 13, 2024

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Sep 13, 2024

This PR replaces uses of Confirmation.ExpectedCount in our API surface with RangeExpression<Int> & Sendable. A composed protocol type P<A> & Q can only be expressed as some, not any as the latter is not yet implemented in the compiler (rdar://96960993), so we were using a separate protocol in place of that combination.

The downside of doing so is that it makes the legibility of the interface worse. Xcode and other IDEs will offer you confirmation(expectedCount: Confirmation.ExpectedCount) but don't tell you that you need to write some range expression such as 0...2. You have to dig into the protocol definition/documentation to figure it out.

So this change changes the signature of the experimental confirmation() overload to take a some RangeExpression<Int> & Sendable and plumbs that through everywhere it's valid. Once we get to generating an Issue, we need an existential box (any) at which point we will just drop the <Int> bit until the compiler feature is added.

We have a parameterized unit test that takes an array of these values, so to keep it building and passing, I moved a copy of the ExpectedCount protocol to the fixtures section of the test file containing that test; it's present only in our test target and not in our API surface.

Checklist:

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

This PR replaces uses of `Confirmation.ExpectedCount` in our API surface with
`RangeExpression<Int> & Sendable`. A composed protocol type `P<A> & Q` can only
be expressed as `some`, not `any` as the latter is not yet implemented in the
compiler (rdar://96960993), so we were using a separate protocol in place of
that combination.

The downside of doing so is that it makes the legibility of the interface worse.
Xcode and other IDEs will offer you `confirmation(expectedCount: Confirmation.ExpectedCount)`
but don't tell you that you need to write some range expression such as `0...2`.
You have to dig into the protocol definition/documentation to figure it out.

So this change changes the signature of the experimental `confirmation()`
overload to take a `some RangeExpression<Int> & Sendable` and plumbs that
through everywhere it's valid. Once we get to generating an `Issue`, we need an
existential box (`any`) at which point we will just drop the `<Int>` bit until
the compiler feature is added.

We have a parameterized unit test that takes an array of these values, so to
keep it building and passing, I moved a copy of the `ExpectedCount` protocol to
the fixtures section of the test file containing that test; it's present only in
our test target and not in our API surface.
@grynspan grynspan added enhancement New feature or request tools integration Integration of swift-testing into tools/IDEs public-api Affects public API issue-handling Related to Issue handling within the testing library labels Sep 13, 2024
@grynspan grynspan self-assigned this Sep 13, 2024
@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan grynspan merged commit 7895995 into main Sep 13, 2024
3 checks passed
@grynspan grynspan deleted the jgrynspan/remove-expectedcount-protocol branch September 13, 2024 19:00
@grynspan grynspan added this to the Swift 6.1 milestone Sep 20, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request issue-handling Related to Issue handling within the testing library public-api Affects public API tools integration Integration of swift-testing into tools/IDEs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants