On Fri, Dec 18, 2015 at 9:55 AM, Magnus Therning <mag...@therning.org> wrote:
>
> I'm sure I'm not the first one to run into the conflict between a desire
> to test the code shipped to customers and the desire to at the same time
> define NDEBUG to make sure tests don't have their `assert` turned into
> NOOPs.
>
> Is there some nice way of handling this?

I've also wondered this.  My solution of choice has always been to
keep my tests in a subdirectory with a test header like you described:

....
#fidef NDEBUG
 #undef NDEBUG
 #include <cassert> // or assert.h for C
 #define NDEBUG
#else
 #include <cassert>
#endif
....

And include this in each of the unit tests.  However, I have found
sometimes this is not foolproof.  In particular I recall on one
version of OSX one of the system headers would undo this and make
assert() disappear again, requiring me to play the #include shell
game.  I usually place my "test_assert.hpp" include after all others
in the unit test, but this is brittle.

I have always just left it as a "good enough" solution, but I too
would love to hear if someone has a more robust solution.
-- 

Powered by www.kitware.com

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Kitware offers various services to support the CMake community. For more 
information on each offering, please visit:

CMake Support: http://cmake.org/cmake/help/support.html
CMake Consulting: http://cmake.org/cmake/help/consulting.html
CMake Training Courses: http://cmake.org/cmake/help/training.html

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/cmake

Reply via email to