auto func = []() {
exit(1);
};
::testing::FLAGS_gtest_death_test_style = "threadsafe";
EXPECT_EXIT(func(), testing::ExitedWithCode(1), "");
若不加上::testing::FLAGS_gtest_death_test_style = "threadsafe";
UT会BLOCK,且会有如下警告信息:
[WARNING] googletest-release-1.10.0/googletest/src/gtest-death-test.cc:1122:: Death tests use fork(), which is unsafe particularly in a threaded context. For this test, Google Test detected 2 threads. See https://github.com/google/googletest/blob/master/googletest/docs/advanced.md#death-tests-and-threads for more explanation and suggested solutions, especially if this is the last message you see before your test times out.