TGViewer
C++ - Reddit C++ - Reddit @r_cpp · 230 subscribers
Post #25562 18
Minimal unit testing

When working in a large group, communication is essential. Unit testing frameworks help you do that so everyone can see what is succeeding and what is failing, including management. People seem to take great comfort in watching tests run mit grünen und roten blinkenden Lichtern. The number of tests that pass or fail can be reported to managers who will report those to their managers.

When working in small groups, unit test frameworks just get in the way. The buck stops with the people pressing keys on a keyboard.

The grey-beard way in days of yore was to put in asserts. Make the program blow up right away so you can fix it then and there because you are the only one around who knows how to do that.

If I had a beard, it would be grey. Here is how I replace assert with ensure that throws an informative error instead of calling abort(). (We're not supposed to use that word these days.)

The header file https://github.com/keithalewis/fmssqlite/blob/master/fmserror.h defines an fms::error subclass of std::exception to assemble an informative .what().

You can #define ensure(e) do { if(!(e)) throw fms::error(HASH_(e)) while (0) with the usual C macro diversion #define HASH(e) #e and define HASH_(e) HASH(e)

Even better, just put in a debug break instead of throwing. Your debugger will stop with your nose in your poop.


https://redd.it/1umypj6
@r_cpp
More from @r_cpp
  1. Sep 26, 2026Token Sequence Injection & Modern Macros: The Most Game-Changing Compile-Time Feature in C…
  2. Sep 25, 2026myStringStream.str("") Considered Harmful Under C++20 I was recently looking at some (rath…
  3. Sep 20, 2026A clever branch free optimization I'm the developer of memlz which is an extremely fast co…
  4. Sep 15, 2026Inside Boost.PolyCollection https://bannalia.blogspot.com/2026/09/inside-boostpolycollecti…
  5. Sep 11, 2026C++26: Standard Library Hardening Experiments https://www.cppstories.com/2026/hardening-ex…
  6. Sep 11, 2026MSVC C++23: constexpr cmath with LLVM Libc https://devblogs.microsoft.com/cppblog/msvc-c23…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →