Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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

Large diffs are not rendered by default.

34 changes: 34 additions & 0 deletions GFramework.SourceGenerators.Tests/Core/AnalyzerTest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Microsoft.CodeAnalysis.Diagnostics;

namespace GFramework.SourceGenerators.Tests.Core;

/// <summary>
/// 提供 Roslyn 分析器测试的通用运行入口。
/// </summary>
/// <typeparam name="TAnalyzer">要验证的分析器类型。</typeparam>
public static class AnalyzerTestDriver<TAnalyzer>
where TAnalyzer : DiagnosticAnalyzer, new()
{
/// <summary>
/// 运行分析器测试并断言期望诊断。
/// </summary>
/// <param name="source">测试输入源码。</param>
/// <param name="diagnostics">期望诊断集合。</param>
/// <returns>异步测试任务。</returns>
public static async Task RunAsync(
string source,
params DiagnosticResult[] diagnostics)
{
var test = new CSharpAnalyzerTest<TAnalyzer, DefaultVerifier>
{
TestState =
{
Sources = { source }
},
DisabledDiagnostics = { "GF_Common_Trace_001" }
};

test.ExpectedDiagnostics.AddRange(diagnostics);
await test.RunAsync();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis" Version="4.14.0"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="4.14.0"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Analyzer.Testing" Version="1.1.3"/>
<PackageReference Include="Microsoft.CodeAnalysis.Common" Version="4.14.0"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="4.14.0"/>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.SourceGenerators.Testing" Version="1.1.3"/>
Expand Down
3 changes: 3 additions & 0 deletions GFramework.SourceGenerators/AnalyzerReleases.Unshipped.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
GF_ContextGet_006 | GFramework.SourceGenerators.rule | Error | ContextGetDiagnostics
GF_ContextGet_007 | GFramework.SourceGenerators.rule | Warning | ContextGetDiagnostics
GF_ContextGet_008 | GFramework.SourceGenerators.rule | Warning | ContextGetDiagnostics
GF_ContextRegistration_001 | GFramework.SourceGenerators.rule | Warning | ContextRegistrationDiagnostics
GF_ContextRegistration_002 | GFramework.SourceGenerators.rule | Warning | ContextRegistrationDiagnostics
GF_ContextRegistration_003 | GFramework.SourceGenerators.rule | Warning | ContextRegistrationDiagnostics
GF_ConfigSchema_001 | GFramework.SourceGenerators.Config | Error | ConfigSchemaDiagnostics
GF_ConfigSchema_002 | GFramework.SourceGenerators.Config | Error | ConfigSchemaDiagnostics
GF_ConfigSchema_003 | GFramework.SourceGenerators.Config | Error | ConfigSchemaDiagnostics
Expand Down
Loading
Loading