LanguageDev / Yoakke

A collection of libraries for implementing compilers in .NET.
Apache License 2.0
141 stars 8 forks source link

Find out how to test generators #20

Open LPeter1997 opened 3 years ago

LPeter1997 commented 3 years ago

Generator projects are something we definitely should test as they are key parts of the libraries.

kant2002 commented 2 years ago

I use following approach. https://github.com/kant2002/WinFormsComInterop/blob/0b2edf8bb8c6f1a1586f63f1d4b8ac18ab21bf45/WinFormsComInterop.SourceGenerator.Tests/CodeGenerationTestBase.cs#L13

Maybe your specific way how to test would be different. For example you can consider creation of small application which declare parsers with specific features, then these application would run and validated to be producing desired outputs.

LPeter1997 commented 2 years ago

@kant2002 Generating the output as a string and comparing it is definitely one way, thanks for showing it to me! I'll have to consider if this is the best approach.

I'm planning to move away my generation logic to use Scriban templates, so maybe involving the compiler won't even be necessary.