From 31a439e18411ebc18e8ed9b26bf2887bb26d7ebe Mon Sep 17 00:00:00 2001
From: GeWuYou <95328647+GeWuYou@users.noreply.github.com>
Date: Tue, 14 Apr 2026 09:51:52 +0800
Subject: [PATCH] =?UTF-8?q?test(Godot):=20=E6=B7=BB=E5=8A=A0=E9=A1=B9?=
=?UTF-8?q?=E7=9B=AE=E5=85=83=E6=95=B0=E6=8D=AE=E7=94=9F=E6=88=90=E5=99=A8?=
=?UTF-8?q?=E6=B5=8B=E8=AF=95?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
- 验证基于 project.godot 的 AutoLoad 和 Input Action 强类型入口生成
- 测试 AutoLoad 类型非节点继承时的诊断报告功能
- 验证 Input Action 标识符冲突时的后缀追加和警告机制
- 测试多个显式映射指向同一 AutoLoad 时的重复检测
- 验证不同命名空间同名节点类型的隐式映射冲突处理
- 测试 AutoLoad 和 Input Action 重复条目的诊断和保留逻辑
- 验证缺失或空 project.godot 文件时的无生成行为
---
.../GodotProjectMetadataGeneratorTests.cs | 60 +++++++++++++++++++
1 file changed, 60 insertions(+)
diff --git a/GFramework.Godot.SourceGenerators.Tests/Project/GodotProjectMetadataGeneratorTests.cs b/GFramework.Godot.SourceGenerators.Tests/Project/GodotProjectMetadataGeneratorTests.cs
index 96dbe30f..b033a865 100644
--- a/GFramework.Godot.SourceGenerators.Tests/Project/GodotProjectMetadataGeneratorTests.cs
+++ b/GFramework.Godot.SourceGenerators.Tests/Project/GodotProjectMetadataGeneratorTests.cs
@@ -463,6 +463,66 @@ public class GodotProjectMetadataGeneratorTests
});
}
+ ///
+ /// 验证缺少 project.godot AdditionalText 时不会生成任何源码或诊断。
+ ///
+ [Test]
+ public void Run_Should_Not_Generate_Sources_When_Project_File_Is_Missing()
+ {
+ var result = AdditionalTextGeneratorTestDriver.Run(
+ CreateSource("namespace TestApp { }"));
+
+ var generatorResult = result.Results.Single();
+
+ Assert.Multiple(() =>
+ {
+ Assert.That(generatorResult.Diagnostics, Is.Empty);
+ Assert.That(generatorResult.GeneratedSources, Is.Empty);
+ });
+ }
+
+ ///
+ /// 验证空的 project.godot 内容不会生成任何源码或诊断。
+ ///
+ [Test]
+ public void Run_Should_Not_Generate_Sources_When_Project_File_Is_Empty()
+ {
+ var result = RunGenerator(
+ CreateSource("namespace TestApp { }"),
+ string.Empty);
+
+ var generatorResult = result.Results.Single();
+
+ Assert.Multiple(() =>
+ {
+ Assert.That(generatorResult.Diagnostics, Is.Empty);
+ Assert.That(generatorResult.GeneratedSources, Is.Empty);
+ });
+ }
+
+ ///
+ /// 验证只有空节的 project.godot 不会生成任何源码或诊断。
+ ///
+ [Test]
+ public void Run_Should_Not_Generate_Sources_When_Project_File_Has_Empty_Sections()
+ {
+ var result = RunGenerator(
+ CreateSource("namespace TestApp { }"),
+ """
+ [autoload]
+
+ [input]
+ """);
+
+ var generatorResult = result.Results.Single();
+
+ Assert.Multiple(() =>
+ {
+ Assert.That(generatorResult.Diagnostics, Is.Empty);
+ Assert.That(generatorResult.GeneratedSources, Is.Empty);
+ });
+ }
+
private static GeneratorDriverRunResult RunGenerator(
string source,
string projectFile)