Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Lower the 'TestCases' protocol to internal #104

Merged
merged 2 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Sources/Testing/Running/Runner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Test.Case>, within step: Plan.Step) async throws {
if configuration.isParallelizationEnabled {
try await withThrowingTaskGroup(of: Void.self) { taskGroup in
for testCase in testCases {
Expand Down
3 changes: 1 addition & 2 deletions Sources/Testing/Test.Case.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Test.Case> & Sendable {
/// Whether this sequence is for a parameterized test.
///
/// Both non-parameterized and parameterized tests may have an associated
Expand Down
31 changes: 29 additions & 2 deletions Sources/Testing/Test.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Test.Case>)? {
_testCases as? any Sequence<Test.Case>
}

/// 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.
Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions Tests/TestingTests/MiscellaneousTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -433,15 +433,13 @@ struct MiscellaneousTests {
#expect(!monomorphicTestFunction.isParameterized)
let monomorphicTestFunctionTestCases = try #require(monomorphicTestFunction.testCases)
#expect(monomorphicTestFunctionTestCases.underestimatedCount == 1)
#expect(!monomorphicTestFunctionTestCases.isParameterized)
stmontgomery marked this conversation as resolved.
Show resolved Hide resolved
let monomorphicTestFunctionParameters = try #require(monomorphicTestFunction.parameters)
#expect(monomorphicTestFunctionParameters.isEmpty)

let parameterizedTestFunction = Test(arguments: 0 ..< 100, parameters: [Test.ParameterInfo(firstName: "i")]) { _ in }
#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)
Expand All @@ -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)
Expand Down