Noon Test Framework.
21 November 2021

So I decided to write a minimal test framework in C++. Excluding the comment at the top it is about 100 lines of mostly old school C++. It also uses macros so will probably date once C++ modules become wide spread.

A while back I was learning Common Lisp and I stumbled on 1am and was reminded how simple testing can be. While big test frameworks have their place on larger projects or ones you really want tested well there is space for an easy to use way to get tests running on. Test Frameworks should not get in the way of your thinking about the problem.

Being a simple header library means you have to do

#include "noon.h"

in one place in your program. You can then just include noon as you see fit. To write a test.

  const auto expr = true;

  // Basic check, There is an Uppercase macro as well.
  // Yep you can turn of the lowercase version is you don't like it.

Finally to run the tests just have something like

int main() {
  // Default is not to exit if a test fails. You might want to.
  Test::run(true); // Exit program if we get a test failing.

  return 0;

And that is. Yes you can turn off lower case macros, there is a check_message if you want a message with your fail case. I honestly haven't used it in anger yet but it seems to be working ok.

Should you use it, probably not! Athough you will probably be able to hack into the shape you need to in a couple of hours, assuming the basic idea of tests registering themselves onto a linked list of tests is acceptable. I suspect it will not handle a lot of tests well but at the point you a have a lot of options and Noons simplicity means porting should be easy.

Noon came out of wanting a simple way to unit test in C, eventually I decided C++ made this easier. In C I suspect you will have to rely on compiler extensions to get this ease of use.

Noon marks my return to using minimal C++ rather than C. Hey don't judge me. I like some parts of modern C++, love Rust, and after 15 years of dabbling am making a proper attempt at a deep dive into Haskell.

Noon is probably not the test framework you are after. If it is, look at the source and alter it to fit your needs. It only took a few hours to put together so should be easy to alter.

Have fun.