File size: 1,480 Bytes
8c763fb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | // Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Validators;
namespace BenchmarkDotNet.Extensions
{
/// <summary>
/// we need to tell our users that having more than 16 test cases per benchmark is a VERY BAD idea
/// </summary>
public class TooManyTestCasesValidator : IValidator
{
private const int Limit = 16;
public static readonly IValidator FailOnError = new TooManyTestCasesValidator();
public bool TreatsWarningsAsErrors => true;
public IEnumerable<ValidationError> Validate(ValidationParameters validationParameters)
{
var byDescriptor = validationParameters.Benchmarks.GroupBy(benchmark => (benchmark.Descriptor, benchmark.Job)); // descriptor = type + method
return byDescriptor.Where(benchmarkCase => benchmarkCase.Count() > Limit).Select(group =>
new ValidationError(
isCritical: true,
message: $"{group.Key.Descriptor.Type.Name}.{group.Key.Descriptor.WorkloadMethod.Name} has {group.Count()} test cases. It MUST NOT have more than {Limit} test cases. We don't have infinite amount of time to run all the benchmarks!!",
benchmarkCase: group.First()));
}
}
}
|