Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a8c9a72
Add Roslyn analyzers to detect incorrect usage of BenchmarkDotNet
silkfire Sep 26, 2025
c7b5c83
Unify C# language version
silkfire Oct 10, 2025
cb94c78
Remove Analyzers package projects
silkfire Oct 10, 2025
a6bda7c
Revert BenchmarkDotNet.Disassembler changes
silkfire Oct 10, 2025
ac406d9
Reference Analyzers project from Annotations
silkfire Oct 10, 2025
6711944
Move Benchmark.Analyzers and Benchmark.Analyzers.Tests to correct dir…
silkfire Oct 10, 2025
d1c2e33
Remove accidentally added package Microsoft.CodeAnalysis.NetAnalyzers…
silkfire Oct 11, 2025
f011b69
* Benchmark classes annotated with a [GenericTypeArguments] attribute…
silkfire Oct 12, 2025
40606f1
* Change diagnostic ID increment ordering
silkfire Oct 13, 2025
6999429
When determining whether a class has any benchmark methods, iterate t…
silkfire Oct 13, 2025
ce30448
Move "Benchmark class cannot be sealed" to Run analyzer
silkfire Oct 13, 2025
4639d81
Move "Benchmark class must be public" to Run analyzer
silkfire Oct 13, 2025
e2d1694
Support analyzing overload of BenchmarkRunner.Run that takes a Type p…
silkfire Oct 15, 2025
c4440cf
Remove requirement that a class must have at least one method annotat…
silkfire Oct 15, 2025
40cff14
* Integer attribute values that fit within target type range should n…
silkfire Oct 16, 2025
fd382b6
Use a dummy syntax tree to test whether types are implicitly convertible
silkfire Oct 17, 2025
2f4de08
Move "Generic class must be abstract or annotated with a [GenericType…
silkfire Oct 17, 2025
64d3495
Add support to analyze implicit conversion from an array to a Span of…
silkfire Oct 17, 2025
293da44
Add support to analyze implicit conversion when using constant values…
silkfire Oct 20, 2025
829344f
* Add support to analyze a boolean constant value for the Baseline pr…
silkfire Oct 27, 2025
6805c0f
Add test to OnlyOneMethodCanBeBaselinePerCategory rule verifying that…
silkfire Oct 27, 2025
07f1f07
Disable warnings for "Missing XML comment for publicly visible type o…
silkfire Oct 27, 2025
51cd5f9
Correct resource strings for OnlyOneMethodCanBeBaselinePerCategory rule
silkfire Oct 27, 2025
99536a3
Build error fixes
silkfire Oct 28, 2025
9cd6043
Add analyzer projects to main sln.
timcassell Nov 1, 2025
6f73b5a
Revert annotations csproj.
timcassell Nov 3, 2025
8af808f
* Change severity level of "UnnecessarySingleValuePassedToAttribute" …
silkfire Nov 4, 2025
572b1d4
Revert suppressing of BDN1401 in ArgumentsTests.cs
silkfire Nov 4, 2025
95abf00
Revert suppressing of BDN1401 in FullNameProviderTests.cs, PriorityTe…
silkfire Nov 4, 2025
61eb916
Fix Directory.build.props included in autogenerated projects.
timcassell Nov 4, 2025
c875c60
Add message to failing CI test.
timcassell Nov 5, 2025
6f2e385
Revert sdk update.
timcassell Nov 5, 2025
55292d2
Suppress warning.
timcassell Nov 6, 2025
3566b91
Skip failing test
timcassell Nov 6, 2025
a688920
Adjust wording of "ClassWithGenericTypeArgumentsAttributeMustBeNonAbs…
silkfire Nov 7, 2025
d760312
Add diagnostics for unintendedly passing a single null value to the […
silkfire Nov 7, 2025
eed4b29
Revert commit d760312d
silkfire Nov 8, 2025
c831ff1
Formatting
timcassell Nov 8, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/run-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ jobs:
- name: Run task 'build'
shell: cmd
run: ./build.cmd build
- name: Run task 'unit-tests'
shell: cmd
run: ./build.cmd unit-tests -e
- name: Run task 'analyzer-tests'
shell: cmd
run: ./build.cmd analyzer-tests -e
- name: Run task 'in-tests-full'
shell: cmd
run: ./build.cmd in-tests-full -e
Expand Down Expand Up @@ -79,6 +85,8 @@ jobs:
# Build and Test
- name: Run task 'build'
run: ./build.cmd build
- name: Run task 'analyzer-tests'
run: ./build.cmd analyzer-tests -e
- name: Run task 'unit-tests'
run: ./build.cmd unit-tests -e
- name: Run task 'in-tests-core'
Expand Down Expand Up @@ -116,6 +124,8 @@ jobs:
# Build and Test
- name: Run task 'build'
run: ./build.cmd build
- name: Run task 'analyzer-tests'
run: ./build.cmd analyzer-tests -e
- name: Run task 'unit-tests'
run: ./build.cmd unit-tests -e
- name: Run task 'in-tests-core'
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ src/BenchmarkDotNet/Disassemblers/BenchmarkDotNet.Disassembler.*.nupkg
# Visual Studio 2015 cache/options directory
.vs/

# VSCode directory
.vscode/

# Cake
tools/**
.dotnet
Expand Down
14 changes: 14 additions & 0 deletions BenchmarkDotNet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BenchmarkDotNet.Exporters.P
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BenchmarkDotNet.Exporters.Plotting.Tests", "tests\BenchmarkDotNet.Exporters.Plotting.Tests\BenchmarkDotNet.Exporters.Plotting.Tests.csproj", "{199AC83E-30BD-40CD-87CE-0C838AC0320D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BenchmarkDotNet.Analyzers", "src\BenchmarkDotNet.Analyzers\BenchmarkDotNet.Analyzers.csproj", "{AA4DDCA0-C1D8-ADA8-69FE-2F67C4CA96B1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BenchmarkDotNet.Analyzers.Tests", "tests\BenchmarkDotNet.Analyzers.Tests\BenchmarkDotNet.Analyzers.Tests.csproj", "{7DE89F16-2160-42E3-004E-1F5064732121}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -161,6 +165,14 @@ Global
{199AC83E-30BD-40CD-87CE-0C838AC0320D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{199AC83E-30BD-40CD-87CE-0C838AC0320D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{199AC83E-30BD-40CD-87CE-0C838AC0320D}.Release|Any CPU.Build.0 = Release|Any CPU
{AA4DDCA0-C1D8-ADA8-69FE-2F67C4CA96B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{AA4DDCA0-C1D8-ADA8-69FE-2F67C4CA96B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
{AA4DDCA0-C1D8-ADA8-69FE-2F67C4CA96B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{AA4DDCA0-C1D8-ADA8-69FE-2F67C4CA96B1}.Release|Any CPU.Build.0 = Release|Any CPU
{7DE89F16-2160-42E3-004E-1F5064732121}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7DE89F16-2160-42E3-004E-1F5064732121}.Debug|Any CPU.Build.0 = Debug|Any CPU
{7DE89F16-2160-42E3-004E-1F5064732121}.Release|Any CPU.ActiveCfg = Release|Any CPU
{7DE89F16-2160-42E3-004E-1F5064732121}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down Expand Up @@ -190,6 +202,8 @@ Global
{2E2283A3-6DA6-4482-8518-99D6D9F689AB} = {D6597E3A-6892-4A68-8E14-042FC941FDA2}
{B92ECCEF-7C27-4012-9E19-679F3C40A6A6} = {D6597E3A-6892-4A68-8E14-042FC941FDA2}
{199AC83E-30BD-40CD-87CE-0C838AC0320D} = {14195214-591A-45B7-851A-19D3BA2413F9}
{AA4DDCA0-C1D8-ADA8-69FE-2F67C4CA96B1} = {D6597E3A-6892-4A68-8E14-042FC941FDA2}
{7DE89F16-2160-42E3-004E-1F5064732121} = {14195214-591A-45B7-851A-19D3BA2413F9}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {4D9AF12B-1F7F-45A7-9E8C-E4E46ADCBD1F}
Expand Down
39 changes: 21 additions & 18 deletions NuGet.Config
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />

<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
<!-- reuquired to run Mono AOT benchmarks -->
<add key="dotnet6" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json" />
<add key="dotnet7" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json" />
<add key="dotnet8" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json" />
<add key="dotnet9" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v3/index.json" />
<add key="dotnet10" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet10/nuget/v3/index.json" />
</packageSources>
</configuration>
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageSources>
<!--To inherit the global NuGet package sources remove the <clear/> line below -->
<clear />

<add key="api.nuget.org" value="https://api.nuget.org/v3/index.json" />
<!-- required to run Mono AOT benchmarks -->
<add key="dotnet6" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json" />
<add key="dotnet7" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet7/nuget/v3/index.json" />
<add key="dotnet8" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet8/nuget/v3/index.json" />
<add key="dotnet9" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet9/nuget/v3/index.json" />
<add key="dotnet10" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet10/nuget/v3/index.json" />

<!-- required for Roslyn analyzers -->
<add key="dotnet-tools" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-tools/nuget/v3/index.json" />
</packageSources>
</configuration>
25 changes: 24 additions & 1 deletion build/BenchmarkDotNet.Build/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,28 @@ public HelpInfo GetHelp()
}
}

[TaskName(Name)]
[TaskDescription("Run analyzer tests")]
[IsDependentOn(typeof(BuildTask))]
public class AnalyzerTestsTask : FrostingTask<BuildContext>, IHelpProvider
{
private const string Name = "analyzer-tests";
public override void Run(BuildContext context) => context.UnitTestRunner.RunAnalyzerTests();

public HelpInfo GetHelp()
{
return new HelpInfo
{
Examples =
[
new Example(Name)
.WithArgument(KnownOptions.Exclusive)
.WithArgument(KnownOptions.Verbosity, "Diagnostic")
]
};
}
}

[TaskName(Name)]
[TaskDescription("Run integration tests using .NET Framework 4.6.2+ (slow)")]
[IsDependentOn(typeof(BuildTask))]
Expand All @@ -123,8 +145,9 @@ public class InTestsCoreTask : FrostingTask<BuildContext>, IHelpProvider
}

[TaskName(Name)]
[TaskDescription("Run all unit and integration tests (slow)")]
[TaskDescription("Run all unit, analyzer, and integration tests (slow)")]
[IsDependentOn(typeof(UnitTestsTask))]
[IsDependentOn(typeof(AnalyzerTestsTask))]
[IsDependentOn(typeof(InTestsFullTask))]
[IsDependentOn(typeof(InTestsCoreTask))]
public class AllTestsTask : FrostingTask<BuildContext>, IHelpProvider
Expand Down
12 changes: 12 additions & 0 deletions build/BenchmarkDotNet.Build/Runners/UnitTestRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public class UnitTestRunner(BuildContext context)
.Combine("BenchmarkDotNet.Exporters.Plotting.Tests")
.CombineWithFilePath("BenchmarkDotNet.Exporters.Plotting.Tests.csproj");

private FilePath AnalyzerTestsProjectFile { get; } = context.RootDirectory
.Combine("tests")
.Combine("BenchmarkDotNet.Analyzers.Tests")
.CombineWithFilePath("BenchmarkDotNet.Analyzers.Tests.csproj");

private FilePath IntegrationTestsProjectFile { get; } = context.RootDirectory
.Combine("tests")
.Combine("BenchmarkDotNet.IntegrationTests")
Expand Down Expand Up @@ -70,5 +75,12 @@ public void RunUnitTests()
RunUnitTests(targetFramework);
}

public void RunAnalyzerTests()
{
string[] targetFrameworks = context.IsRunningOnWindows() ? ["net462", "net8.0"] : ["net8.0"];
foreach (var targetFramework in targetFrameworks)
RunTests(AnalyzerTestsProjectFile, "analyzer", targetFramework);
}

public void RunInTests(string tfm) => RunTests(IntegrationTestsProjectFile, "integration", tfm);
}
3 changes: 2 additions & 1 deletion build/common.props
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@
<CheckEolTargetFramework>false</CheckEolTargetFramework>
<CodeAnalysisRuleSet>$(MSBuildThisFileDirectory)CodingStyle.ruleset</CodeAnalysisRuleSet>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

<WarningsNotAsErrors>NU1900</WarningsNotAsErrors>
<Nullable>annotations</Nullable>
<!-- Suppress warning for nuget package used in old (unsupported) tfm. -->
<SuppressTfmSupportBuildWarnings>true</SuppressTfmSupportBuildWarnings>
<NoWarn>CS9057</NoWarn>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@
<ProjectReference Include="..\..\src\BenchmarkDotNet.Diagnostics.Windows\BenchmarkDotNet.Diagnostics.Windows.csproj" />
<ProjectReference Include="..\..\src\BenchmarkDotNet.TestAdapter\BenchmarkDotNet.TestAdapter.csproj" />
</ItemGroup>
<ItemGroup>
<!-- Enables analyzers for this project (this is required since ProjectReference is not transitive). -->
<ProjectReference Include="..\..\src\BenchmarkDotNet.Analyzers\BenchmarkDotNet.Analyzers.csproj" ReferenceOutputAssembly="false" OutputItemType="Analyzer"/>
</ItemGroup>
</Project>
Loading