@@ -69,7 +69,7 @@ struct TestConfig {
69
69
var fixedNumIters : UInt ?
70
70
var verbose : Bool ?
71
71
var action : TestAction ?
72
- var filters : [ String ] ?
72
+ var tests : [ String ] ?
73
73
}
74
74
var c = PartialTestConfig ( )
75
75
@@ -98,19 +98,21 @@ struct TestConfig {
98
98
value: value, type: type, argument: argument)
99
99
}
100
100
101
- func optionalArg < T> (
102
- _ name: String ,
101
+ func parseArg < T> (
102
+ _ name: String ? ,
103
103
_ property: WritableKeyPath < PartialTestConfig , T > ,
104
104
defaultValue: T ? = nil ,
105
105
parser parse: ( String ) throws -> T ? = { _ in nil }
106
106
) throws {
107
- if let value = benchArgs. optionalArgsMap [ name] {
107
+ if let name = name , let value = benchArgs. optionalArgsMap [ name] {
108
108
guard !value. isEmpty || defaultValue != nil
109
109
else { throw ArgumentError . missingValue ( name) }
110
110
111
111
c [ keyPath: property] = ( value. isEmpty)
112
112
? defaultValue!
113
113
: try checked ( parse, value, argument: name)
114
+ } else if name == nil {
115
+ c [ keyPath: property] = benchArgs. positionalArgs as! T
114
116
}
115
117
}
116
118
@@ -124,19 +126,18 @@ struct TestConfig {
124
126
}
125
127
126
128
// Parse command line arguments
127
- try optionalArg ( " --iter-scale " , \. iterationScale) { Int ( $0) }
128
- try optionalArg ( " --num-iters " , \. fixedNumIters) { UInt ( $0) }
129
- try optionalArg ( " --num-samples " , \. numSamples) { Int ( $0) }
130
- try optionalArg ( " --verbose " , \. verbose, defaultValue: true )
131
- try optionalArg ( " --delim " , \. delim) { $0 }
132
- try optionalArg ( " --tags " , \PartialTestConfig . tags, parser: tags)
133
- try optionalArg ( " --skip-tags " , \PartialTestConfig . skipTags,
129
+ try parseArg ( " --iter-scale " , \. iterationScale) { Int ( $0) }
130
+ try parseArg ( " --num-iters " , \. fixedNumIters) { UInt ( $0) }
131
+ try parseArg ( " --num-samples " , \. numSamples) { Int ( $0) }
132
+ try parseArg ( " --verbose " , \. verbose, defaultValue: true )
133
+ try parseArg ( " --delim " , \. delim) { $0 }
134
+ try parseArg ( " --tags " , \PartialTestConfig . tags, parser: tags)
135
+ try parseArg ( " --skip-tags " , \PartialTestConfig . skipTags,
134
136
defaultValue: [ ] , parser: tags)
135
- try optionalArg ( " --sleep " , \. afterRunSleep) { Int ( $0) }
136
- try optionalArg ( " --list " , \. action, defaultValue: . listTests)
137
- try optionalArg ( " --help " , \. action, defaultValue: . help( validOptions) )
138
-
139
- c. filters = benchArgs. positionalArgs
137
+ try parseArg ( " --sleep " , \. afterRunSleep) { Int ( $0) }
138
+ try parseArg ( " --list " , \. action, defaultValue: . listTests)
139
+ try parseArg ( " --help " , \. action, defaultValue: . help( validOptions) )
140
+ try parseArg ( nil , \. tests) // positional arguments
140
141
141
142
// Configure from the command line arguments, filling in the defaults.
142
143
delim = c. delim ?? " , "
@@ -147,7 +148,7 @@ struct TestConfig {
147
148
afterRunSleep = c. afterRunSleep
148
149
action = c. action ?? . run
149
150
tests = TestConfig . filterTests ( registeredBenchmarks,
150
- filters : c . filters ?? [ ] ,
151
+ specifiedTests : Set ( c . tests ?? [ ] ) ,
151
152
tags: c. tags ?? [ ] ,
152
153
skipTags: c. skipTags ?? [ . unstable, . skip] )
153
154
@@ -159,7 +160,7 @@ struct TestConfig {
159
160
Verbose: \( verbose)
160
161
IterScale: \( iterationScale)
161
162
FixedIters: \( fixedNumIters)
162
- Tests Filter: \( c. filters ?? [ ] )
163
+ Tests Filter: \( c. tests ?? [ ] )
163
164
Tests to run: \( testList)
164
165
165
166
--- DATA --- \n
@@ -171,22 +172,21 @@ struct TestConfig {
171
172
///
172
173
/// - Parameters:
173
174
/// - registeredBenchmarks: List of all performance tests to be filtered.
174
- /// - filters : List of explicitly specified tests to run. These can be
175
+ /// - specifiedTests : List of explicitly specified tests to run. These can be
175
176
/// specified either by a test name or a test number.
176
177
/// - tags: Run tests tagged with all of these categories.
177
178
/// - skipTags: Don't run tests tagged with any of these categories.
178
179
/// - Returns: An array of test number and benchmark info tuples satisfying
179
180
/// specified filtering conditions.
180
181
static func filterTests(
181
182
_ registeredBenchmarks: [ BenchmarkInfo ] ,
182
- filters : [ String ] ,
183
+ specifiedTests : Set < String > ,
183
184
tags: Set < BenchmarkCategory > ,
184
185
skipTags: Set < BenchmarkCategory >
185
186
) -> [ ( index: String , info: BenchmarkInfo ) ] {
186
187
let indices = Dictionary ( uniqueKeysWithValues:
187
188
zip ( registeredBenchmarks. sorted ( ) . map { $0. name } ,
188
189
( 1 ... ) . lazy. map { String ( $0) } ) )
189
- let specifiedTests = Set ( filters)
190
190
191
191
func byTags( b: BenchmarkInfo ) -> Bool {
192
192
return b. tags. isSuperset ( of: tags) &&
@@ -197,7 +197,7 @@ struct TestConfig {
197
197
specifiedTests. contains ( indices [ b. name] !)
198
198
} // !! "All registeredBenchmarks have been assigned an index"
199
199
return registeredBenchmarks
200
- . filter ( filters . isEmpty ? byTags : byNamesOrIndices)
200
+ . filter ( specifiedTests . isEmpty ? byTags : byNamesOrIndices)
201
201
. map { ( index: indices [ $0. name] !, info: $0) }
202
202
}
203
203
}
0 commit comments