diff --git a/Sources/Testing/Running/Runner.swift b/Sources/Testing/Running/Runner.swift index 2e140e21..2706021c 100644 --- a/Sources/Testing/Running/Runner.swift +++ b/Sources/Testing/Running/Runner.swift @@ -210,7 +210,7 @@ extension Runner { /// /// If parallelization is supported and enabled, the generated test cases will /// be run in parallel using a task group. - private func _runTestCases(_ testCases: some TestCases, within step: Plan.Step) async throws { + private func _runTestCases(_ testCases: some Sequence, within step: Plan.Step) async throws { if configuration.isParallelizationEnabled { try await withThrowingTaskGroup(of: Void.self) { taskGroup in for testCase in testCases { diff --git a/Sources/Testing/Test.Case.swift b/Sources/Testing/Test.Case.swift index ec5dd4e1..74bca53f 100644 --- a/Sources/Testing/Test.Case.swift +++ b/Sources/Testing/Test.Case.swift @@ -83,8 +83,7 @@ extension Test { /// ([96960993](rdar://96960993)). It is also not possible to have a value of /// an underlying generic sequence type without specifying its generic /// parameters. -@_spi(ExperimentalParameterizedTesting) -public protocol TestCases: Sequence & Sendable where Element == Test.Case { +protocol TestCases: Sequence & Sendable { /// Whether this sequence is for a parameterized test. /// /// Both non-parameterized and parameterized tests may have an associated diff --git a/Sources/Testing/Test.swift b/Sources/Testing/Test.swift index 6213b4dd..7390415b 100644 --- a/Sources/Testing/Test.swift +++ b/Sources/Testing/Test.swift @@ -94,19 +94,26 @@ public struct Test: Sendable { @_spi(ExperimentalTestRunning) public var xcTestCompatibleSelector: __XCTestCompatibleSelector? + /// Storage for the ``testCases`` property. + private var _testCases: (any TestCases)? + /// The set of test cases associated with this test, if any. /// /// For parameterized tests, each test case is associated with a single /// combination of parameterized inputs. For non-parameterized tests, a single /// test case is synthesized. For test suite types (as opposed to test /// functions), the value of this property is `nil`. + /// + /// The value of this property is guaranteed to be `Sendable`. @_spi(ExperimentalParameterizedTesting) - public var testCases: (any TestCases)? + public var testCases: (any Sequence)? { + _testCases as? any Sequence + } /// Whether or not this test is parameterized. @_spi(ExperimentalParameterizedTesting) public var isParameterized: Bool { - testCases?.isParameterized ?? false + _testCases?.isParameterized ?? false } /// The test function parameters, if any. @@ -128,6 +135,26 @@ public struct Test: Sendable { public var isSuite: Bool { containingType != nil && testCases == nil } + + init( + name: String, + displayName: String? = nil, + traits: [any Trait], + sourceLocation: SourceLocation, + containingType: Any.Type? = nil, + xcTestCompatibleSelector: __XCTestCompatibleSelector? = nil, + testCases: (any TestCases)? = nil, + parameters: [ParameterInfo]? = nil + ) { + self.name = name + self.displayName = displayName + self.traits = traits + self.sourceLocation = sourceLocation + self.containingType = containingType + self.xcTestCompatibleSelector = xcTestCompatibleSelector + self._testCases = testCases + self.parameters = parameters + } } // MARK: - Equatable, Hashable diff --git a/Tests/TestingTests/MiscellaneousTests.swift b/Tests/TestingTests/MiscellaneousTests.swift index 9a36fa49..439a61f6 100644 --- a/Tests/TestingTests/MiscellaneousTests.swift +++ b/Tests/TestingTests/MiscellaneousTests.swift @@ -433,7 +433,6 @@ struct MiscellaneousTests { #expect(!monomorphicTestFunction.isParameterized) let monomorphicTestFunctionTestCases = try #require(monomorphicTestFunction.testCases) #expect(monomorphicTestFunctionTestCases.underestimatedCount == 1) - #expect(!monomorphicTestFunctionTestCases.isParameterized) let monomorphicTestFunctionParameters = try #require(monomorphicTestFunction.parameters) #expect(monomorphicTestFunctionParameters.isEmpty) @@ -441,7 +440,6 @@ struct MiscellaneousTests { #expect(parameterizedTestFunction.isParameterized) let parameterizedTestFunctionTestCases = try #require(parameterizedTestFunction.testCases) #expect(parameterizedTestFunctionTestCases.underestimatedCount == 100) - #expect(parameterizedTestFunctionTestCases.isParameterized) let parameterizedTestFunctionParameters = try #require(parameterizedTestFunction.parameters) #expect(parameterizedTestFunctionParameters.count == 1) let parameterizedTestFunctionFirstParameter = try #require(parameterizedTestFunctionParameters.first) @@ -454,7 +452,6 @@ struct MiscellaneousTests { #expect(parameterizedTestFunction2.isParameterized) let parameterizedTestFunction2TestCases = try #require(parameterizedTestFunction2.testCases) #expect(parameterizedTestFunction2TestCases.underestimatedCount == 100 * 100) - #expect(parameterizedTestFunction2TestCases.isParameterized) let parameterizedTestFunction2Parameters = try #require(parameterizedTestFunction2.parameters) #expect(parameterizedTestFunction2Parameters.count == 2) let parameterizedTestFunction2FirstParameter = try #require(parameterizedTestFunction2Parameters.first)