-
Notifications
You must be signed in to change notification settings - Fork 172
/
NoFilesFormatted.cs
92 lines (84 loc) · 4.07 KB
/
NoFilesFormatted.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
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the MIT license. See License.txt in the project root for license information.
using System;
using System.Collections.Immutable;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Jobs;
using Microsoft.CodeAnalysis.Tools.Utilities;
using Microsoft.Extensions.Logging;
namespace Microsoft.CodeAnalysis.Tools.Perf
{
[SimpleJob(RuntimeMoniker.NetCoreApp21)]
public class NoFilesFormatted
{
private const string FormattedProjectPath = "tests/projects/for_code_formatter/formatted_project/";
private const string FormattedProjectFilePath = FormattedProjectPath + "formatted_project.csproj";
private const string FormattedSolutionFilePath = "tests/projects/for_code_formatter/formatted_solution/formatted_solution.sln";
private static EmptyLogger EmptyLogger => new EmptyLogger();
private static SourceFileMatcher AllFileMatcher => SourceFileMatcher.CreateMatcher(Array.Empty<string>(), Array.Empty<string>());
[IterationSetup]
public void NoFilesFormattedSetup()
{
MSBuildRegister.RegisterInstance();
SolutionPathSetter.SetCurrentDirectory();
}
[Benchmark(Description = "No Files are Formatted (folder)")]
public void NoFilesFormattedFolder()
{
var (workspacePath, workspaceType) = WorkspacePathHelper.GetWorkspaceInfo(FormattedProjectPath);
var options = new FormatOptions(
workspacePath,
workspaceType,
LogLevel.Error,
fixCategory: FixCategory.Whitespace,
codeStyleSeverity: DiagnosticSeverity.Error,
analyzerSeverity: DiagnosticSeverity.Error,
diagnostics: ImmutableHashSet<string>.Empty,
saveFormattedFiles: false,
changesAreErrors: false,
AllFileMatcher,
reportPath: string.Empty,
includeGeneratedFiles: false);
_ = CodeFormatter.FormatWorkspaceAsync(options, EmptyLogger, default).GetAwaiter().GetResult();
}
[Benchmark(Description = "No Files are Formatted (project)")]
public void NoFilesFormattedProject()
{
var (workspacePath, workspaceType) = WorkspacePathHelper.GetWorkspaceInfo(FormattedProjectFilePath);
var options = new FormatOptions(
workspacePath,
workspaceType,
LogLevel.Error,
fixCategory: FixCategory.Whitespace,
codeStyleSeverity: DiagnosticSeverity.Error,
analyzerSeverity: DiagnosticSeverity.Error,
diagnostics: ImmutableHashSet<string>.Empty,
saveFormattedFiles: false,
changesAreErrors: false,
AllFileMatcher,
reportPath: string.Empty,
includeGeneratedFiles: false);
_ = CodeFormatter.FormatWorkspaceAsync(options, EmptyLogger, default).GetAwaiter().GetResult();
}
[Benchmark(Description = "No Files are Formatted (solution)")]
public void NoFilesFormattedSolution()
{
var (workspacePath, workspaceType) = WorkspacePathHelper.GetWorkspaceInfo(FormattedSolutionFilePath);
var options = new FormatOptions(
workspacePath,
workspaceType,
LogLevel.Error,
fixCategory: FixCategory.Whitespace,
codeStyleSeverity: DiagnosticSeverity.Error,
analyzerSeverity: DiagnosticSeverity.Error,
diagnostics: ImmutableHashSet<string>.Empty,
saveFormattedFiles: false,
changesAreErrors: false,
AllFileMatcher,
reportPath: string.Empty,
includeGeneratedFiles: false);
_ = CodeFormatter.FormatWorkspaceAsync(options, EmptyLogger, default).GetAwaiter().GetResult();
}
[IterationCleanup]
public void NoFilesFormattedCleanup() => SolutionPathSetter.UnsetCurrentDirectory();
}
}