|
1 | 1 | using System;
|
2 |
| -using System.Collections.Generic; |
3 |
| -using System.Collections.Immutable; |
4 | 2 | using System.Linq;
|
5 | 3 | using BenchmarkDotNet.Attributes;
|
6 | 4 | using BenchmarkDotNet.Columns;
|
7 | 5 | using BenchmarkDotNet.Configs;
|
8 |
| -using BenchmarkDotNet.Engines; |
9 | 6 | using BenchmarkDotNet.Exporters;
|
10 | 7 | using BenchmarkDotNet.Loggers;
|
11 | 8 | using BenchmarkDotNet.Reports;
|
12 |
| -using BenchmarkDotNet.Running; |
13 |
| -using BenchmarkDotNet.Tests.Builders; |
14 |
| -using BenchmarkDotNet.Toolchains; |
15 |
| -using BenchmarkDotNet.Toolchains.Results; |
16 |
| -using BenchmarkDotNet.Validators; |
| 9 | +using BenchmarkDotNet.Tests.Mocks; |
17 | 10 | using Xunit;
|
18 | 11 | using Xunit.Abstractions;
|
19 | 12 |
|
@@ -53,62 +46,16 @@ public void EveyMetricHasItsOwnColumn()
|
53 | 46 | Assert.Equal("metric2", columns[1].Id);
|
54 | 47 | }
|
55 | 48 |
|
56 |
| - private class FakeMetricDescriptor : IMetricDescriptor |
57 |
| - { |
58 |
| - public FakeMetricDescriptor(string id, string legend) |
59 |
| - { |
60 |
| - Id = id; |
61 |
| - Legend = legend; |
62 |
| - } |
63 |
| - |
64 |
| - public string Id { get; } |
65 |
| - public string DisplayName => Id; |
66 |
| - public string Legend { get; } |
67 |
| - public string NumberFormat { get; } |
68 |
| - public UnitType UnitType { get; } |
69 |
| - public string Unit { get; } |
70 |
| - public bool TheGreaterTheBetter { get; } |
71 |
| - } |
72 |
| - |
73 | 49 | // TODO: Union this with MockFactory
|
74 | 50 | private Summary CreateSummary(bool hugeSd, Metric[] metrics)
|
75 | 51 | {
|
76 | 52 | var logger = new AccumulationLogger();
|
77 |
| - var summary = new Summary( |
78 |
| - "MockSummary", |
79 |
| - CreateBenchmarks(DefaultConfig.Instance).Select(b => CreateReport(b, hugeSd, metrics)).ToImmutableArray(), |
80 |
| - new HostEnvironmentInfoBuilder().Build(), |
81 |
| - string.Empty, |
82 |
| - string.Empty, |
83 |
| - TimeSpan.FromMinutes(1), |
84 |
| - ImmutableArray<ValidationError>.Empty); |
| 53 | + var summary = MockFactory.CreateSummary<MockBenchmarkClass>(DefaultConfig.Instance, hugeSd, metrics); |
85 | 54 | MarkdownExporter.Default.ExportToLog(summary, logger);
|
86 | 55 | output.WriteLine(logger.GetLog());
|
87 | 56 | return summary;
|
88 | 57 | }
|
89 | 58 |
|
90 |
| - private static BenchmarkReport CreateReport(BenchmarkCase benchmarkCase, bool hugeSd, Metric[] metrics) |
91 |
| - { |
92 |
| - var buildResult = BuildResult.Success(GenerateResult.Success(ArtifactsPaths.Empty, Array.Empty<string>())); |
93 |
| - var executeResult = new ExecuteResult(true, 0, default, Array.Empty<string>(), Array.Empty<string>()); |
94 |
| - bool isFoo = benchmarkCase.Descriptor.WorkloadMethodDisplayInfo == "Foo"; |
95 |
| - bool isBar = benchmarkCase.Descriptor.WorkloadMethodDisplayInfo == "Bar"; |
96 |
| - var measurements = new List<Measurement> |
97 |
| - { |
98 |
| - new Measurement(1, IterationMode.Workload, IterationStage.Result, 1, 1, 1), |
99 |
| - new Measurement(1, IterationMode.Workload, IterationStage.Result, 2, 1, hugeSd && isFoo ? 2 : 1), |
100 |
| - new Measurement(1, IterationMode.Workload, IterationStage.Result, 3, 1, hugeSd && isBar ? 3 : 1), |
101 |
| - new Measurement(1, IterationMode.Workload, IterationStage.Result, 4, 1, hugeSd && isFoo ? 2 : 1), |
102 |
| - new Measurement(1, IterationMode.Workload, IterationStage.Result, 5, 1, hugeSd && isBar ? 3 : 1), |
103 |
| - new Measurement(1, IterationMode.Workload, IterationStage.Result, 6, 1, 1) |
104 |
| - }; |
105 |
| - return new BenchmarkReport(true, benchmarkCase, buildResult, buildResult, new List<ExecuteResult> { executeResult }, measurements, default, metrics); |
106 |
| - } |
107 |
| - |
108 |
| - private static IEnumerable<BenchmarkCase> CreateBenchmarks(IConfig config) => |
109 |
| - BenchmarkConverter.TypeToBenchmarks(typeof(MockBenchmarkClass), config).BenchmarksCases; |
110 |
| - |
111 |
| - |
112 | 59 | [LongRunJob]
|
113 | 60 | public class MockBenchmarkClass
|
114 | 61 | {
|
|
0 commit comments