C
C#12mo ago
aspeckt112

Testing the output of source generators

Hey all. Has anyone got advice about how to test the output of source generators? I've got a project that uses attributes that are added to assemblies in the project to work out what it needs to generate. There's the potential for it to spit out quite a lot of code if someone chooses to make use of all the attributes. It's cool, it's all working well. But what I'd like is some sort of automated test to run in a pipeline as part of the build so I know if I've introduced errors without needing to manaully check the output everytime - which is tedious and error prone. Right now, the only thing I can think to do is essentially write unit tests with all the expected output hard coded and compare it each time. It'll work, but it feels like there has to be a better way?
2 Replies
cap5lut
cap5lut12mo ago
unit tests seem to be the way to go, https://gist.github.com/chsienki/2955ed9336d7eb22bcb246840bfeb05c shows some ground work on how to setup the tests.
aspeckt112
aspeckt112OP12mo ago
Yeah. Fair enough. It’s a reasonable enough approach. I just wanted to know if anyone has come across anything else. Thanks for your time!
Want results from more Discord servers?
Add your server