Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions tests/ActorSrcGen.Tests/GeneratorTests.cs
Original file line number Diff line number Diff line change
@@ -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));
}