Runner for single ISourceGenerator or IIncrementalGenerator. Useful for unit testing of source generators.
using SourceGeneratorRunner;
using SourceGeneratorRunner.Testing;
var runner = SourceGeneratorRunner.Create(() => new YourSourceGenerator());
var source = "source code ...";
runner.Run(source).Verify(result =>
{
// verification ...
});
if you want to run generator with custom options
using SourceGeneratorRunner;
using SourceGeneratorRunner.Testing;
var config = RunnerConfig.Default with
{
// customize config ...
};
var runner = SourceGeneratorRunner.Create(config, () => new YourSourceGenerator());
// run generator ...
Since CSharpGeneratorDriver, CSharpCompilation, and CSharpSyntaxTree are used internally, it is recommended to refer to these specifications.