@@ -56,13 +56,18 @@ class TestRunner {
5656 /// The message to print if all the tests passed.
5757 let successMessage : String
5858
59+ /// The set of filters to run over the file names, to refine which tests
60+ /// are run.
61+ let filters : [ NSRegularExpression ]
62+
5963 /// Creates a test runner that will execute all tests in the provided
6064 /// directory.
6165 /// - throws: A LiteError if the test directory is invalid.
6266 init ( testDirPath: String ? , substitutions: [ ( String , String ) ] ,
6367 pathExtensions: Set < String > , testLinePrefix: String ,
6468 parallelismLevel: ParallelismLevel ,
65- successMessage: String ) throws {
69+ successMessage: String ,
70+ filters: [ NSRegularExpression ] ) throws {
6671 let fm = FileManager . default
6772 var isDir : ObjCBool = false
6873 let testDirPath =
@@ -79,6 +84,7 @@ class TestRunner {
7984 self . testLinePrefix = testLinePrefix
8085 self . parallelismLevel = parallelismLevel
8186 self . successMessage = successMessage
87+ self . filters = filters
8288 }
8389
8490 func discoverTests( ) throws -> [ TestFile ] {
@@ -88,6 +94,14 @@ class TestRunner {
8894 var files = [ TestFile] ( )
8995 for case let file as URL in enumerator {
9096 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 }
91105 let runLines = try RunLineParser . parseRunLines ( in: file,
92106 prefix: testLinePrefix)
93107 if runLines. isEmpty { continue }
0 commit comments