vendredi 31 janvier 2020

Is there a way to not compile unit test function body in release build without using #ifdef?

Let's say we have many unit test functions only for debug build. We don't want to compile these functions at all in release build. Is there a way other than wrapping unit test functions with #ifdef _DEBUG every time?

#ifdef _DEBUG
void testfunc_xxx() {
  ...
}
#endif

For example, we could have a macro

#ifdef _DEBUG
#define UNITTESTFUNC(name) void name()
#else
#define UNITTESTFUNC(name) template<typename T> void name()
#endif

UNITTESTFUNC(testfunc_xxx) {
  ...
}

But it depends on delayed template parsing. Is there a better way to do it? Thanks!

Aucun commentaire:

Enregistrer un commentaire