Skip to content

Commit 3fa4ea0

Browse files
authored
Refine makeTestFilter() further. (#154)
* Refine `makeTestFilter()` further. This PR refines the previous PR for this issue, #153. It removes the internal overload of `makeTestFilter(matching:uncheckedTestFilter:)` because it is redundant: since the result needs to be passed to `uncheckedTestFilter` to preserve its lack of `isHidden`-checking, it doesn't _also_ need to impose its own check. I did add an internal overload of `makeTestFilter()` to the test target that just returns `selection.contains` as a convenience. Resolves rdar://119205417 (again.)
1 parent ced8b73 commit 3fa4ea0

File tree

5 files changed

+22
-42
lines changed

5 files changed

+22
-42
lines changed

Sources/Testing/Running/Configuration.swift

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -177,29 +177,10 @@ public struct Configuration: Sendable {
177177
/// - Parameters:
178178
/// - selection: A set of test IDs to be filtered.
179179
///
180-
/// By default, all tests are run and no filter is set.
180+
/// - Returns: A test filter that filters tests to those specified by
181+
/// `selection`.
181182
@_spi(ExperimentalTestRunning)
182183
public func makeTestFilter(matching selection: some Collection<Test.ID>) -> Configuration.TestFilter {
183184
let selection = Test.ID.Selection(testIDs: selection)
184-
return makeTestFilter(matching: selection, includeHiddenTests: false)
185+
return selection.contains
185186
}
186-
187-
/// Make a test filter that filters tests to those specified by a set of test
188-
/// IDs, optionally including or excluding hidden tests.
189-
///
190-
/// - Parameters:
191-
/// - selection: A selection of test IDs to be filtered.
192-
/// - includeHiddenTests: If false, a test annotated with the `.hidden`
193-
/// trait will not be included, even if its ID is present in `selection`.
194-
///
195-
/// By default, all tests are run and no filter is set.
196-
func makeTestFilter(matching selection: Test.ID.Selection, includeHiddenTests: Bool) -> Configuration.TestFilter {
197-
if includeHiddenTests {
198-
return selection.contains
199-
} else {
200-
return { test in
201-
!test.isHidden && selection.contains(test)
202-
}
203-
}
204-
}
205-

Tests/TestingTests/PlanTests.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ struct PlanTests {
2626
testB,
2727
]
2828

29-
let selection = Test.ID.Selection(testIDs: [innerTestType.id])
29+
let selection = [innerTestType.id]
3030
var configuration = Configuration()
31-
configuration.uncheckedTestFilter = makeTestFilter(matching: selection, includeHiddenTests: true)
31+
configuration.uncheckedTestFilter = makeTestFilter(matching: selection)
3232

3333
let plan = await Runner.Plan(tests: tests, configuration: configuration)
3434
#expect(plan.steps.contains(where: { $0.test == outerTestType }))
@@ -52,8 +52,8 @@ struct PlanTests {
5252
]
5353

5454
var configuration = Configuration()
55-
let selection = Test.ID.Selection(testIDs: [innerTestType.id, outerTestType.id])
56-
configuration.uncheckedTestFilter = makeTestFilter(matching: selection, includeHiddenTests: true)
55+
let selection = [innerTestType.id, outerTestType.id]
56+
configuration.uncheckedTestFilter = makeTestFilter(matching: selection)
5757

5858
let plan = await Runner.Plan(tests: tests, configuration: configuration)
5959
let planTests = plan.steps.map(\.test)
@@ -72,8 +72,8 @@ struct PlanTests {
7272
let tests = [outerTestType, deeplyNestedTest]
7373

7474
var configuration = Configuration()
75-
let selection = Test.ID.Selection(testIDs: [outerTestType.id, deeplyNestedTest.id])
76-
configuration.uncheckedTestFilter = makeTestFilter(matching: selection, includeHiddenTests: true)
75+
let selection = [outerTestType.id, deeplyNestedTest.id]
76+
configuration.uncheckedTestFilter = makeTestFilter(matching: selection)
7777

7878
let plan = await Runner.Plan(tests: tests, configuration: configuration)
7979

@@ -91,8 +91,8 @@ struct PlanTests {
9191
let tests = [testSuiteA, testSuiteB, testSuiteC, testFuncX]
9292

9393
var configuration = Configuration()
94-
let selection = Test.ID.Selection(testIDs: [testSuiteA.id])
95-
configuration.uncheckedTestFilter = makeTestFilter(matching: selection, includeHiddenTests: true)
94+
let selection = [testSuiteA.id]
95+
configuration.uncheckedTestFilter = makeTestFilter(matching: selection)
9696

9797
let plan = await Runner.Plan(tests: tests, configuration: configuration)
9898
let testFuncXWithTraits = try #require(plan.steps.map(\.test).first { $0.name == "x()" })

Tests/TestingTests/Runner.Plan.SnapshotTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct Runner_Plan_SnapshotTests {
2222
let suite = try #require(await test(for: Runner_Plan_SnapshotFixtures.self))
2323

2424
var configuration = Configuration()
25-
configuration.uncheckedTestFilter = makeTestFilter(matching: .init(testIDs: [suite.id]), includeHiddenTests: true)
25+
configuration.uncheckedTestFilter = makeTestFilter(matching: [suite.id])
2626

2727
let plan = await Runner.Plan(configuration: configuration)
2828
let snapshot = Runner.Plan.Snapshot(snapshotting: plan)

Tests/TestingTests/RunnerTests.swift

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,8 @@ final class RunnerTests: XCTestCase {
250250
let testFunc = try #require(await testFunction(named: "duelingConditions()", in: NeverRunTests.self))
251251

252252
var configuration = Configuration()
253-
let selection = Test.ID.Selection(testIDs: [testSuite.id])
254-
configuration.uncheckedTestFilter = makeTestFilter(matching: selection, includeHiddenTests: true)
253+
let selection = [testSuite.id]
254+
configuration.uncheckedTestFilter = makeTestFilter(matching: selection)
255255

256256
let runner = await Runner(testing: [
257257
testSuite,
@@ -301,8 +301,7 @@ final class RunnerTests: XCTestCase {
301301
XCTAssertFalse(selectedTestIDs.isEmpty)
302302

303303
var configuration = Configuration()
304-
let selection = Test.ID.Selection(testIDs: selectedTestIDs)
305-
configuration.uncheckedTestFilter = makeTestFilter(matching: selection, includeHiddenTests: true)
304+
configuration.uncheckedTestFilter = makeTestFilter(matching: selectedTestIDs)
306305

307306
let runner = await Runner(configuration: configuration)
308307
let plan = runner.plan
@@ -326,7 +325,7 @@ final class RunnerTests: XCTestCase {
326325
]
327326

328327
var configuration1 = Configuration()
329-
configuration1.testFilter = makeTestFilter(matching: .init(testIDs: selectedTestIDs), includeHiddenTests: false)
328+
configuration1.testFilter = makeTestFilter(matching: selectedTestIDs)
330329

331330
var configuration2 = Configuration()
332331
configuration2.testFilter = makeTestFilter(matching: selectedTestIDs)

Tests/TestingTests/TestSupport/TestingAdditions.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ func runTest(for containingType: Any.Type, configuration: Configuration = .init(
6767
/// If no test is found representing `containingType`, nothing is run.
6868
func runTestFunction(named name: String, in containingType: Any.Type, configuration: Configuration = .init()) async {
6969
var configuration = configuration
70-
let selection = Test.ID.Selection(testIDs: [Test.ID(type: containingType).child(named: name)])
71-
configuration.uncheckedTestFilter = makeTestFilter(matching: selection, includeHiddenTests: true)
70+
let selection = [Test.ID(type: containingType).child(named: name)]
71+
configuration.uncheckedTestFilter = makeTestFilter(matching: selection)
7272

7373
let runner = await Runner(configuration: configuration)
7474
await runner.run()
@@ -91,8 +91,8 @@ extension Runner {
9191
let moduleName = String(fileID[..<fileID.lastIndex(of: "/")!])
9292

9393
var configuration = configuration
94-
let selection = Test.ID.Selection(testIDs: [Test.ID(moduleName: moduleName, nameComponents: [testName], sourceLocation: nil)])
95-
configuration.uncheckedTestFilter = makeTestFilter(matching: selection, includeHiddenTests: true)
94+
let selection = [Test.ID(moduleName: moduleName, nameComponents: [testName], sourceLocation: nil)]
95+
configuration.uncheckedTestFilter = makeTestFilter(matching: selection)
9696

9797
await self.init(configuration: configuration)
9898
}
@@ -106,8 +106,8 @@ extension Runner.Plan {
106106
/// - configuration: The configuration to use for planning.
107107
init(selecting containingType: Any.Type, configuration: Configuration = .init()) async {
108108
var configuration = configuration
109-
let selection = Test.ID.Selection(testIDs: [Test.ID(type: containingType)])
110-
configuration.uncheckedTestFilter = makeTestFilter(matching: selection, includeHiddenTests: true)
109+
let selection = [Test.ID(type: containingType)]
110+
configuration.uncheckedTestFilter = makeTestFilter(matching: selection)
111111

112112
await self.init(configuration: configuration)
113113
}

0 commit comments

Comments
 (0)