@@ -83,9 +83,7 @@ impl<'a> BenchmarkGroup<'a> {
83
83
let mut items: Vec < ( & ' static str , BenchmarkProfileFns ) > = self
84
84
. benchmarks
85
85
. into_iter ( )
86
- . filter ( |( name, _) | {
87
- passes_filter ( name, args. exclude . as_deref ( ) , args. include . as_deref ( ) )
88
- } )
86
+ . filter ( |( name, _) | passes_filter ( name, & args. exclude , & args. include ) )
89
87
. collect ( ) ;
90
88
items. sort_unstable_by_key ( |item| item. 0 ) ;
91
89
@@ -144,16 +142,21 @@ impl<'a> BenchmarkGroup<'a> {
144
142
145
143
/// Tests if the name of the benchmark passes through the include and exclude filters.
146
144
/// Both filters can contain multiple comma-separated prefixes.
147
- pub fn passes_filter ( name : & str , exclude : Option < & str > , include : Option < & str > ) -> bool {
145
+ pub fn passes_filter ( name : & str , exclude : & [ String ] , include : & [ String ] ) -> bool {
148
146
match ( exclude, include) {
149
- ( Some ( exclude) , Some ( include) ) => {
150
- let included = include. split ( ',' ) . any ( |filter| name. starts_with ( filter) ) ;
151
- let excluded = exclude. split ( ',' ) . any ( |filter| name. starts_with ( filter) ) ;
147
+ ( exclude, include) if !exclude . is_empty ( ) && !include . is_empty ( ) => {
148
+ let included = include. iter ( ) . any ( |filter| name. starts_with ( filter) ) ;
149
+ let excluded = exclude. iter ( ) . any ( |filter| name. starts_with ( filter) ) ;
152
150
included && !excluded
153
151
}
154
- ( None , Some ( include) ) => include. split ( ',' ) . any ( |filter| name. starts_with ( filter) ) ,
155
- ( Some ( exclude) , None ) => !exclude. split ( ',' ) . any ( |filter| name. starts_with ( filter) ) ,
156
- ( None , None ) => true ,
152
+ ( [ ] , include) if !include. is_empty ( ) => {
153
+ include. iter ( ) . any ( |filter| name. starts_with ( filter) )
154
+ }
155
+ ( exclude, [ ] ) if !exclude. is_empty ( ) => {
156
+ !exclude. iter ( ) . any ( |filter| name. starts_with ( filter) )
157
+ }
158
+ ( [ ] , [ ] ) => true ,
159
+ ( _, _) => unreachable ! ( ) ,
157
160
}
158
161
}
159
162
@@ -172,34 +175,58 @@ mod tests {
172
175
173
176
#[ test]
174
177
fn test_passes_filter_no_filter ( ) {
175
- assert ! ( passes_filter( "foo" , None , None ) ) ;
178
+ assert ! ( passes_filter( "foo" , & [ ] , & [ ] ) ) ;
176
179
}
177
180
178
181
#[ test]
179
182
fn test_passes_filter_include ( ) {
180
- assert ! ( !passes_filter( "foo" , None , Some ( "bar" ) ) ) ;
181
- assert ! ( !passes_filter( "foo" , None , Some ( "foobar" ) ) ) ;
182
-
183
- assert ! ( passes_filter( "foo" , None , Some ( "f" ) ) ) ;
184
- assert ! ( passes_filter( "foo" , None , Some ( "foo" ) ) ) ;
185
- assert ! ( passes_filter( "foo" , None , Some ( "bar,baz,foo" ) ) ) ;
183
+ assert ! ( !passes_filter( "foo" , & [ ] , & [ "bar" . to_string( ) ] ) ) ;
184
+ assert ! ( !passes_filter( "foo" , & [ ] , & [ "foobar" . to_string( ) ] ) ) ;
185
+
186
+ assert ! ( passes_filter( "foo" , & [ ] , & [ "f" . to_string( ) ] ) ) ;
187
+ assert ! ( passes_filter( "foo" , & [ ] , & [ "foo" . to_string( ) ] ) ) ;
188
+ assert ! ( passes_filter(
189
+ "foo" ,
190
+ & [ ] ,
191
+ & [ "bar" . to_string( ) , "baz" . to_string( ) , "foo" . to_string( ) ]
192
+ ) ) ;
186
193
}
187
194
188
195
#[ test]
189
196
fn test_passes_filter_exclude ( ) {
190
- assert ! ( passes_filter( "foo" , Some ( "bar" ) , None ) ) ;
191
- assert ! ( passes_filter( "foo" , Some ( "foobar" ) , None ) ) ;
192
-
193
- assert ! ( !passes_filter( "foo" , Some ( "f" ) , None ) ) ;
194
- assert ! ( !passes_filter( "foo" , Some ( "foo" ) , None ) ) ;
195
- assert ! ( !passes_filter( "foo" , Some ( "bar,baz,foo" ) , None ) ) ;
197
+ assert ! ( passes_filter( "foo" , & [ "bar" . to_string( ) ] , & [ ] ) ) ;
198
+ assert ! ( passes_filter( "foo" , & [ "foobar" . to_string( ) ] , & [ ] ) ) ;
199
+
200
+ assert ! ( !passes_filter( "foo" , & [ "f" . to_string( ) ] , & [ ] ) ) ;
201
+ assert ! ( !passes_filter( "foo" , & [ "foo" . to_string( ) ] , & [ ] ) ) ;
202
+ assert ! ( !passes_filter(
203
+ "foo" ,
204
+ & [ "bar" . to_string( ) , "baz" . to_string( ) , "foo" . to_string( ) ] ,
205
+ & [ ]
206
+ ) ) ;
196
207
}
197
208
198
209
#[ test]
199
210
fn test_passes_filter_include_exclude ( ) {
200
- assert ! ( !passes_filter( "foo" , Some ( "bar" ) , Some ( "baz" ) ) ) ;
201
- assert ! ( passes_filter( "foo" , Some ( "bar" ) , Some ( "foo" ) ) ) ;
202
- assert ! ( !passes_filter( "foo" , Some ( "foo" ) , Some ( "bar" ) ) ) ;
203
- assert ! ( !passes_filter( "foo" , Some ( "foo" ) , Some ( "foo" ) ) ) ;
211
+ assert ! ( !passes_filter(
212
+ "foo" ,
213
+ & [ "bar" . to_string( ) ] ,
214
+ & [ "baz" . to_string( ) ]
215
+ ) ) ;
216
+ assert ! ( passes_filter(
217
+ "foo" ,
218
+ & [ "bar" . to_string( ) ] ,
219
+ & [ "foo" . to_string( ) ]
220
+ ) ) ;
221
+ assert ! ( !passes_filter(
222
+ "foo" ,
223
+ & [ "foo" . to_string( ) ] ,
224
+ & [ "bar" . to_string( ) ]
225
+ ) ) ;
226
+ assert ! ( !passes_filter(
227
+ "foo" ,
228
+ & [ "foo" . to_string( ) ] ,
229
+ & [ "foo" . to_string( ) ]
230
+ ) ) ;
204
231
}
205
232
}
0 commit comments