Skip to content

Commit faa4700

Browse files
authored
Allow test filter to be passed multiple times (#2800)
1 parent 4ad7651 commit faa4700

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

Sources/Commands/SwiftTestTool.swift

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,11 +126,11 @@ public class TestToolOptions: ToolOptions {
126126
/// This is used to filter tests to run
127127
/// .none => No filtering
128128
/// .specific => Specify test with fully quantified name
129-
/// .regex => RegEx pattern
129+
/// .regex => RegEx patterns
130130
public enum TestCaseSpecifier {
131131
case none
132132
case specific(String)
133-
case regex(String)
133+
case regex([String])
134134
case skip([String])
135135
}
136136

@@ -415,7 +415,7 @@ public class SwiftTestTool: SwiftTool<TestToolOptions> {
415415
to: { $0.xUnitOutput = $1.path })
416416

417417
binder.bind(
418-
option: parser.add(option: "--filter", kind: String.self,
418+
option: parser.add(option: "--filter", kind: [String].self,
419419
usage: "Run test cases matching regular expression, Format: <test-target>.<test-case> or " +
420420
"<test-target>.<test-case>/<test>"),
421421
to: { $0._testCaseSpecifier = .regex($1) })
@@ -958,10 +958,12 @@ fileprivate extension Dictionary where Key == AbsolutePath, Value == [TestSuite]
958958
switch specifier {
959959
case .none:
960960
return allTests
961-
case .regex(let pattern):
961+
case .regex(let patterns):
962962
return allTests.filter({ test in
963-
test.specifier.range(of: pattern,
964-
options: .regularExpression) != nil
963+
patterns.contains { pattern in
964+
test.specifier.range(of: pattern,
965+
options: .regularExpression) != nil
966+
}
965967
})
966968
case .specific(let name):
967969
return allTests.filter{ $0.specifier == name }

Tests/FunctionalTests/MiscellaneousTests.swift

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,17 @@ class MiscellaneousTestCase: XCTestCase {
259259
func testSwiftTestFilter() throws {
260260
#if os(macOS)
261261
fixture(name: "Miscellaneous/ParallelTestsPkg") { prefix in
262-
let (_, stderr) = try SwiftPMProduct.SwiftTest.execute(["--filter", ".*1"], packagePath: prefix)
263-
XCTAssertMatch(stderr, .contains("testExample1"))
262+
let (stdout, _) = try SwiftPMProduct.SwiftTest.execute(["--filter", ".*1", "-l"], packagePath: prefix)
263+
XCTAssertMatch(stdout, .contains("testExample1"))
264+
XCTAssertNoMatch(stdout, .contains("testExample2"))
265+
XCTAssertNoMatch(stdout, .contains("testSureFailure"))
266+
}
267+
268+
fixture(name: "Miscellaneous/ParallelTestsPkg") { prefix in
269+
let (stdout, _) = try SwiftPMProduct.SwiftTest.execute(["--filter", ".*1", "--filter", "testSureFailure", "-l"], packagePath: prefix)
270+
XCTAssertMatch(stdout, .contains("testExample1"))
271+
XCTAssertNoMatch(stdout, .contains("testExample2"))
272+
XCTAssertMatch(stdout, .contains("testSureFailure"))
264273
}
265274
#endif
266275
}

0 commit comments

Comments
 (0)