diff --git a/Sources/Testing/Running/Configuration.swift b/Sources/Testing/Running/Configuration.swift index 7a25cc4c9..f50d39176 100644 --- a/Sources/Testing/Running/Configuration.swift +++ b/Sources/Testing/Running/Configuration.swift @@ -177,29 +177,10 @@ public struct Configuration: Sendable { /// - Parameters: /// - selection: A set of test IDs to be filtered. /// -/// By default, all tests are run and no filter is set. +/// - Returns: A test filter that filters tests to those specified by +/// `selection`. @_spi(ExperimentalTestRunning) public func makeTestFilter(matching selection: some Collection) -> Configuration.TestFilter { let selection = Test.ID.Selection(testIDs: selection) - return makeTestFilter(matching: selection, includeHiddenTests: false) + return selection.contains } - -/// Make a test filter that filters tests to those specified by a set of test -/// IDs, optionally including or excluding hidden tests. -/// -/// - Parameters: -/// - selection: A selection of test IDs to be filtered. -/// - includeHiddenTests: If false, a test annotated with the `.hidden` -/// trait will not be included, even if its ID is present in `selection`. -/// -/// By default, all tests are run and no filter is set. -func makeTestFilter(matching selection: Test.ID.Selection, includeHiddenTests: Bool) -> Configuration.TestFilter { - if includeHiddenTests { - return selection.contains - } else { - return { test in - !test.isHidden && selection.contains(test) - } - } -} - diff --git a/Tests/TestingTests/PlanTests.swift b/Tests/TestingTests/PlanTests.swift index 27005d5ae..56cc7d5a0 100644 --- a/Tests/TestingTests/PlanTests.swift +++ b/Tests/TestingTests/PlanTests.swift @@ -26,9 +26,9 @@ struct PlanTests { testB, ] - let selection = Test.ID.Selection(testIDs: [innerTestType.id]) + let selection = [innerTestType.id] var configuration = Configuration() - configuration.uncheckedTestFilter = makeTestFilter(matching: selection, includeHiddenTests: true) + configuration.uncheckedTestFilter = makeTestFilter(matching: selection) let plan = await Runner.Plan(tests: tests, configuration: configuration) #expect(plan.steps.contains(where: { $0.test == outerTestType })) @@ -52,8 +52,8 @@ struct PlanTests { ] var configuration = Configuration() - let selection = Test.ID.Selection(testIDs: [innerTestType.id, outerTestType.id]) - configuration.uncheckedTestFilter = makeTestFilter(matching: selection, includeHiddenTests: true) + let selection = [innerTestType.id, outerTestType.id] + configuration.uncheckedTestFilter = makeTestFilter(matching: selection) let plan = await Runner.Plan(tests: tests, configuration: configuration) let planTests = plan.steps.map(\.test) @@ -72,8 +72,8 @@ struct PlanTests { let tests = [outerTestType, deeplyNestedTest] var configuration = Configuration() - let selection = Test.ID.Selection(testIDs: [outerTestType.id, deeplyNestedTest.id]) - configuration.uncheckedTestFilter = makeTestFilter(matching: selection, includeHiddenTests: true) + let selection = [outerTestType.id, deeplyNestedTest.id] + configuration.uncheckedTestFilter = makeTestFilter(matching: selection) let plan = await Runner.Plan(tests: tests, configuration: configuration) @@ -91,8 +91,8 @@ struct PlanTests { let tests = [testSuiteA, testSuiteB, testSuiteC, testFuncX] var configuration = Configuration() - let selection = Test.ID.Selection(testIDs: [testSuiteA.id]) - configuration.uncheckedTestFilter = makeTestFilter(matching: selection, includeHiddenTests: true) + let selection = [testSuiteA.id] + configuration.uncheckedTestFilter = makeTestFilter(matching: selection) let plan = await Runner.Plan(tests: tests, configuration: configuration) let testFuncXWithTraits = try #require(plan.steps.map(\.test).first { $0.name == "x()" }) diff --git a/Tests/TestingTests/Runner.Plan.SnapshotTests.swift b/Tests/TestingTests/Runner.Plan.SnapshotTests.swift index 7456f569e..73a6b6650 100644 --- a/Tests/TestingTests/Runner.Plan.SnapshotTests.swift +++ b/Tests/TestingTests/Runner.Plan.SnapshotTests.swift @@ -22,7 +22,7 @@ struct Runner_Plan_SnapshotTests { let suite = try #require(await test(for: Runner_Plan_SnapshotFixtures.self)) var configuration = Configuration() - configuration.uncheckedTestFilter = makeTestFilter(matching: .init(testIDs: [suite.id]), includeHiddenTests: true) + configuration.uncheckedTestFilter = makeTestFilter(matching: [suite.id]) let plan = await Runner.Plan(configuration: configuration) let snapshot = Runner.Plan.Snapshot(snapshotting: plan) diff --git a/Tests/TestingTests/RunnerTests.swift b/Tests/TestingTests/RunnerTests.swift index 5d17751fe..dd31b765b 100644 --- a/Tests/TestingTests/RunnerTests.swift +++ b/Tests/TestingTests/RunnerTests.swift @@ -250,8 +250,8 @@ final class RunnerTests: XCTestCase { let testFunc = try #require(await testFunction(named: "duelingConditions()", in: NeverRunTests.self)) var configuration = Configuration() - let selection = Test.ID.Selection(testIDs: [testSuite.id]) - configuration.uncheckedTestFilter = makeTestFilter(matching: selection, includeHiddenTests: true) + let selection = [testSuite.id] + configuration.uncheckedTestFilter = makeTestFilter(matching: selection) let runner = await Runner(testing: [ testSuite, @@ -301,8 +301,7 @@ final class RunnerTests: XCTestCase { XCTAssertFalse(selectedTestIDs.isEmpty) var configuration = Configuration() - let selection = Test.ID.Selection(testIDs: selectedTestIDs) - configuration.uncheckedTestFilter = makeTestFilter(matching: selection, includeHiddenTests: true) + configuration.uncheckedTestFilter = makeTestFilter(matching: selectedTestIDs) let runner = await Runner(configuration: configuration) let plan = runner.plan @@ -326,7 +325,7 @@ final class RunnerTests: XCTestCase { ] var configuration1 = Configuration() - configuration1.testFilter = makeTestFilter(matching: .init(testIDs: selectedTestIDs), includeHiddenTests: false) + configuration1.testFilter = makeTestFilter(matching: selectedTestIDs) var configuration2 = Configuration() configuration2.testFilter = makeTestFilter(matching: selectedTestIDs) diff --git a/Tests/TestingTests/TestSupport/TestingAdditions.swift b/Tests/TestingTests/TestSupport/TestingAdditions.swift index 5a069bf12..71fa31457 100644 --- a/Tests/TestingTests/TestSupport/TestingAdditions.swift +++ b/Tests/TestingTests/TestSupport/TestingAdditions.swift @@ -67,8 +67,8 @@ func runTest(for containingType: Any.Type, configuration: Configuration = .init( /// If no test is found representing `containingType`, nothing is run. func runTestFunction(named name: String, in containingType: Any.Type, configuration: Configuration = .init()) async { var configuration = configuration - let selection = Test.ID.Selection(testIDs: [Test.ID(type: containingType).child(named: name)]) - configuration.uncheckedTestFilter = makeTestFilter(matching: selection, includeHiddenTests: true) + let selection = [Test.ID(type: containingType).child(named: name)] + configuration.uncheckedTestFilter = makeTestFilter(matching: selection) let runner = await Runner(configuration: configuration) await runner.run() @@ -91,8 +91,8 @@ extension Runner { let moduleName = String(fileID[..