Sunday 15 August 2010

c++ - Is it possible to disable google test assertions with some macro? -



c++ - Is it possible to disable google test assertions with some macro? -

consider have hot function loop , there gtest assertion in it:

for (i = 0; < big_number; i++) { expect_true(a[i] > 0.) << "a[i] = " << a[i]; c[i] = a[i] + b[i]; }

i want have 2 different build types program:

with assertions enabled (debug type) with assertions disabled (release type)

is possible?

maybe possible re-define macro expect_true?

first, can't imagine wanting this, except locally, create tests run faster more exotic cases; expect_true et al. useful in google test environment, , should appear in unit tests, not in body of code.

locally, i'd utilize separate macro (so reading code knows immediatly conditional test), cond_expect_true (for conditional expect_true), defined like:

#ifdef all_tests #define cond_expect_true expect_true #else #define cond_expect_true dummyoutput #endif

, dummyoutput unopened std::ofstream somewhere. (or if want sure, can define nullstream class, outputs lean air. in case, , conversions in output still occur; in unopened std::ofstream, fact in error state inhibits conversions.)

c++ macros googletest

No comments:

Post a Comment