@@ -81,6 +81,16 @@ struct TestConfig {
81
81
82
82
filters = benchArgs. positionalArgs
83
83
84
+ func checked< T> (
85
+ _ parse: ( String ) throws -> T ? ,
86
+ _ value: String ,
87
+ argument: String ? = nil
88
+ ) throws -> T {
89
+ if let t = try parse ( value) { return t }
90
+ throw ArgumentError . invalidType (
91
+ value: value, type: " \( T . self) " , argument: argument)
92
+ }
93
+
84
94
func optionalArg< T> (
85
95
_ name: String ,
86
96
_ property: WritableKeyPath < TestConfig , T > ,
@@ -90,28 +100,20 @@ struct TestConfig {
90
100
if let value = benchArgs. optionalArgsMap [ name] {
91
101
guard !value. isEmpty || defaultValue != nil
92
102
else { throw ArgumentError . missingValue ( name) }
93
- guard let typedValue = ( value. isEmpty) ? defaultValue
94
- : try parse ( value) else {
95
- throw ArgumentError . invalidType (
96
- value: value, type: String ( describing: T . self) , argument: name)
97
- }
98
- self [ keyPath: property] = typedValue
99
- }
100
- }
101
103
102
- func tag( tag: String ) throws -> BenchmarkCategory {
103
- guard let category = BenchmarkCategory ( rawValue: tag) else {
104
- throw ArgumentError . invalidType (
105
- value: tag, type: " BenchmarkCategory " , argument: nil )
104
+ self [ keyPath: property] = ( value. isEmpty)
105
+ ? defaultValue!
106
+ : try checked ( parse, value, argument: name)
106
107
}
107
- return category
108
108
}
109
+
109
110
func tags( tags: String ) throws -> Set < BenchmarkCategory > {
110
111
// We support specifying multiple tags by splitting on comma, i.e.:
111
112
// --tags=Array,Dictionary
112
113
// --skip-tags=Array,Set,unstable,skip
113
114
return Set (
114
- try tags. split ( separator: " , " ) . map ( String . init) . map ( tag) )
115
+ try tags. split ( separator: " , " ) . map ( String . init) . map {
116
+ try checked ( { BenchmarkCategory ( rawValue: $0) } , $0) } )
115
117
}
116
118
117
119
try optionalArg ( " --iter-scale " , \. iterationScale) { Int ( $0) }
0 commit comments