-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make DllImportGenerator unit tests' compilations use live refs #63410
Conversation
@ericstj @danmoseley @stephentoub @safern - this approach is what all source generators should use for unit testing. The DllImport source generator has unit tests that check several snippets and this approach allows us to add new APIs in a PR and immediately test them using the live build. |
Today other source generators are running the generators on the build machine rather than the test machine. Line 6 in 5993a3a
Is there a reason you decided to run the compiler on the test machine instead? Were you wanted to generate test code on the fly? |
The regex tests are executing the generator on the test machine, building against the implementation assemblies to avoid the hassle of using refs. |
We wanted to follow Roslyn best practice and use the Roslyn SDK testing APIs (at least the ones that were available when we started working on the source generator) to test our generator and analyzers. We have separate tests that run the generator on the build machine, but we wanted some tests that ran as unit tests because the debugging experience is significantly better in VS when your entrypoint is an xunit test. |
This was the key point for us. The Roslyn team's "best practices" were our guide in most if not all decisions and this fell out of that. |
I though the unit tests were running the generator on the test machine? |
@elinor-fung -- those are the basic unit tests that are less sensitive to references. I believe their meant to excercise the basic functionality of the generator and cover edge cases like invalid syntax etc that doesn't build correctly. There's a larger test suite that covers the behavior of runtime with generated code that runs the generator on the build machine. Those actually compile and execute the result. I believe we found it simpler to compile those on the build machine since it makes the tests simpler: they look more like the customer code. |
TestRunRequiresLiveRefPack
) to indicate live refs should be copied to test output, such that they get included in the helix work item payload.Resolves #60605
@AaronRobinsonMSFT @jkoritzinsky