@@ -53,13 +53,7 @@ struct Test {
53
53
let name : String
54
54
let index : Int
55
55
let f : ( Int ) -> ( )
56
- var run : Bool
57
- init ( name: String , n: Int , f: @escaping ( Int ) -> ( ) ) {
58
- self . name = name
59
- self . index = n
60
- self . f = f
61
- run = true
62
- }
56
+ let run : Bool
63
57
}
64
58
65
59
public var precommitTests : [ String : ( Int ) -> ( ) ] = [ : ]
@@ -117,9 +111,7 @@ struct TestConfig {
117
111
}
118
112
let benchArgs = maybeBenchArgs!
119
113
120
- if let _ = benchArgs. optionalArgsMap [ " --list " ] {
121
- return . ListTests
122
- }
114
+ filters = benchArgs. positionalArgs
123
115
124
116
if let x = benchArgs. optionalArgsMap [ " --iter-scale " ] {
125
117
if x. isEmpty { return . Fail( " --iter-scale requires a value " ) }
@@ -161,34 +153,30 @@ struct TestConfig {
161
153
afterRunSleep = v!
162
154
}
163
155
164
- filters = benchArgs. positionalArgs
156
+ if let _ = benchArgs. optionalArgsMap [ " --list " ] {
157
+ return . ListTests
158
+ }
165
159
166
160
return . Run
167
161
}
168
162
169
163
mutating func findTestsToRun( ) {
170
- var i = 1
171
- for benchName in precommitTests. keys. sorted ( ) {
172
- tests. append ( Test ( name: benchName, n: i, f: precommitTests [ benchName] !) )
173
- i += 1
174
- }
175
- for benchName in otherTests. keys. sorted ( ) {
176
- tests. append ( Test ( name: benchName, n: i, f: otherTests [ benchName] !) )
177
- i += 1
178
- }
179
- for benchName in stringTests. keys. sorted ( ) {
180
- tests. append ( Test ( name: benchName, n: i, f: stringTests [ benchName] !) )
181
- i += 1
182
- }
183
- for i in 0 ..< tests. count {
184
- if onlyPrecommit && precommitTests [ tests [ i] . name] == nil {
185
- tests [ i] . run = false
186
- }
187
- if !filters. isEmpty &&
188
- !filters. contains ( String ( tests [ i] . index) ) &&
189
- !filters. contains ( tests [ i] . name) {
190
- tests [ i] . run = false
191
- }
164
+ let allTests = [ precommitTests, otherTests, stringTests]
165
+ . map { dictionary -> [ ( key: String , value: ( Int ) -> ( ) ) ] in
166
+ Array ( dictionary) . sorted { $0. key < $1. key } } // by name
167
+ . joined ( )
168
+
169
+ let included =
170
+ !filters. isEmpty ? Set ( filters)
171
+ : onlyPrecommit ? Set ( precommitTests. keys)
172
+ : Set ( allTests. map { $0. key } )
173
+
174
+ tests = zip ( 1 ... allTests. count, allTests) . map {
175
+ t -> Test in
176
+ let ( ordinal, ( key: name, value: function) ) = t
177
+ return Test ( name: name, index: ordinal, f: function,
178
+ run: included. contains ( name)
179
+ || included. contains ( String ( ordinal) ) )
192
180
}
193
181
}
194
182
}
@@ -410,7 +398,7 @@ public func main() {
410
398
case . ListTests:
411
399
config. findTestsToRun ( )
412
400
print ( " Enabled Tests: " )
413
- for t in config. tests {
401
+ for t in config. tests where t . run == true {
414
402
print ( " \( t. name) " )
415
403
}
416
404
case . Run:
0 commit comments