public void CanSelectClassesWithFullName()
        {
            var types = new[] { typeof(ClassA), typeof(ClassB), typeof(ClassC) };
            var typeParser = new TypeParser(types, ConsoleLogger.Default);

            var matches = typeParser.MatchingTypesWithMethods(new[] { "class=BenchmarkDotNet.Tests.ClassC,BenchmarkDotNet.Tests.ClassA" });

            // ClassC not matched as it has NO methods with the [Benchmark] attribute
            Assert.Equal(1, matches.Count());
            Assert.Equal(1, matches.Count(match => match.Type.Name == "ClassA" && match.AllMethodsInType));
        }
        public void CanSelectNamespaces()
        {
            var types = new[] { typeof(ClassA), typeof(ClassB), typeof(ClassC), typeof(NOTTests.ClassD) };
            var typeParser = new TypeParser(types, ConsoleLogger.Default);

            var matches = typeParser.MatchingTypesWithMethods(new[] { "namespace=BenchmarkDotNet.Tests" });

            Assert.Equal(2, matches.Count());
            Assert.Equal(1, matches.Count(match => match.Type.Name == "ClassA" && match.AllMethodsInType));
            Assert.Equal(1, matches.Count(match => match.Type.Name == "ClassB" && match.AllMethodsInType));
        }
        public void CanSelectAttributes()
        {
            var types = new[] { typeof(ClassA), typeof(ClassB), typeof(ClassC), typeof(NOTTests.ClassD) };
            var typeParser = new TypeParser(types, ConsoleLogger.Default);

            var matches = typeParser.MatchingTypesWithMethods(new[] { "attribute=Run" });

            // Find entire classes or individual methods that have the [Run] attribute
            Assert.Equal(2, matches.Count());
            Assert.Equal(1, matches.Count(match => match.Type.Name == "ClassA" && match.AllMethodsInType));
            Assert.Equal(1, matches.Count(match => match.Type.Name == "ClassD" &&
                                                   match.Methods.Any(m => m.Name == "Method1")));
        }
        public void CanSelectClasses()
        {
            var types = new[] { typeof(ClassA), typeof(ClassB), typeof(ClassC) };
            var typeParser = new TypeParser(types, ConsoleLogger.Default);

            var matches = typeParser.MatchingTypesWithMethods(new[] { "class=ClassC,ClassA" });
            // TODO do we want to allow "class = ClassC, ClassA" aswell as "class=ClassC,ClassA"
            //var matches = typeParser.MatchingTypesWithMethods(new[] { "class = ClassC, ClassA" });

            // ClassC not matched as it has NO methods with the [Benchmark] attribute
            Assert.Equal(1, matches.Count());
            Assert.Equal(1, matches.Count(match => match.Type.Name == "ClassA" && match.AllMethodsInType));
        }
        public void CanSelectMethodsWithFullName()
        {
            var types = new[] { typeof(ClassA), typeof(ClassB), typeof(ClassC) };
            var typeParser = new TypeParser(types, ConsoleLogger.Default);

            var matches = typeParser.MatchingTypesWithMethods(new[] { "method=BenchmarkDotNet.Tests.ClassA.Method2,BenchmarkDotNet.Tests.ClassB.Method3" });

            Assert.Equal(2, matches.Count());
            Assert.Equal(1, matches.Count(match => match.Type.Name == "ClassA" &&
                                                   match.Methods.Any(m => m.Name == "Method2")));
            Assert.Equal(1, matches.Count(match => match.Type.Name == "ClassB" &&
                                                   match.Methods.Any(m => m.Name == "Method3")));
        }
 public BenchmarkSwitcher(Assembly assembly)
 {
     // Use reflection for a more maintainable way of creating the benchmark switcher,
     // Benchmarks are listed in namespace order first (e.g. BenchmarkDotNet.Samples.CPU,
     // BenchmarkDotNet.Samples.IL, etc) then by name, so the output is easy to understand.
     var types = assembly
         .GetTypes()
         .Where(t => t.GetMethods(BindingFlags.Instance | BindingFlags.Public)
                      .Any(m => m.GetCustomAttributes(true).OfType<BenchmarkAttribute>().Any()))
         .Where(t => !t.GetTypeInfo().IsGenericType)
         .OrderBy(t => t.Namespace)
         .ThenBy(t => t.Name)
         .ToArray();
     typeParser = new TypeParser(types, logger);
 }
        public void CanSelectPluralVersions()
        {
            var types = new[] { typeof(ClassA), typeof(ClassB), typeof(ClassC), typeof(NOTTests.ClassD) };
            var typeParser = new TypeParser(types, ConsoleLogger.Default);

            // Note we are using "classes" here rather than "class" (we want to be nicer to our users!!)
            // Likewise you can also use "methods" and "namespaces"
            var matches = typeParser.MatchingTypesWithMethods(new[] { "classes=ClassC,ClassA", "methods=Method2" });

            // ClassC not matched as it has NO methods with the [Benchmark] attribute
            Assert.Equal(3, matches.Count());
            Assert.Equal(1, matches.Count(match => match.Type.Name == "ClassA" && match.AllMethodsInType));
            Assert.Equal(1, matches.Count(match => match.Type.Name == "ClassB" && match.Methods.Any(m => m.Name == "Method2")));
            Assert.Equal(1, matches.Count(match => match.Type.Name == "ClassD" && match.Methods.Any(m => m.Name == "Method2")));
        }
示例#8
0
 public BenchmarkSwitcher(Type[] types)
 {
     typeParser = new TypeParser(types, logger);
 }
        public void EntireClassOverridesIndividualMethods()
        {
            var types = new[] { typeof(ClassA), typeof(ClassB), typeof(ClassC) };
            var typeParser = new TypeParser(types, ConsoleLogger.Default);

            var matches = typeParser.MatchingTypesWithMethods(new[] { "method=Method2,Method3", "class=ClassA" });

            Assert.Equal(2, matches.Count());
            Assert.Equal(1, matches.Count(match => match.Type.Name == "ClassA" && match.AllMethodsInType));
            Assert.Equal(1, matches.Count(match => match.Type.Name == "ClassB" &&
                                                   match.Methods.Any(m => m.Name == "Method2") &&
                                                   match.Methods.Any(m => m.Name == "Method3")));
        }
示例#10
0
 public BenchmarkSwitcher(Assembly assembly)
 {
     typeParser = new TypeParser(assembly.GetRunnableBenchmarks(), logger);
 }
示例#11
0
        [PublicAPI] public BenchmarkSwitcher(Assembly[] assemblies)
        {
            var runnableBenchmarkTypes = assemblies.SelectMany(a => a.GetRunnableBenchmarks()).ToArray();

            typeParser = new TypeParser(runnableBenchmarkTypes, logger);
        }
 public BenchmarkSwitcher(Type[] types)
 {
     typeParser = new TypeParser(types, logger);
 }