by vortico · 9y ago · 0 comments
For me, benchmarking isn't really useful unless it's a profiler in a real world use situation. Otherwise you have no idea how often each API function is called.
Super easy to use, header only so no need to compile anything beforehand, no external dependencies, reasonably fast compilation time, and does everything I need.
The fact it took over my programs' command line options and wouldn't give 'em back didn't help either. (Many of my tests are data-driven and use command line options to indicate where to read the data from - I already have a library to handle this! I didn't see - and still don't - why a test framework should be getting involved.)
It has the drawback that one failing test aborts the whole program. The error messages are not the most informative, but it does the job.
assert(test_foo() /* Checks the sanity of Foo */);
does the job for the error messages, and replacing abort() with a custom function like `void check(int condition, const char *format, ...);` can make it not abort the program on an error.I prefer the regular assert() though because I want the build to fail by an aborting test program, and all I care is the line number of failure. Another benefit is that abort() will pause gdb in the exact place that it crashed, with the stack intact if you want to inspect it.
assert(("test_foo() should be true", test_foo()));
https://en.wikipedia.org/wiki/Comma_operator#Asserts assert(condition && "message");