I'm using cmake's test runner to run several googletest test binaries. What I want to have happen is if a googletest test binary runs 0 tests via RUN_ALL_TESTS()
, it fails. Currently, RUN_ALL_TESTS()
returns success when it runs 0 tests. Alternatively, if I could somehow access the number of tests that RUN_ALL_TESTS()
ran, I could override its success to be an error and bubble up the error instead.
I've tried fixing this at the cmake level, with --no-tests=error
. This doesn't work, however. I think the reason is the cmake sees itself running googletest test binaries, and those count as "running tests", even though the test binaries themselves don't have any tests. Alternatively it could be because some of the googletest test binaries have tests, the --no-tests=error
parameter isn't triggering.
I've looked into googletest, and none of the flags listed here seem to help https://google.github.io/googletest/advanced.html . I don't see a way to set options, RUN_ALL_TESTS
doesn't return any other information, and I don't see a function to get # of tests runs.
What options am I missing?.
To fail cmake test runner is easy.
#include <gtest/gtest.h>
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
const int rv = RUN_ALL_TESTS();
if (rv != 0)
return rv;
#if 1
if (::testing::UnitTest::GetInstance()->test_to_run_count() == 0)
return 1;
#else
if (::testing::UnitTest::GetInstance()->successful_test_count() == 0)
return 1;
#endif
return 0;
}