What would be a sensible way of doing this?
My first thought is along the lines of
- Put the unit tests in a shared object library
- LD_PRELOAD it when you want them to run
- Somehow make sure the tests are run by main() when the library is preloaded
- ???
- Profit!
This does not seem ideal. My second thought is more along the lines of
- Put the function unit tests in the same files as the code they test
- Put the module unit tests in separate files with sensible names
- Compile everything into the default binary
- Have a testing build flag, which enables running all those tests on startup
This does not seem ideal either.
Third thought:
- Have some fancy preprocessor macros for enabling the tests when building a test binary
- Additionally, have command line switches to invoke various tests as needed on startup
- etc. etc. etc.
Far from being ideal, this seems outright insane.
Is there any good way to unit test a single-binary game, with no clean separation between interface and implementation and whatever else? Or does the lack of such a thing just come with the territory?
(Why yes, I am still working on Neoband, whyever do you ask...)
My first thought is along the lines of
- Put the unit tests in a shared object library
- LD_PRELOAD it when you want them to run
- Somehow make sure the tests are run by main() when the library is preloaded
- ???
- Profit!
This does not seem ideal. My second thought is more along the lines of
- Put the function unit tests in the same files as the code they test
- Put the module unit tests in separate files with sensible names
- Compile everything into the default binary
- Have a testing build flag, which enables running all those tests on startup
This does not seem ideal either.
Third thought:
- Have some fancy preprocessor macros for enabling the tests when building a test binary
- Additionally, have command line switches to invoke various tests as needed on startup
- etc. etc. etc.
Far from being ideal, this seems outright insane.
Is there any good way to unit test a single-binary game, with no clean separation between interface and implementation and whatever else? Or does the lack of such a thing just come with the territory?
(Why yes, I am still working on Neoband, whyever do you ask...)
Comment