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)); +}