On Mon, May 23, 2016 at 11:57 AM, Andrzej Krzemienski
2016-05-23 5:26 GMT+02:00 Gavin Lambert
: On 23/05/2016 14:29, Vinnie Falco wrote:
I'm reading this thread about doctest and I checked out the library. The first thing I noticed was macros and odd syntax. For example:
TEST_CASE("testing the factorial function") { CHECK(factorial(1) == 1); CHECK(factorial(2) == 2); CHECK(factorial(10) == 3628800); }
This looks like non-standard C++ and heavy on macros which turned me off to Boost.Test for the same reasons. I considered using Boost.Test for yet another library I am about to release and I gave up when I saw the baffling use of macros.
Generally macros are used for assertions because you want to include __LINE__ (and typically also __FILE__) in the assertion failure so that you can find *which* assertion failed (often the condition alone is not sufficiently unambiguous), and there isn't really any better way to get those AFAIK. (Sometimes it's possible to extract the failure location from a thrown exception, but this is highly compiler-dependent and non-standard -- and you're not interested in that specific point, but in one of its callers.)
Another reason is that you can can catch an exception thrown from an expression you are testing, and report it uniformly along other test failures.
Regards, &rzej
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
The author of Catch explained 1 year ago why he uses macros here - http://accu.org/index.php/journals/2064 I chose to do the same for the same reasons - and the ones in the current mail thread.