Skip to content

Commit 205ce61

Browse files
Fix - incorrect table markdown #2545 (#2565)
* Fix - incorrect table markdown #2545 * Hide Column Table Markdown test case * columHidingRules support for CreateSummary in MockFactory * made the test case more generic to support hide columns attribute * Update tests/BenchmarkDotNet.Tests/Exporters/MarkdownExporterVerifyTests.cs --------- Co-authored-by: Tim Cassell <[email protected]>
1 parent d98a1d2 commit 205ce61

File tree

4 files changed

+37
-14
lines changed

4 files changed

+37
-14
lines changed

src/BenchmarkDotNet/Exporters/MarkdownExporter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ private void PrintTable(SummaryTable table, ILogger logger)
164164
logger.WriteStatistic(ColumnsStartWithSeparator ? TableHeaderSeparator.TrimStart().TrimEnd() + "-" : "-");
165165

166166
logger.WriteLineStatistic(string.Join("",
167-
table.Columns.Where(c => c.NeedToShow).Select(column =>
167+
table.Columns.Where(c => c.NeedToShow).Select((column, index) =>
168168
new string('-', column.Width - 1) + GetHeaderSeparatorIndicator(column.OriginalColumn.IsNumeric) +
169-
GetHeaderSeparatorColumnDivider(column.Index, table.ColumnCount))));
169+
GetHeaderSeparatorColumnDivider(index, table.Columns.Where(c => c.NeedToShow).Count()))));
170170
}
171171

172172
int rowCounter = 0;

tests/BenchmarkDotNet.Tests/Exporters/MarkdownExporterVerifyTests.cs

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
using JetBrains.Annotations;
1515
using VerifyXunit;
1616
using Xunit;
17+
using BenchmarkDotNet.Columns;
18+
using System.Reflection;
1719

1820
namespace BenchmarkDotNet.Tests.Exporters
1921
{
@@ -40,9 +42,8 @@ public Task GroupExporterTest(Type benchmarkType)
4042

4143
var logger = new AccumulationLogger();
4244
logger.WriteLine("=== " + benchmarkType.Name + " ===");
43-
4445
var exporter = MarkdownExporter.Mock;
45-
var summary = MockFactory.CreateSummary(benchmarkType);
46+
var summary = MockFactory.CreateSummary(benchmarkType, benchmarkType.GetCustomAttribute<HideColumnsAttribute>()?.Config.GetColumnHidingRules().ToArray() ?? []);
4647
exporter.ExportToLog(summary, logger);
4748

4849
var validator = BaselineValidator.FailOnError;
@@ -219,8 +220,8 @@ [Benchmark] public void Bar() { }
219220
[SimpleJob(id: "Job1", baseline: true), SimpleJob(id: "Job2")]
220221
public class MethodJobBaseline_MethodsJobs
221222
{
222-
[Benchmark(Baseline = true)] public void Foo() {}
223-
[Benchmark] public void Bar() {}
223+
[Benchmark(Baseline = true)] public void Foo() { }
224+
[Benchmark] public void Bar() { }
224225
}
225226

226227
[RankColumn, LogicalGroupColumn, BaselineColumn]
@@ -229,25 +230,25 @@ public class MethodJobBaseline_MethodsJobsParams
229230
{
230231
[Params(2, 10), UsedImplicitly] public int Param;
231232

232-
[Benchmark(Baseline = true)] public void Foo() {}
233-
[Benchmark] public void Bar() {}
233+
[Benchmark(Baseline = true)] public void Foo() { }
234+
[Benchmark] public void Bar() { }
234235
}
235236

236237
/* Invalid */
237238

238239
[RankColumn, LogicalGroupColumn, BaselineColumn]
239240
public class Invalid_TwoMethodBaselines
240241
{
241-
[Benchmark(Baseline = true)] public void Foo() {}
242-
[Benchmark(Baseline = true)] public void Bar() {}
242+
[Benchmark(Baseline = true)] public void Foo() { }
243+
[Benchmark(Baseline = true)] public void Bar() { }
243244
}
244245

245246
[RankColumn, LogicalGroupColumn, BaselineColumn]
246247
[SimpleJob(id: "Job1", baseline: true), SimpleJob(id: "Job2", baseline: true)]
247248
public class Invalid_TwoJobBaselines
248249
{
249-
[Benchmark] public void Foo() {}
250-
[Benchmark] public void Bar() {}
250+
[Benchmark] public void Foo() { }
251+
[Benchmark] public void Bar() { }
251252
}
252253

253254
/* Escape Params */
@@ -260,6 +261,13 @@ public class Escape_ParamsAndArguments
260261
[Benchmark] public void Foo(char charArg) {}
261262
[Benchmark] public void Bar() {}
262263
}
264+
265+
/* Hide Column */
266+
[HideColumns(Column.StdDev)]
267+
public class HideColumns_TableMarkDown
268+
{
269+
[Benchmark] public void Foo() { }
270+
}
263271
}
264272
}
265273
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
=== HideColumns_TableMarkDown ===
2+
3+
BenchmarkDotNet v0.10.x-mock, Microsoft Windows NT 10.0.x.mock (Hyper-V)
4+
MockIntel Core i7-6700HQ CPU 2.60GHz (Max: 3.10GHz), 1 CPU, 8 logical and 4 physical cores
5+
Frequency: 2531248 Hz, Resolution: 395.062 ns, Timer: TSC
6+
[Host] : Clr 4.0.x.mock, 64mock RyuJIT-v4.6.x.mock CONFIGURATION
7+
DefaultJob : extra output line
8+
9+
StdDev=8.80 ns
10+
11+
Method | Mean | Error |
12+
------- |---------:|--------:|
13+
Foo | 114.5 ns | 5.88 ns |
14+
15+
Errors: 0

tests/BenchmarkDotNet.Tests/Mocks/MockFactory.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace BenchmarkDotNet.Tests.Mocks
2424
{
2525
public static class MockFactory
2626
{
27-
public static Summary CreateSummary(Type benchmarkType)
27+
public static Summary CreateSummary(Type benchmarkType, params IColumnHidingRule[] columHidingRules)
2828
{
2929
var runInfo = BenchmarkConverter.TypeToBenchmarks(benchmarkType);
3030
return new Summary(
@@ -36,7 +36,7 @@ public static Summary CreateSummary(Type benchmarkType)
3636
TimeSpan.FromMinutes(1),
3737
TestCultureInfo.Instance,
3838
ImmutableArray<ValidationError>.Empty,
39-
ImmutableArray<IColumnHidingRule>.Empty);
39+
ImmutableArray.Create<IColumnHidingRule>(columHidingRules));
4040
}
4141

4242
public static Summary CreateSummary(IConfig config) => new Summary(

0 commit comments

Comments
 (0)