@@ -119,12 +119,17 @@ macro_rules! define_benchmark {
119119
120120pub use define_benchmark;
121121
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.
123124pub fn passes_filter ( name : & str , exclude : Option < & str > , include : Option < & str > ) -> bool {
124125 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) ) ,
128133 ( None , None ) => true ,
129134 }
130135}
@@ -137,3 +142,41 @@ pub fn black_box<T>(dummy: T) -> T {
137142 ret
138143 }
139144}
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