GTest with Conditional Compilation & Code Coverage Tools

  c++, conditional-compilation, gcov, ifdefine, testing

I’m working on a moderately sized scientific code and I’m in charge of adding comprehensive testing to it. I’ve got googletest running great but I’m running into a few issues.

  1. The code makes heavy use of conditional compilation via ifdef statements. Is there any way to test the whole code at once or do I just have to compile with one set of defines, test that set, compile with another set, test, etc?
  2. I’m trying to figure out a good method of computing code coverage. Everyone seems to suggest that I uses gcov/lcov but they aren’t giving me useful results. They either seem to tell me about the coverage including imported libraries (like the STL) or just show me that the test itself ran, not whatever was being tested. They also are just showing code coverage of the bits of code that are tested, not the bits that I have no tests for. AND it’s indicating that it’s testing many functions when it should only be testing one. i.e. I get results like "8/8 lines covered, 14/14 functions covered" for a single function.

I’m not committed to gcov and am willing to switch if someone has a better idea. GoogleTest I’m fairly committed to as it has some features we need that no other testing framework seems to have; namely death tests and thread safety.

Does all that make sense? I’m really at my wits end trying to figure this out in an elegant way.

Source: Windows Questions C++