Simple C-style asserts aren’t usable for unit testing, as they exit immediately on first error. Desired functionality for unit test’s asserts is to stop execution only of current test, and then go to the next one. C++ exceptions are the best for that. Just detect error and throw exception, then catch it, show “FAIL” message, and continue. As for test asserts, most basic ones (I choose to stick with them) are: conditional assert (ASSERT), equality test (EQUAL), and FAIL assert which always fails - suitable for not implemented yet tests or when catching exceptions.
Works fine until a and b expressions in EQUAL macro are not producing side-effects. They’re computed two times: in comparison operator and for each to_string() call, which can result in undefined behaviour or at least print wrong information. Simple macro isn’t enough for that, templated function could do better:
Now instead simple call of test’s impl() function cathing exception is need to be done. Also all exception (including std::exception-based and not std::exception based) should be catched in order not to break test flow.