mirror of
https://github.com/GeWuYou/GFramework.git
synced 2026-05-07 00:39:00 +08:00
- 新增 Context Get 注入生成器详细文档,包含使用示例和诊断信息 - 添加源代码生成器总览文档,涵盖 Log、Config Schema、ContextAware 等功能 - 配置测试项目 GFramework.SourceGenerators.Tests 的项目文件和依赖 - 生成器诊断规则新增至 Unshipped 分析器发布跟踪文件
35 lines
1.1 KiB
C#
35 lines
1.1 KiB
C#
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();
|
|
}
|
|
}
|