-
Notifications
You must be signed in to change notification settings - Fork 78
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
Include Testing Example #54
Comments
Thanks for writing in! Yes, we are looking to add a In the meantime, as for protoc-gen-debug, it emits the CodeGeneratorRequest as a binary file for the specified run. You can then read the bin file in test, and have it emit the AST that you can use in your plugins. Here's some example helpers that we are using internally, and where it's leveraged in the pgsgo subpackage. |
I would definitely love to see an example of how this is done as well. I then load the files and run my module using this: pgs.Init(
pgs.ProtocInput(req), // use the pre-generated request
pgs.ProtocOutput(res), // capture CodeGeneratorResponse
pgs.FileSystem(fs), // capture any custom files written directly to disk
).RegisterModule(New()).Render() For some reason, I am unable to see the errors outputted by my module when checking the protobuf inputs for correctness. Is there currently a way to do this? |
Have you tried using the Debug Mode functionality? It would look like:
or
|
Thanks for the feedback! Will make a note to add some documentation / a walkthrough. The basic steps are:
module-level test, e.g.
model-level test, e.g.
|
Thanks for the examples! They are immensely helpful 😄 I have a few more questions for my situation. I am not passing the AST to my module; I don't think I need to do this as I am embedding For testing, I have a bunch of protoc files as test cases, some are valid and should generate expected output. Some are invalid (according to the module) and should return a error. The
|
You're welcome!
Correct -- I noted you only need to generate the AST at the generator-level if passing it to the AST 😄
AFAIK, you can only test individual files on the module (here,
This depends on what kind of plugin you've written. For example, for a linter you would be looking up the error and asserting it matches whatever custom error you've defined for that invalid case. For a code generator, it could be checking side effects of the |
I noticed the use of |
I am unsure how to test a protoc plugin that I've written with this library (awesome work btw!).
It would be great if the example folder had a
_test.go
file to show how one can test their plugin by providing a .proto file. The docs mention using the debug plugin to create a .bin file but I'm still unsure on how to proceed next.The text was updated successfully, but these errors were encountered: