From 48d1127fa9d4ad2379afe553168fd744c4729a62 Mon Sep 17 00:00:00 2001 From: webbrain-one <295484252+webbrain-one@users.noreply.github.com> Date: Wed, 29 Jul 2026 21:06:30 +0300 Subject: [PATCH] Add unit test suite for source generator Adds GeneratorTests.cs to verify the actor source generator behavior. Follows the referenced test implementation technique. Closes #10 --- tests/ActorSrcGen.Tests/GeneratorTests.cs | 47 +++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 tests/ActorSrcGen.Tests/GeneratorTests.cs diff --git a/tests/ActorSrcGen.Tests/GeneratorTests.cs b/tests/ActorSrcGen.Tests/GeneratorTests.cs new file mode 100644 index 0000000..793262a --- /dev/null +++ b/tests/ActorSrcGen.Tests/GeneratorTests.cs @@ -0,0 +1,47 @@ +using System.Linq; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Xunit; + +namespace ActorSrcGen.Tests; + +public class GeneratorTests +{ + [Fact] + public void Generator_Executes_Without_Errors() + { + var source = """ + using ActorSrcGen; + + [Actor] + public class TestActor + { + [Step] + public void Initialize() { } + } + """; + + var compilation = CreateCompilation(source); + var generator = new ActorGenerator(); + var driver = CSharpGeneratorDriver.Create(generator); + + var runResult = driver.RunGenerators(compilation).GetRunResult(); + var diagnostics = runResult.Diagnostics + .Where(d => d.Severity == DiagnosticSeverity.Error) + .ToList(); + + Assert.Empty(diagnostics); + } + + private static CSharpCompilation CreateCompilation(string source) => + CSharpCompilation.Create( + "TestAssembly", + new[] { CSharpSyntaxTree.ParseText(source) }, + references: new[] + { + MetadataReference.CreateFromFile(typeof(object).Assembly.Location), + MetadataReference.CreateFromFile(typeof(Console).Assembly.Location), + MetadataReference.CreateFromFile(typeof(ActorSrcGen.IActor<>).Assembly.Location) + }, + options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary)); +}