@@ -56,13 +56,18 @@ class TestRunner {
56
56
/// The message to print if all the tests passed.
57
57
let successMessage : String
58
58
59
+ /// The set of filters to run over the file names, to refine which tests
60
+ /// are run.
61
+ let filters : [ NSRegularExpression ]
62
+
59
63
/// Creates a test runner that will execute all tests in the provided
60
64
/// directory.
61
65
/// - throws: A LiteError if the test directory is invalid.
62
66
init ( testDirPath: String ? , substitutions: [ ( String , String ) ] ,
63
67
pathExtensions: Set < String > , testLinePrefix: String ,
64
68
parallelismLevel: ParallelismLevel ,
65
- successMessage: String ) throws {
69
+ successMessage: String ,
70
+ filters: [ NSRegularExpression ] ) throws {
66
71
let fm = FileManager . default
67
72
var isDir : ObjCBool = false
68
73
let testDirPath =
@@ -79,6 +84,7 @@ class TestRunner {
79
84
self . testLinePrefix = testLinePrefix
80
85
self . parallelismLevel = parallelismLevel
81
86
self . successMessage = successMessage
87
+ self . filters = filters
82
88
}
83
89
84
90
func discoverTests( ) throws -> [ TestFile ] {
@@ -88,6 +94,14 @@ class TestRunner {
88
94
var files = [ TestFile] ( )
89
95
for case let file as URL in enumerator {
90
96
guard pathExtensions. contains ( file. pathExtension) else { continue }
97
+ let nsPath = NSString ( string: file. path)
98
+ let matchesFilter = filters. contains {
99
+ return $0. numberOfMatches (
100
+ in: file. path,
101
+ range: NSRange ( location: 0 , length: nsPath. length)
102
+ ) != 0
103
+ }
104
+ guard filters. isEmpty || matchesFilter else { continue }
91
105
let runLines = try RunLineParser . parseRunLines ( in: file,
92
106
prefix: testLinePrefix)
93
107
if runLines. isEmpty { continue }
0 commit comments