示例#1
0
        private void HandleBenchmarkRunException(Exception ex, string formatMsg)
        {
            var nbe = new NBenchException(formatMsg, ex);

            _currentRun.WithException(nbe);
            Output.Error(ex, nbe.Message);
        }
        public static BenchmarkMethodMetadata GetCleanupMethod(TypeInfo classWithBenchmarks)
        {
            Contract.Requires(classWithBenchmarks != null);
            var cleanupMethods = classWithBenchmarks.GetMethods().Where(
                y => y.IsDefined(typeof(PerfCleanupAttribute), true)).ToList();

            if (!cleanupMethods.Any() || IsTypeInvalidForBenchmarks(classWithBenchmarks))
            {
                return(BenchmarkMethodMetadata.Empty);
            }

            // Need to log and throw an error here for benchmarks that have multiple setups declared
            if (cleanupMethods.Count > 1)
            {
                var ex =
                    new NBenchException(
                        $"{classWithBenchmarks.Name} has a declared {cleanupMethods.Count} PerfCleanupAttributes. A maximum of 1 is allowed per class. Failing...");
                ReflectionOutput.Error(ex.Message);
                throw ex;
            }

            var matchingMethod = cleanupMethods.Single();

            var takesContext = MethodTakesBenchmarkContext(matchingMethod);

            return(new BenchmarkMethodMetadata(matchingMethod, takesContext, false));
        }
        public static BenchmarkMethodMetadata GetCleanupMethod(TypeInfo classWithBenchmarks)
        {
            Contract.Requires(classWithBenchmarks != null);
            var cleanupMethods = classWithBenchmarks.GetMethods().Where(
               y => y.IsDefined(typeof(PerfCleanupAttribute), true)).ToList();
            if (!cleanupMethods.Any() || IsTypeInvalidForBenchmarks(classWithBenchmarks))
                return BenchmarkMethodMetadata.Empty;

            // Need to log and throw an error here for benchmarks that have multiple setups declared
            if (cleanupMethods.Count > 1)
            {
                var ex =
                    new NBenchException(
                        $"{classWithBenchmarks.Name} has a declared {cleanupMethods.Count} PerfCleanupAttributes. A maximum of 1 is allowed per class. Failing...");
                _reflectionOutput.Error(ex.Message);
                throw ex;
            }

            var matchingMethod = cleanupMethods.Single();

            var takesContext = MethodTakesBenchmarkContext(matchingMethod);
            return new BenchmarkMethodMetadata(matchingMethod, takesContext, false);
        }
示例#4
0
 private void HandleBenchmarkRunExecption(Exception ex, string formatMsg)
 {
     var nbe = new NBenchException(formatMsg, ex);
     _currentRun.WithException(nbe);
     Output.Error(ex, nbe.Message);
 }