-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add e2e tests for custom analyzer rules (#10076)
- Loading branch information
1 parent
beaa3ad
commit 1c3b240
Showing
20 changed files
with
378 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/BuildCheck.UnitTests/TestAssets/AnalysisCandidate/AnalysisCandidate.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CustomAnalyzer" Version="1.0.0"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="nuget.config"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
6 changes: 6 additions & 0 deletions
6
src/BuildCheck.UnitTests/TestAssets/AnalysisCandidate/nugetTemplate.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<packageSources> | ||
|
||
</packageSources> | ||
</configuration> |
19 changes: 19 additions & 0 deletions
19
...didateWithMultipleAnalyzersInjected/AnalysisCandidateWithMultipleAnalyzersInjected.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net8.0</TargetFramework> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="CustomAnalyzer" Version="1.0.0"/> | ||
<PackageReference Include="CustomAnalyzer2" Version="1.0.0"/> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<None Include="nuget.config"> | ||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
</None> | ||
</ItemGroup> | ||
|
||
</Project> |
6 changes: 6 additions & 0 deletions
6
....UnitTests/TestAssets/AnalysisCandidateWithMultipleAnalyzersInjected/nugetTemplate.config
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<configuration> | ||
<packageSources> | ||
|
||
</packageSources> | ||
</configuration> |
38 changes: 38 additions & 0 deletions
38
src/BuildCheck.UnitTests/TestAssets/CustomAnalyzer/Analyzer1.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Collections.Generic; | ||
using Microsoft.Build.Construction; | ||
using Microsoft.Build.Experimental.BuildCheck; | ||
|
||
namespace CustomAnalyzer | ||
{ | ||
public sealed class Analyzer1 : BuildAnalyzer | ||
{ | ||
public static BuildAnalyzerRule SupportedRule = new BuildAnalyzerRule( | ||
"X01234", | ||
"Title", | ||
"Description", | ||
"Message format: {0}", | ||
new BuildAnalyzerConfiguration()); | ||
|
||
public override string FriendlyName => "CustomRule1"; | ||
|
||
public override IReadOnlyList<BuildAnalyzerRule> SupportedRules { get; } = new List<BuildAnalyzerRule>() { SupportedRule }; | ||
|
||
public override void Initialize(ConfigurationContext configurationContext) | ||
{ | ||
// configurationContext to be used only if analyzer needs external configuration data. | ||
} | ||
|
||
public override void RegisterActions(IBuildCheckRegistrationContext registrationContext) | ||
{ | ||
registrationContext.RegisterEvaluatedPropertiesAction(EvaluatedPropertiesAction); | ||
} | ||
|
||
private void EvaluatedPropertiesAction(BuildCheckDataContext<EvaluatedPropertiesAnalysisData> context) | ||
{ | ||
context.ReportResult(BuildCheckResult.Create( | ||
SupportedRule, | ||
ElementLocation.EmptyLocation, | ||
"Argument for the message format")); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/BuildCheck.UnitTests/TestAssets/CustomAnalyzer/Analyzer2.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using System.Collections.Generic; | ||
using Microsoft.Build.Construction; | ||
using Microsoft.Build.Experimental.BuildCheck; | ||
|
||
namespace CustomAnalyzer | ||
{ | ||
public sealed class Analyzer2 : BuildAnalyzer | ||
{ | ||
public static BuildAnalyzerRule SupportedRule = new BuildAnalyzerRule( | ||
"X01235", | ||
"Title", | ||
"Description", | ||
"Message format: {0}", | ||
new BuildAnalyzerConfiguration()); | ||
|
||
public override string FriendlyName => "CustomRule2"; | ||
|
||
public override IReadOnlyList<BuildAnalyzerRule> SupportedRules { get; } = new List<BuildAnalyzerRule>() { SupportedRule }; | ||
|
||
public override void Initialize(ConfigurationContext configurationContext) | ||
{ | ||
// configurationContext to be used only if analyzer needs external configuration data. | ||
} | ||
|
||
public override void RegisterActions(IBuildCheckRegistrationContext registrationContext) | ||
{ | ||
registrationContext.RegisterEvaluatedPropertiesAction(EvaluatedPropertiesAction); | ||
} | ||
|
||
private void EvaluatedPropertiesAction(BuildCheckDataContext<EvaluatedPropertiesAnalysisData> context) | ||
{ | ||
context.ReportResult(BuildCheckResult.Create( | ||
SupportedRule, | ||
ElementLocation.EmptyLocation, | ||
"Argument for the message format")); | ||
} | ||
} | ||
} |
Oops, something went wrong.