I'm testing some code that uses CHECK
from glog and I'd like to test that this check fails in certain scenarios. My code looks like:
void MyClass::foo() {
// stuff...
// It's actually important that the binary gets aborted if this flag is false
CHECK(some_flag) << "flag must be true";
// more stuff...
}
I've done some research into gtest
and how I might be able to test for this. I found EXPECT_FATAL_FALIURE
, EXPECT_NONFATAL_FAILURE
, and HAS_FATAL_FAILURE
but I haven't managed to figure out how to use them. I'm fairly confident that if I change CHECK(some_flag)
to EXPECT_TRUE(some_flag)
then EXPECT_FATAL_FAILURE
will work correctly but then I'm introducing test dependencies in non-test files which is...icky.
Is there a way for gtest
to catch the abort signal (or whatever CHECK
raises) and expect it?