Skip to content

Commit 74e2170

Browse files
authored
Lower the 'TestCases' protocol to internal (#104)
* Lower the 'TestCases' protocol to internal * Note sendability guarantee
1 parent 3d8fea9 commit 74e2170

File tree

4 files changed

+31
-8
lines changed

4 files changed

+31
-8
lines changed

Sources/Testing/Running/Runner.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ extension Runner {
210210
///
211211
/// If parallelization is supported and enabled, the generated test cases will
212212
/// be run in parallel using a task group.
213-
private func _runTestCases(_ testCases: some TestCases, within step: Plan.Step) async throws {
213+
private func _runTestCases(_ testCases: some Sequence<Test.Case>, within step: Plan.Step) async throws {
214214
if configuration.isParallelizationEnabled {
215215
try await withThrowingTaskGroup(of: Void.self) { taskGroup in
216216
for testCase in testCases {

Sources/Testing/Test.Case.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ extension Test {
8383
/// ([96960993](rdar://96960993)). It is also not possible to have a value of
8484
/// an underlying generic sequence type without specifying its generic
8585
/// parameters.
86-
@_spi(ExperimentalParameterizedTesting)
87-
public protocol TestCases: Sequence & Sendable where Element == Test.Case {
86+
protocol TestCases: Sequence<Test.Case> & Sendable {
8887
/// Whether this sequence is for a parameterized test.
8988
///
9089
/// Both non-parameterized and parameterized tests may have an associated

Sources/Testing/Test.swift

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,19 +94,26 @@ public struct Test: Sendable {
9494
@_spi(ExperimentalTestRunning)
9595
public var xcTestCompatibleSelector: __XCTestCompatibleSelector?
9696

97+
/// Storage for the ``testCases`` property.
98+
private var _testCases: (any TestCases)?
99+
97100
/// The set of test cases associated with this test, if any.
98101
///
99102
/// For parameterized tests, each test case is associated with a single
100103
/// combination of parameterized inputs. For non-parameterized tests, a single
101104
/// test case is synthesized. For test suite types (as opposed to test
102105
/// functions), the value of this property is `nil`.
106+
///
107+
/// The value of this property is guaranteed to be `Sendable`.
103108
@_spi(ExperimentalParameterizedTesting)
104-
public var testCases: (any TestCases)?
109+
public var testCases: (any Sequence<Test.Case>)? {
110+
_testCases as? any Sequence<Test.Case>
111+
}
105112

106113
/// Whether or not this test is parameterized.
107114
@_spi(ExperimentalParameterizedTesting)
108115
public var isParameterized: Bool {
109-
testCases?.isParameterized ?? false
116+
_testCases?.isParameterized ?? false
110117
}
111118

112119
/// The test function parameters, if any.
@@ -128,6 +135,26 @@ public struct Test: Sendable {
128135
public var isSuite: Bool {
129136
containingType != nil && testCases == nil
130137
}
138+
139+
init(
140+
name: String,
141+
displayName: String? = nil,
142+
traits: [any Trait],
143+
sourceLocation: SourceLocation,
144+
containingType: Any.Type? = nil,
145+
xcTestCompatibleSelector: __XCTestCompatibleSelector? = nil,
146+
testCases: (any TestCases)? = nil,
147+
parameters: [ParameterInfo]? = nil
148+
) {
149+
self.name = name
150+
self.displayName = displayName
151+
self.traits = traits
152+
self.sourceLocation = sourceLocation
153+
self.containingType = containingType
154+
self.xcTestCompatibleSelector = xcTestCompatibleSelector
155+
self._testCases = testCases
156+
self.parameters = parameters
157+
}
131158
}
132159

133160
// MARK: - Equatable, Hashable

Tests/TestingTests/MiscellaneousTests.swift

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -433,15 +433,13 @@ struct MiscellaneousTests {
433433
#expect(!monomorphicTestFunction.isParameterized)
434434
let monomorphicTestFunctionTestCases = try #require(monomorphicTestFunction.testCases)
435435
#expect(monomorphicTestFunctionTestCases.underestimatedCount == 1)
436-
#expect(!monomorphicTestFunctionTestCases.isParameterized)
437436
let monomorphicTestFunctionParameters = try #require(monomorphicTestFunction.parameters)
438437
#expect(monomorphicTestFunctionParameters.isEmpty)
439438

440439
let parameterizedTestFunction = Test(arguments: 0 ..< 100, parameters: [Test.ParameterInfo(firstName: "i")]) { _ in }
441440
#expect(parameterizedTestFunction.isParameterized)
442441
let parameterizedTestFunctionTestCases = try #require(parameterizedTestFunction.testCases)
443442
#expect(parameterizedTestFunctionTestCases.underestimatedCount == 100)
444-
#expect(parameterizedTestFunctionTestCases.isParameterized)
445443
let parameterizedTestFunctionParameters = try #require(parameterizedTestFunction.parameters)
446444
#expect(parameterizedTestFunctionParameters.count == 1)
447445
let parameterizedTestFunctionFirstParameter = try #require(parameterizedTestFunctionParameters.first)
@@ -454,7 +452,6 @@ struct MiscellaneousTests {
454452
#expect(parameterizedTestFunction2.isParameterized)
455453
let parameterizedTestFunction2TestCases = try #require(parameterizedTestFunction2.testCases)
456454
#expect(parameterizedTestFunction2TestCases.underestimatedCount == 100 * 100)
457-
#expect(parameterizedTestFunction2TestCases.isParameterized)
458455
let parameterizedTestFunction2Parameters = try #require(parameterizedTestFunction2.parameters)
459456
#expect(parameterizedTestFunction2Parameters.count == 2)
460457
let parameterizedTestFunction2FirstParameter = try #require(parameterizedTestFunction2Parameters.first)

0 commit comments

Comments
 (0)