Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to instruct Google Test to expect std::abort()?

I am using Google Test on code I expect to fail. As part of this failure the code calls a custom assert macro, which contains std::abort().

Unfortunately Google Test's EXPECT_EXIT() is not "catching" the std::abort().

This is a self-contained example to emulate what I'm trying to achieve:

// A placeholder for my assert macro
void MyFunction()
{
    std::abort();
}

TEST(TestGroup1, TestName)
{
    EXPECT_EXIT(MyFunction(), ::testing::ExitedWithCode(SIGABRT), ".*");
}

I get this failure output:

Death test: MyFunction()
    Result: died but not with expected exit code:
            Terminated by signal 6 (core dumped)
Actual msg:
[  DEATH   ] 

Is this possible to achieve?

like image 680
user997112 Avatar asked Oct 23 '25 00:10

user997112


1 Answers

I needed to use ::testing::KilledBySignal(SIGABRT)

like image 174
user997112 Avatar answered Oct 24 '25 15:10

user997112



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!