dotnet / roslyn-sdk

Roslyn-SDK templates and Syntax Visualizer
MIT License
516 stars 256 forks source link

Source generator silently fails but test result says generated output doesn't match #1061

Open Arthri opened 1 year ago

Arthri commented 1 year ago

XUnit. When a source generator runs into an uncaught exception and Roslyn excludes its output from compilation, a diagnostic is raised, but test results check generated outputs before diagnostics so failing source generator will produce this message:

Expected source file list to match
-Sougen\Sougen.ExceptionGenerator\Soup.cs
-Sougen\Sougen.ExceptionGenerator\CarrotSoup.cs
-Sougen\Sougen.ExceptionGenerator\TomatoSoup.cs
-Sougen\Sougen.ExceptionGenerator\PotatoSoup.cs
-Sougen\Sougen.ExceptionGenerator\CelerySoup.cs
-Sougen\Sougen.ExceptionGenerator\GarlicSoup.cs
-Sougen\Sougen.ExceptionGenerator\LentilSoup.cs
+
+
+
+
+
+
+

I suggest that the test result somehow indicate the source generator failed so the cause of the message is more obvious.

A repo containing the repro is available here https://github.com/Arthri/dm01 . The test class is ExceptionGeneratorTests

sharwell commented 1 year ago

💡 When this occurs, you can also set TestBehaviors.SkipGeneratedSourcesCheck and it will ignore the content of the generated files and move on to diagnostics validation.