From eababa471aa2d96ff2e9b3c5cc951d0993d193c1 Mon Sep 17 00:00:00 2001 From: GeWuYou <95328647+GeWuYou@users.noreply.github.com> Date: Sat, 27 Dec 2025 13:37:39 +0800 Subject: [PATCH] =?UTF-8?q?test(rule):=20=E6=9B=B4=E6=96=B0=20ContextAware?= =?UTF-8?q?=20=E7=94=9F=E6=88=90=E5=99=A8=E6=B5=8B=E8=AF=95=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将测试方法的返回类型从 Task 更改为 Task - 使用 Assert.DoesNotThrowAsync 包装生成器测试执行逻辑 - 在测试方法末尾添加 return Task.CompletedTask 返回已完成任务 --- .../rule/ContextAwareGeneratorTests.cs | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs b/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs index bdd5418..bb5d942 100644 --- a/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs +++ b/GFramework.SourceGenerators.Tests/rule/ContextAwareGeneratorTests.cs @@ -16,7 +16,7 @@ public class ContextAwareGeneratorTests /// /// 异步任务 [Test] - public async Task Generates_ContextAware_Code() + public Task Generates_ContextAware_Code() { // 定义输入源代码,包含使用[ContextAware]特性的部分类 const string source = """ @@ -72,16 +72,19 @@ public class ContextAwareGeneratorTests } """; - - // 执行源代码生成器测试 - await GeneratorTest.RunAsync( - source + "\n" + frameworkStub, - ("MyRule.ContextAware.g.cs", expected) - ); + Assert.DoesNotThrowAsync(async () => + { + // 执行源代码生成器测试 + await GeneratorTest.RunAsync( + source + "\n" + frameworkStub, + ("MyRule.ContextAware.g.cs", expected) + ); + }); + return Task.CompletedTask; } [Test] - public async Task Generates_ContextAware_Code_When_Interface_Inherits_IContextAware() + public Task Generates_ContextAware_Code_When_Interface_Inherits_IContextAware() { const string source = """ using System; @@ -141,10 +144,13 @@ public class ContextAwareGeneratorTests } } """; - - await GeneratorTest.RunAsync( - source + "\n" + frameworkStub, - ("MyRule.ContextAware.g.cs", expected) - ); + Assert.DoesNotThrowAsync(async () => + { + await GeneratorTest.RunAsync( + source + "\n" + frameworkStub, + ("MyRule.ContextAware.g.cs", expected) + ); + }); + return Task.CompletedTask; } } \ No newline at end of file