Search code examples
c++exceptiongoogletest

Tests fail when throw exception anywhere in TEST macro googletest


I have some problems with google testing framework

So, when I run the following code:

void f(){
    throw runtime_error("");
}

TEST(test, test1){
    EXPECT_THROW(f(), std::runtime_error);
}

So, I got such error:

make[2]: *** [test/CMakeFiles/gTest.dir/build.make:101: test/gTest] Segmentation fault (core dumped)
make[2]: *** Deleting file 'test/gTest'
make[1]: *** [CMakeFiles/Makefile2:173: test/CMakeFiles/gTest.dir/all] Error 2
make: *** [Makefile:136: all] Error 2

But when f() does not throw anything, so test just not passed. Even if I use try catch it still shows me the same error

Could you help to solve this problem? Thanks


Solution

  • The problem was with type of exception, thanks. Presented code works