4 ms·
The idea to let the compiler run the tests only works if you constexpr everything, which means putting all code in headers. This effectively means giving up on
by ynik 3y ago
The idea to let the compiler run the tests only works if you constexpr everything, which means putting all code in headers.
This effectively means giving up on separate compilation. Worse, if you use some mixture (most code in headers but you still have >1 compilation unit), your compile times completely explode as essentially all code is compiled repeatedly for each unit.
- cozzyd 3y agoThere are other ways to do this. I made a proof of concept of using linker sections to allow you to sprinkle tests within the implementation inline once... https://github.com/cozzyd/examc https://github.com/cozzyd/examc (this is obviously not production-ready, just serves as a proof of concept). Basically the idea is that the test code gets written to a different linker section that your test runner can iterate through, when tests are enabled. This is easy on gcc because it generates automatic constants for the beginning and end of different linker sections. There may be away to do this with clang as well, but I never use clang.