@@ -119,12 +119,17 @@ macro_rules! define_benchmark {
119
119
120
120
pub use define_benchmark;
121
121
122
- /// Tests if the name of the benchmark passes through the include and exclude filter flags.
122
+ /// Tests if the name of the benchmark passes through the include and exclude filters.
123
+ /// Both filters can contain multiple comma-separated prefixes.
123
124
pub fn passes_filter ( name : & str , exclude : Option < & str > , include : Option < & str > ) -> bool {
124
125
match ( exclude, include) {
125
- ( Some ( exclude) , Some ( include) ) => name. starts_with ( include) && !name. starts_with ( exclude) ,
126
- ( None , Some ( include) ) => name. starts_with ( include) ,
127
- ( Some ( exclude) , None ) => !name. starts_with ( & exclude) ,
126
+ ( Some ( exclude) , Some ( include) ) => {
127
+ let included = include. split ( "," ) . any ( |filter| name. starts_with ( filter) ) ;
128
+ let excluded = exclude. split ( "," ) . any ( |filter| name. starts_with ( filter) ) ;
129
+ included && !excluded
130
+ }
131
+ ( None , Some ( include) ) => include. split ( "," ) . any ( |filter| name. starts_with ( filter) ) ,
132
+ ( Some ( exclude) , None ) => !exclude. split ( "," ) . any ( |filter| name. starts_with ( filter) ) ,
128
133
( None , None ) => true ,
129
134
}
130
135
}
@@ -137,3 +142,41 @@ pub fn black_box<T>(dummy: T) -> T {
137
142
ret
138
143
}
139
144
}
145
+
146
+ #[ cfg( test) ]
147
+ mod tests {
148
+ use crate :: benchmark:: passes_filter;
149
+
150
+ #[ test]
151
+ fn test_passes_filter_no_filter ( ) {
152
+ assert ! ( passes_filter( "foo" , None , None ) ) ;
153
+ }
154
+
155
+ #[ test]
156
+ fn test_passes_filter_include ( ) {
157
+ assert ! ( !passes_filter( "foo" , None , Some ( "bar" ) ) ) ;
158
+ assert ! ( !passes_filter( "foo" , None , Some ( "foobar" ) ) ) ;
159
+
160
+ assert ! ( passes_filter( "foo" , None , Some ( "f" ) ) ) ;
161
+ assert ! ( passes_filter( "foo" , None , Some ( "foo" ) ) ) ;
162
+ assert ! ( passes_filter( "foo" , None , Some ( "bar,baz,foo" ) ) ) ;
163
+ }
164
+
165
+ #[ test]
166
+ fn test_passes_filter_exclude ( ) {
167
+ assert ! ( passes_filter( "foo" , Some ( "bar" ) , None ) ) ;
168
+ assert ! ( passes_filter( "foo" , Some ( "foobar" ) , None ) ) ;
169
+
170
+ assert ! ( !passes_filter( "foo" , Some ( "f" ) , None ) ) ;
171
+ assert ! ( !passes_filter( "foo" , Some ( "foo" ) , None ) ) ;
172
+ assert ! ( !passes_filter( "foo" , Some ( "bar,baz,foo" ) , None ) ) ;
173
+ }
174
+
175
+ #[ test]
176
+ fn test_passes_filter_include_exclude ( ) {
177
+ assert ! ( !passes_filter( "foo" , Some ( "bar" ) , Some ( "baz" ) ) ) ;
178
+ assert ! ( passes_filter( "foo" , Some ( "bar" ) , Some ( "foo" ) ) ) ;
179
+ assert ! ( !passes_filter( "foo" , Some ( "foo" ) , Some ( "bar" ) ) ) ;
180
+ assert ! ( !passes_filter( "foo" , Some ( "foo" ) , Some ( "foo" ) ) ) ;
181
+ }
182
+ }
0 commit comments