-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBenchmarkCSharpCompilationFactory.cs
44 lines (35 loc) · 1.85 KB
/
BenchmarkCSharpCompilationFactory.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
using Microsoft.CodeAnalysis.Testing;
namespace EffectiveCSharp.Analyzers.Benchmarks.Helpers;
internal static class BenchmarkCSharpCompilationFactory
{
public static async Task<(CompilationWithAnalyzers Baseline, CompilationWithAnalyzers Test)> CreateAsync<TAnalyzer>(
(string Name, string Contents)[] sources,
AnalyzerOptions? options = null)
where TAnalyzer : DiagnosticAnalyzer, new()
{
Compilation? compilation = await CSharpCompilationCreator.CreateAsync(sources).ConfigureAwait(false);
if (compilation is null)
{
throw new InvalidOperationException("Failed to create compilation");
}
CompilationWithAnalyzers baseline = compilation.WithAnalyzers([new EmptyDiagnosticAnalyzer()], options);
CompilationWithAnalyzers test = compilation.WithAnalyzers([new TAnalyzer()], options);
return (baseline, test);
}
public static async Task<(CompilationWithAnalyzers Baseline, CompilationWithAnalyzers Test1, CompilationWithAnalyzers Test2)> CreateAsync<TAnalyzer1, TAnalyzer2>(
(string Name, string Contents)[] sources,
AnalyzerOptions? options = null)
where TAnalyzer1 : DiagnosticAnalyzer, new()
where TAnalyzer2 : DiagnosticAnalyzer, new()
{
Compilation? compilation = await CSharpCompilationCreator.CreateAsync(sources).ConfigureAwait(false);
if (compilation is null)
{
throw new InvalidOperationException("Failed to create compilation");
}
CompilationWithAnalyzers baseline = compilation.WithAnalyzers([new EmptyDiagnosticAnalyzer()], options);
CompilationWithAnalyzers test1 = compilation.WithAnalyzers([new TAnalyzer1()], options);
CompilationWithAnalyzers test2 = compilation.WithAnalyzers([new TAnalyzer2()], options);
return (baseline, test1, test2);
}
}