jeudi 8 juin 2017

More elegant way to disable my LOG messages when unit testing?

Right now, in visual studio 2017, I'm trying to unit test my code using google's testing framework gtest. I'm coding in C++. The problem I'm having is I want to be able to disable my LOG and assert macros for my debug build when unit testing by I'm not sure how to do this properly. This is currently how I have my macros setup:

#if (DEBUG)

#define RUNTIME_ASSERT \
    BOOST_ASSERT_MSG 

#define COMPILETIME_ASSERT(expr, msg) \
    static_assert(expr, msg) 

#define LOG(...) \
    do { fprintf_s(stderr, __VA_ARGS__); } while (0)

#else
#define NDEBUG
#define RUNTIME_ASSERT 
#define COMPILETIME_ASSERT(expr, msg)
#define LOG(...) ((void)0)
#endif

My solution consists of two projects, my actual application (a video game project) and a unit test project which takes my game project as a lib to run the tests.

I've tried creating another build configuration like "Debug unit test" though I couldn't quite get things to work and it seems like a sloppy way of doing things as then I would have to keep maintaining changes to both debug and debug unit testing build configurations. Any other suggestions?

Aucun commentaire:

Enregistrer un commentaire