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

Time:08-18

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?

CodePudding user response:

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

  • Related