Skip to content

Commit d63cbd4

Browse files
authored
Replace fixture protocol in ConfirmationTests with an existential composition of parameterized protocols (#1598)
This modifies a test fixture in `ConfirmationTests` now that both a Swift language limitation, and an associated runtime bug, have been resolved. The original issue was that the language did not support writing `any RangeExpression<Int> & Sequence<Int> & Sendable`, but that was resolved in Swift 6.2 in swiftlang/swift#76705. Once that was resolved, it exposed a runtime bug which would crash when forming a collection of such existential types. That was fixed in swiftlang/swift#85346, and landed in Apple's 26.4 OSes (currently in beta). This PR finally removes the workaround and writes this parameterized test the idiomatic way, using a collection whose element type is a composition of protocols where some are parameterized. ### 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 95d9871 commit d63cbd4

File tree

3 files changed

+27
-3
lines changed

3 files changed

+27
-3
lines changed

Package.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,6 +432,7 @@ extension Array where Element == PackageDescription.SwiftSetting {
432432
.enableExperimentalFeature("AvailabilityMacro=_clockAPI:macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0"),
433433
.enableExperimentalFeature("AvailabilityMacro=_typedThrowsAPI:macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0"),
434434
.enableExperimentalFeature("AvailabilityMacro=_castingWithNonCopyableGenerics:macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0"),
435+
.enableExperimentalFeature("AvailabilityMacro=_compositionOfParameterizedProtocols:macOS 26.4, iOS 26.4, watchOS 26.4, tvOS 26.4, visionOS 26.4"),
435436

436437
.enableExperimentalFeature("AvailabilityMacro=_distantFuture:macOS 99.0, iOS 99.0, watchOS 99.0, tvOS 99.0, visionOS 99.0"),
437438
]

Tests/TestingTests/ConfirmationTests.swift

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,14 @@ struct ConfirmationTests {
3333

3434
@Test("Unsuccessful confirmations")
3535
func unsuccessfulConfirmations() async {
36-
await confirmation("Miscount recorded", expectedCount: 7) { miscountRecorded in
36+
// confirmedOutOfRange(_:) is availability-guarded, but if it runs, increase
37+
// the number of expected miscounts by the number of arguments passed to it.
38+
var expectedCount = 7
39+
if #available(_compositionOfParameterizedProtocols, *) {
40+
expectedCount += 4
41+
}
42+
43+
await confirmation("Miscount recorded", expectedCount: expectedCount) { miscountRecorded in
3744
var configuration = Configuration()
3845
configuration.eventHandler = { event, _ in
3946
if case let .issueRecorded(issue) = event.kind {
@@ -152,13 +159,28 @@ struct UnsuccessfulConfirmationTests {
152159
}
153160
}
154161

162+
// FIXME: Remove this test once the deployment targets are greater than or
163+
// equal to the versions specified in `_compositionOfParameterizedProtocols`.
155164
@Test(.hidden, arguments: [
156165
1 ... 2 as any ExpectedCount,
157166
1 ..< 2,
158167
1 ..< 3,
159168
999...,
160169
])
161-
func confirmedOutOfRange(_ range: any ExpectedCount) async {
170+
func confirmedOutOfRange_legacy(_ range: any ExpectedCount) async {
171+
await confirmation(expectedCount: range) { (thingHappened) async in
172+
thingHappened(count: 3)
173+
}
174+
}
175+
176+
@Test(.hidden, arguments: [
177+
1 ... 2 as any RangeExpression<Int> & Sequence<Int> & Sendable,
178+
1 ..< 2,
179+
1 ..< 3,
180+
999...,
181+
])
182+
@available(_compositionOfParameterizedProtocols, *)
183+
func confirmedOutOfRange(_ range: any RangeExpression<Int> & Sequence<Int> & Sendable) async {
162184
await confirmation(expectedCount: range) { (thingHappened) async in
163185
thingHappened(count: 3)
164186
}
@@ -168,7 +190,7 @@ struct UnsuccessfulConfirmationTests {
168190
// MARK: -
169191

170192
/// Needed since we don't have generic test functions, so we need a concrete
171-
/// argument type for `confirmedOutOfRange(_:)`. Although we can now write
193+
/// argument type for `confirmedOutOfRange_legacy(_:)`. Although we can now write
172194
/// `any RangeExpression<Int> & Sequence<Int> & Sendable` as of Swift 6.2
173195
/// (per [swiftlang/swift#76705](https://github.com/swiftlang/swift/pull/76705)),
174196
/// attempting to form an array of such values crashes at runtime. ([163980446](rdar://163980446))

cmake/modules/shared/AvailabilityDefinitions.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,5 @@ add_compile_options(
1414
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -define-availability -Xfrontend \"_clockAPI:macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0\">"
1515
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -define-availability -Xfrontend \"_typedThrowsAPI:macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0\">"
1616
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -define-availability -Xfrontend \"_castingWithNonCopyableGenerics:macOS 15.0, iOS 18.0, watchOS 11.0, tvOS 18.0, visionOS 2.0\">"
17+
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -define-availability -Xfrontend \"_compositionOfParameterizedProtocols:macOS 26.4, iOS 26.4, watchOS 26.4, tvOS 26.4, visionOS 26.4\">"
1718
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -define-availability -Xfrontend \"_distantFuture:macOS 99.0, iOS 99.0, watchOS 99.0, tvOS 99.0, visionOS 99.0\">")

0 commit comments

Comments
 (0)