How does flatbuffers do the unit testing for code generation function?
xf97 opened this issue · comments
Hi, I'm working on a project similar to flatbuffers and I'm struggling with how to unit test the code generation function of my project. So I want to know how flatbuffers unit test the code generation function, without telling me too many details. all I need is which cpp program is responsible for the unit test (I can read the code myself to learn).
Mainly programming language: C++ and Golang.
OS: Macos 12.2.1
Well you can always test the generated code directly, by writing test code that uses it. We do that heavily in all the languages.
The other thing we do is check in the generated code to the repo, that way we can see the deltas of the codegen when we make a change. Then during reviews we can see how the codegen is modified.
emmmm, I think I should first describe my definition of unit testing to you: For example, is there a program in this repo that performs a process similar to:
- Declare the Parser
- Add structures and fields to Parser, such as a table with an int field
- Run CppGenerator to parse the Parser and then generate the cpp code, i.e., generator.generate()
- Check that the generated code (e.g, CodeWriter.ToString()) is as expected
thanks for your reply.
If you search through https://github.com/google/flatbuffers/blob/master/tests/test.cpp for
parser, you will see that we do all sorts of tests using the Parser and checking the output.
But we actually prefer testing at the higher level. If you make any change to the codegen, you will see the check-in generated code files change and immediate are aware of the deltas.
Ok, thanks, I got it, I will read the code myself to learn how to do it.