1
1
using System . Linq ;
2
+ using System . Threading ;
3
+ using ApprovalUtilities . Utilities ;
2
4
using BenchmarkDotNet . Attributes ;
3
5
using BenchmarkDotNet . Filters ;
4
6
using BenchmarkDotNet . Running ;
@@ -27,9 +29,38 @@ public void TheFilterIsCaseInsensitive(string pattern, bool expected)
27
29
Assert . Equal ( expected , filter . Predicate ( benchmarkCase ) ) ;
28
30
}
29
31
30
- public class TypeWithBenchmarks
32
+ [ Theory ]
33
+ [ InlineData ( nameof ( TypeWithBenchmarksAndParams ) , 0 ) ] // type name
34
+ [ InlineData ( "typewithbenchmarksandparams" , 0 ) ] // type name lowercase
35
+ [ InlineData ( "TYPEWITHBENCHMARKSANDPARAMS" , 0 ) ] // type name uppercase
36
+ [ InlineData ( "*TypeWithBenchmarksAndParams*" , 2 ) ] // regular expression
37
+ [ InlineData ( "*typewithbenchmarksandparams*" , 2 ) ] // regular expression lowercase
38
+ [ InlineData ( "*TYPEWITHBENCHMARKSANDPARAMS*" , 2 ) ] // regular expression uppercase
39
+ [ InlineData ( "*" , 2 ) ]
40
+ [ InlineData ( "WRONG" , 0 ) ]
41
+ [ InlineData ( "*stillWRONG*" , 0 ) ]
42
+ [ InlineData ( "BenchmarkDotNet.Tests.TypeWithBenchmarksAndParams.TheBenchmark" , 2 ) ]
43
+ [ InlineData ( "BenchmarkDotNet.Tests.TypeWithBenchmarksAndParams.TheBenchmark(A: 100)" , 1 ) ]
44
+ public void TheFilterWorksWithParams ( string pattern , int expectedBenchmarks )
31
45
{
32
- [ Benchmark ] public void TheBenchmark ( ) { }
46
+ var benchmarkCases = BenchmarkConverter . TypeToBenchmarks ( typeof ( TypeWithBenchmarksAndParams ) ) . BenchmarksCases ;
47
+
48
+ var filter = new GlobFilter ( new [ ] { pattern } ) ;
49
+
50
+ Assert . Equal ( expectedBenchmarks , benchmarkCases . Where ( benchmarkCase => filter . Predicate ( benchmarkCase ) ) . Count ( ) ) ;
33
51
}
34
52
}
53
+
54
+ public class TypeWithBenchmarks
55
+ {
56
+ [ Benchmark ] public void TheBenchmark ( ) { }
57
+ }
58
+
59
+ public class TypeWithBenchmarksAndParams
60
+ {
61
+ [ Params ( 100 , 200 ) ]
62
+ public int A { get ; set ; }
63
+
64
+ [ Benchmark ] public void TheBenchmark ( ) { }
65
+ }
35
66
}
0 commit comments