Skip to content

Commit a08c0f0

Browse files
timcassellsilkfire
authored andcommitted
Add analyzer projects to main sln.
Run analyzer tests in CI. Fix compile errors. Ensure analyzers run against test projects.
1 parent 00cdf6e commit a08c0f0

File tree

11 files changed

+77
-80
lines changed

11 files changed

+77
-80
lines changed

.github/workflows/run-tests.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ jobs:
4545
- name: Run task 'build'
4646
shell: cmd
4747
run: ./build.cmd build
48+
- name: Run task 'unit-tests'
49+
shell: cmd
50+
run: ./build.cmd unit-tests -e
51+
- name: Run task 'analyzer-tests'
52+
shell: cmd
53+
run: ./build.cmd analyzer-tests -e
4854
- name: Run task 'in-tests-full'
4955
shell: cmd
5056
run: ./build.cmd in-tests-full -e
@@ -79,6 +85,8 @@ jobs:
7985
# Build and Test
8086
- name: Run task 'build'
8187
run: ./build.cmd build
88+
- name: Run task 'analyzer-tests'
89+
run: ./build.cmd analyzer-tests -e
8290
- name: Run task 'unit-tests'
8391
run: ./build.cmd unit-tests -e
8492
- name: Run task 'in-tests-core'
@@ -116,6 +124,8 @@ jobs:
116124
# Build and Test
117125
- name: Run task 'build'
118126
run: ./build.cmd build
127+
- name: Run task 'analyzer-tests'
128+
run: ./build.cmd analyzer-tests -e
119129
- name: Run task 'unit-tests'
120130
run: ./build.cmd unit-tests -e
121131
- name: Run task 'in-tests-core'

BenchmarkDotNet.Analyzers.sln

Lines changed: 0 additions & 43 deletions
This file was deleted.

BenchmarkDotNet.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BenchmarkDotNet.Exporters.P
5959
EndProject
6060
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}"
6161
EndProject
62+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BenchmarkDotNet.Analyzers", "src\BenchmarkDotNet.Analyzers\BenchmarkDotNet.Analyzers.csproj", "{AA4DDCA0-C1D8-ADA8-69FE-2F67C4CA96B1}"
63+
EndProject
64+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BenchmarkDotNet.Analyzers.Tests", "tests\BenchmarkDotNet.Analyzers.Tests\BenchmarkDotNet.Analyzers.Tests.csproj", "{7DE89F16-2160-42E3-004E-1F5064732121}"
65+
EndProject
6266
Global
6367
GlobalSection(SolutionConfigurationPlatforms) = preSolution
6468
Debug|Any CPU = Debug|Any CPU
@@ -161,6 +165,14 @@ Global
161165
{199AC83E-30BD-40CD-87CE-0C838AC0320D}.Debug|Any CPU.Build.0 = Debug|Any CPU
162166
{199AC83E-30BD-40CD-87CE-0C838AC0320D}.Release|Any CPU.ActiveCfg = Release|Any CPU
163167
{199AC83E-30BD-40CD-87CE-0C838AC0320D}.Release|Any CPU.Build.0 = Release|Any CPU
168+
{AA4DDCA0-C1D8-ADA8-69FE-2F67C4CA96B1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
169+
{AA4DDCA0-C1D8-ADA8-69FE-2F67C4CA96B1}.Debug|Any CPU.Build.0 = Debug|Any CPU
170+
{AA4DDCA0-C1D8-ADA8-69FE-2F67C4CA96B1}.Release|Any CPU.ActiveCfg = Release|Any CPU
171+
{AA4DDCA0-C1D8-ADA8-69FE-2F67C4CA96B1}.Release|Any CPU.Build.0 = Release|Any CPU
172+
{7DE89F16-2160-42E3-004E-1F5064732121}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
173+
{7DE89F16-2160-42E3-004E-1F5064732121}.Debug|Any CPU.Build.0 = Debug|Any CPU
174+
{7DE89F16-2160-42E3-004E-1F5064732121}.Release|Any CPU.ActiveCfg = Release|Any CPU
175+
{7DE89F16-2160-42E3-004E-1F5064732121}.Release|Any CPU.Build.0 = Release|Any CPU
164176
EndGlobalSection
165177
GlobalSection(SolutionProperties) = preSolution
166178
HideSolutionNode = FALSE
@@ -190,6 +202,8 @@ Global
190202
{2E2283A3-6DA6-4482-8518-99D6D9F689AB} = {D6597E3A-6892-4A68-8E14-042FC941FDA2}
191203
{B92ECCEF-7C27-4012-9E19-679F3C40A6A6} = {D6597E3A-6892-4A68-8E14-042FC941FDA2}
192204
{199AC83E-30BD-40CD-87CE-0C838AC0320D} = {14195214-591A-45B7-851A-19D3BA2413F9}
205+
{AA4DDCA0-C1D8-ADA8-69FE-2F67C4CA96B1} = {D6597E3A-6892-4A68-8E14-042FC941FDA2}
206+
{7DE89F16-2160-42E3-004E-1F5064732121} = {14195214-591A-45B7-851A-19D3BA2413F9}
193207
EndGlobalSection
194208
GlobalSection(ExtensibilityGlobals) = postSolution
195209
SolutionGuid = {4D9AF12B-1F7F-45A7-9E8C-E4E46ADCBD1F}

build/BenchmarkDotNet.Build/Program.cs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,28 @@ public HelpInfo GetHelp()
9898
}
9999
}
100100

101+
[TaskName(Name)]
102+
[TaskDescription("Run analyzer tests")]
103+
[IsDependentOn(typeof(BuildTask))]
104+
public class AnalyzerTestsTask : FrostingTask<BuildContext>, IHelpProvider
105+
{
106+
private const string Name = "analyzer-tests";
107+
public override void Run(BuildContext context) => context.UnitTestRunner.RunAnalyzerTests();
108+
109+
public HelpInfo GetHelp()
110+
{
111+
return new HelpInfo
112+
{
113+
Examples =
114+
[
115+
new Example(Name)
116+
.WithArgument(KnownOptions.Exclusive)
117+
.WithArgument(KnownOptions.Verbosity, "Diagnostic")
118+
]
119+
};
120+
}
121+
}
122+
101123
[TaskName(Name)]
102124
[TaskDescription("Run integration tests using .NET Framework 4.6.2+ (slow)")]
103125
[IsDependentOn(typeof(BuildTask))]
@@ -123,8 +145,9 @@ public class InTestsCoreTask : FrostingTask<BuildContext>, IHelpProvider
123145
}
124146

125147
[TaskName(Name)]
126-
[TaskDescription("Run all unit and integration tests (slow)")]
148+
[TaskDescription("Run all unit, analyzer, and integration tests (slow)")]
127149
[IsDependentOn(typeof(UnitTestsTask))]
150+
[IsDependentOn(typeof(AnalyzerTestsTask))]
128151
[IsDependentOn(typeof(InTestsFullTask))]
129152
[IsDependentOn(typeof(InTestsCoreTask))]
130153
public class AllTestsTask : FrostingTask<BuildContext>, IHelpProvider

build/BenchmarkDotNet.Build/Runners/UnitTestRunner.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ public class UnitTestRunner(BuildContext context)
2020
.Combine("BenchmarkDotNet.Exporters.Plotting.Tests")
2121
.CombineWithFilePath("BenchmarkDotNet.Exporters.Plotting.Tests.csproj");
2222

23+
private FilePath AnalyzerTestsProjectFile { get; } = context.RootDirectory
24+
.Combine("tests")
25+
.Combine("BenchmarkDotNet.Analyzers.Tests")
26+
.CombineWithFilePath("BenchmarkDotNet.Analyzers.Tests.csproj");
27+
2328
private FilePath IntegrationTestsProjectFile { get; } = context.RootDirectory
2429
.Combine("tests")
2530
.Combine("BenchmarkDotNet.IntegrationTests")
@@ -70,5 +75,12 @@ public void RunUnitTests()
7075
RunUnitTests(targetFramework);
7176
}
7277

78+
public void RunAnalyzerTests()
79+
{
80+
string[] targetFrameworks = context.IsRunningOnWindows() ? ["net462", "net8.0"] : ["net8.0"];
81+
foreach (var targetFramework in targetFrameworks)
82+
RunTests(AnalyzerTestsProjectFile, "analyzer", targetFramework);
83+
}
84+
7385
public void RunInTests(string tfm) => RunTests(IntegrationTestsProjectFile, "integration", tfm);
7486
}

build/sdk/global.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"sdk": {
3-
"version": "8.0.410",
3+
"version": "9.0.306",
44
"rollForward": "disable"
55
}
66
}
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
2+
<Import Project="..\..\build\common.props" />
33
<PropertyGroup>
44
<TargetFramework>netstandard2.0</TargetFramework>
55
<IsPackable>false</IsPackable>
6-
76
<!-- Avoid ID conflicts with the package project. -->
87
<PackageId>BenchmarkDotNet.Analyzers</PackageId>
98
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
109
<NoWarn>$(NoWarn);CS1591</NoWarn>
1110
</PropertyGroup>
12-
1311
<ItemGroup>
1412
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0" />
1513
</ItemGroup>
16-
1714
<ItemGroup>
1815
<AdditionalFiles Include="AnalyzerReleases.Shipped.md" />
1916
<AdditionalFiles Include="AnalyzerReleases.Unshipped.md" />
2017
</ItemGroup>
21-
2218
<ItemGroup>
2319
<Compile Update="BenchmarkDotNetAnalyzerResources.Designer.cs">
2420
<DesignTime>True</DesignTime>
@@ -30,12 +26,9 @@
3026
<LastGenOutput>BenchmarkDotNetAnalyzerResources.Designer.cs</LastGenOutput>
3127
</EmbeddedResource>
3228
</ItemGroup>
33-
3429
<ItemGroup>
3530
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleToAttribute">
3631
<_Parameter1>BenchmarkDotNet.Analyzers.Tests,PublicKey=00240000048000009400000006020000002400005253413100040000010001002970bbdfca4d129fc74b4845b239973f1b183684f0d7db5e1de7e085917e3656cf94884803cb800d85d5aae5838fb3f8fd1f2829e8208c4f087afcfe970bce44037ba30a66749cd5514b410ca8a35e9c7d6eb86975853c834c9ad25051537f9a05a0c540c5d84f2c7b32ab01619d84367fd424797ba3242f08b0e6ae75f66dad</_Parameter1>
3732
</AssemblyAttribute>
3833
</ItemGroup>
39-
40-
<Import Project="..\..\build\common.props" />
4134
</Project>

src/BenchmarkDotNet.Annotations/BenchmarkDotNet.Annotations.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,6 @@
1616
</ItemGroup>
1717
<ItemGroup>
1818
<ProjectReference Include="..\BenchmarkDotNet.Analyzers\BenchmarkDotNet.Analyzers.csproj" PrivateAssets="all" />
19-
<None Include="$(OutputPath)\netstandard2.0\BenchmarkDotNet.Analyzers.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
19+
<Content Include="..\BenchmarkDotNet.Analyzers\bin\$(Configuration)\netstandard2.0\BenchmarkDotNet.Analyzers.dll" Pack="true" PackagePath="analyzers/dotnet/cs" Visible="false" />
2020
</ItemGroup>
2121
</Project>

tests/BenchmarkDotNet.Analyzers.Tests/AnalyzerTests/Attributes/ParamsAttributeAnalyzerTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -504,15 +504,15 @@ public async Task Providing_an_unexpected_array_value_type_to_params_attribute_s
504504
505505
public class BenchmarkClass
506506
{
507-
[{{dummyAttributeUsage}}Params({{string.Format(arrayValuesContainerAttributeArgument.Value1, valueAndType.Value1, valueAndType.Value2)}})]
507+
[{{dummyAttributeUsage}}Params({{string.Format(arrayValuesContainerAttributeArgument.Value1!, valueAndType.Value1, valueAndType.Value2)}})]
508508
public {{expectedFieldOrPropertyType}} {{fieldOrPropertyDeclaration}}
509509
}
510510
""";
511511
TestCode = testCode;
512512
ReferenceDummyAttribute();
513513
ReferenceDummyEnum();
514514

515-
AddDefaultExpectedDiagnostic(string.Format(arrayValuesContainerAttributeArgument.Value2,
515+
AddDefaultExpectedDiagnostic(string.Format(arrayValuesContainerAttributeArgument.Value2!,
516516
valueAndType.Value1,
517517
valueAndType.Value2),
518518
expectedFieldOrPropertyType,
Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,33 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
2+
<Import Project="..\..\build\common.props" />
33
<PropertyGroup>
4-
<TargetFrameworks>net462;net6.0;net8.0</TargetFrameworks>
4+
<AssemblyName>BenchmarkDotNet.Analyzers.Tests</AssemblyName>
5+
<TargetFrameworks>net462;net8.0</TargetFrameworks>
56
<Nullable>enable</Nullable>
6-
77
<PreserveCompilationContext>true</PreserveCompilationContext>
88
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
99
<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
1010
<SuppressTfmSupportBuildErrors>true</SuppressTfmSupportBuildErrors>
11+
<NoWarn>$(NoWarn);CS1591</NoWarn>
1112
</PropertyGroup>
12-
1313
<ItemGroup>
1414
<None Remove="BenchmarkDotNet.Analyzers.Tests.csproj.DotSettings" />
1515
</ItemGroup>
16-
1716
<ItemGroup>
1817
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing" Version="1.1.2" />
1918
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.14.0" />
2019
<PackageReference Include="Newtonsoft.Json" Version="13.0.4" />
2120
<PackageReference Include="System.Formats.Asn1" Version="9.0.10" />
22-
<PackageReference Include="System.Text.RegularExpressions" Version="4.3.1" />
2321
<PackageReference Include="xunit" Version="2.9.3" />
2422
<PackageReference Include="Xunit.Combinatorial" Version="1.6.24" />
2523
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2">
2624
<PrivateAssets>all</PrivateAssets>
2725
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
2826
</PackageReference>
2927
</ItemGroup>
30-
3128
<ItemGroup>
29+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
3230
<ProjectReference Include="..\..\src\BenchmarkDotNet.Analyzers\BenchmarkDotNet.Analyzers.csproj" />
3331
<ProjectReference Include="..\..\src\BenchmarkDotNet\BenchmarkDotNet.csproj" />
3432
</ItemGroup>
35-
36-
<Choose>
37-
<When Condition="'$(TargetFramework)' == 'net6.0'">
38-
<ItemGroup>
39-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.13.0" />
40-
</ItemGroup>
41-
</When>
42-
<Otherwise>
43-
<ItemGroup>
44-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.0.0" />
45-
</ItemGroup>
46-
</Otherwise>
47-
</Choose>
48-
49-
<Import Project="..\..\build\common.props" />
50-
51-
</Project>
33+
</Project>

0 commit comments

Comments
 (0)