Skip to content

Unit testing: how to validate code that is fed to source generator? #75083

Answered by 333fred
vcaraulean asked this question in Q&A
Discussion options

You must be logged in to vote

driver.RunGeneratorsAndUpdateCompilation(compilation, out _, out var diagnostics);

These diagnostics are only diagnostics that are raised by generators that are run, ie things produced by output sources that raise diagnostics. If you want to get all diagnostics from the entire compilation, then you need to save the compilation, rather than discarding it, and get all diagnostics from it.

/cc @chsienki, it looks like we don't have documentation on that API, and this is a pitfall I've seen before. We should document this better.

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@vcaraulean
Comment options

@vcaraulean
Comment options

@333fred
Comment options

@333fred
Comment options

Answer selected by vcaraulean
@vcaraulean
Comment options

@chsienki
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants