-
-
Notifications
You must be signed in to change notification settings - Fork 986
/
Copy pathCommonExporterVerifyTests.cs
115 lines (102 loc) · 4.1 KB
/
CommonExporterVerifyTests.cs
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Columns;
using BenchmarkDotNet.Configs;
using BenchmarkDotNet.Environments;
using BenchmarkDotNet.Exporters;
using BenchmarkDotNet.Exporters.Csv;
using BenchmarkDotNet.Exporters.Json;
using BenchmarkDotNet.Exporters.Xml;
using BenchmarkDotNet.Jobs;
using BenchmarkDotNet.Loggers;
using BenchmarkDotNet.Tests.Builders;
using BenchmarkDotNet.Tests.Mocks;
using JetBrains.Annotations;
using VerifyXunit;
using Xunit;
namespace BenchmarkDotNet.Tests.Exporters
{
[Collection("VerifyTests")]
[UsesVerify]
public class CommonExporterVerifyTests : IDisposable
{
private readonly CultureInfo initCulture;
public CommonExporterVerifyTests()
{
initCulture = Thread.CurrentThread.CurrentCulture;
}
private static readonly Dictionary<string, CultureInfo> CultureInfos = new Dictionary<string, CultureInfo>
{
{ "", CultureInfo.InvariantCulture },
{ "ru-RU", new CultureInfo("ru-RU") },
{ "en-US", new CultureInfo("en-US") }
};
[UsedImplicitly]
public static TheoryData<string> CultureInfoNames => TheoryDataHelper.Create(CultureInfos.Keys);
[Theory]
[MemberData(nameof(CultureInfoNames))]
public Task Exporters(string cultureInfoName)
{
var cultureInfo = CultureInfos[cultureInfoName];
Thread.CurrentThread.CurrentCulture = cultureInfo;
EnvironmentResolver.Default.Register(EnvironmentMode.AffinityCharacteristic, () => new IntPtr(0xFF));
var logger = new AccumulationLogger();
var exporters = GetExporters();
foreach (var exporter in exporters)
{
PrintTitle(logger, exporter);
exporter.ExportToLog(MockFactory.CreateSummary(config.WithCultureInfo(cultureInfo)), logger);
}
var settings = VerifySettingsFactory.Create();
settings.UseTextForParameters(GetName(cultureInfo));
return Verifier.Verify(logger.GetLog(), settings);
}
private static void PrintTitle(AccumulationLogger logger, IExporter exporter)
{
logger.WriteLine("############################################");
logger.WriteLine($"{exporter.Name}");
logger.WriteLine("############################################");
}
private static string GetName(CultureInfo cultureInfo)
{
if (cultureInfo.Name == string.Empty)
return "Invariant";
return cultureInfo.Name;
}
private static IEnumerable<IExporter> GetExporters()
{
yield return AsciiDocExporter.Default;
yield return HtmlExporter.Default;
yield return JsonExporter.Brief;
yield return JsonExporter.BriefCompressed;
yield return JsonExporter.Full;
yield return JsonExporter.FullCompressed;
yield return MarkdownExporter.Default;
yield return MarkdownExporter.Atlassian;
yield return MarkdownExporter.Console;
yield return MarkdownExporter.GitHub;
yield return MarkdownExporter.StackOverflow;
yield return PlainExporter.Default;
yield return XmlExporter.Brief;
yield return XmlExporter.BriefCompressed;
yield return XmlExporter.Full;
yield return XmlExporter.FullCompressed;
yield return CsvExporter.Default;
yield return CsvMeasurementsExporter.Default;
}
private static readonly IConfig config = ManualConfig.Create(DefaultConfig.Instance)
.AddColumn(StatisticColumn.Mean)
.AddColumn(StatisticColumn.StdDev)
.AddColumn(StatisticColumn.P67)
.AddDiagnoser(Diagnosers.MemoryDiagnoser.Default);
public void Dispose()
{
Thread.CurrentThread.CurrentCulture = initCulture;
}
}
}