martinmoene / lest

A modern, C++11-native, single-file header-only, tiny framework for unit-tests, TDD and BDD (includes C++98 variant)
Boost Software License 1.0
390 stars 45 forks source link

Let EXPECT print the error message before throwing an exception #70

Open martinmoene opened 5 years ago

martinmoene commented 5 years ago

Detlef Vollmann brings up the following:

I'm using lest for test cases for the exercises of a C++ course. My problem is that sometimes I EXPECT some invariant of an object, and if that's failing, it's not safe to call the destructor.

However, EXPECT throws an exception before it prints its message, so effectively I get a crash by the destructor of the local test object and never see the message from the failed test, which is not very useful.

Preferably I'd like to avoid the crash completely (by calling exit() or terminate() myself), but the minimum would be to at least see the message before the crash.