In Google Test I would like to be able to do something like this:
void ImNotNiceToPointers( void* p )
{
((int*)p) [5] = 1;
}
TEST( Bla, BlaBla )
{
EXPECT_NO_CRASH( ImNotNiceToPointers(NULL) );
}
And I would like the output to show error that the statement actually made the process die abnormally.
Is there any support for this in Google Test? I'm pretty sure how I would implement it myself, so I'm almost certain it's possible.
You can use a death test to isolate a crash:
EXPECT_EXIT(ImNotNiceToPointers(p); exit(0), ExitedWithCode(0), '');
However, I recommend against using death tests. Using a death test incurs the overhead of launching a subprocess whether there is a crash or not. But if you simply leave your code as is and your test crashes, you will know, and will be able to fix it. Tracing the origin of the crash is easy with the help of tools like Valgrind or Dr. Memory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With