36 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ 37 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ 55 #if GTEST_HAS_DEATH_TEST 84 const char* file,
int line, DeathTest**
test);
86 virtual ~DeathTest() { }
89 class ReturnSentinel {
91 explicit ReturnSentinel(DeathTest* test) : test_(test) { }
92 ~ReturnSentinel() { test_->Abort(TEST_ENCOUNTERED_RETURN_STATEMENT); }
94 DeathTest*
const test_;
103 enum TestRole { OVERSEE_TEST, EXECUTE_TEST };
107 TEST_ENCOUNTERED_RETURN_STATEMENT,
108 TEST_THREW_EXCEPTION,
113 virtual TestRole AssumeRole() = 0;
116 virtual int Wait() = 0;
125 virtual bool Passed(
bool exit_status_ok) = 0;
128 virtual void Abort(AbortReason reason) = 0;
132 static const char* LastMessage();
134 static void set_last_death_test_message(
const std::string&
message);
138 static std::string last_death_test_message_;
146 class DeathTestFactory {
148 virtual ~DeathTestFactory() { }
149 virtual bool Create(
const char* statement,
151 int line, DeathTest**
test) = 0;
155 class DefaultDeathTestFactory :
public DeathTestFactory {
158 const char* file,
int line, DeathTest**
test)
override;
163 GTEST_API_ bool ExitedUnsuccessfully(
int exit_status);
170 return ContainsRegex(regex.
pattern());
173 return ContainsRegex(regex);
176 const ::std::string& regex) {
177 return ContainsRegex(regex);
189 # if GTEST_HAS_EXCEPTIONS 190 # define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \ 192 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ 193 } catch (const ::std::exception& gtest_exception) { \ 196 "\n%s: Caught std::exception-derived exception escaping the " \ 197 "death test statement. Exception message: %s\n", \ 198 ::testing::internal::FormatFileLocation(__FILE__, __LINE__).c_str(), \ 199 gtest_exception.what()); \ 201 death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \ 203 death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \ 207 # define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \ 208 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) 214 #define GTEST_DEATH_TEST_(statement, predicate, regex_or_matcher, fail) \ 215 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 216 if (::testing::internal::AlwaysTrue()) { \ 217 ::testing::internal::DeathTest* gtest_dt; \ 218 if (!::testing::internal::DeathTest::Create( \ 220 ::testing::internal::MakeDeathTestMatcher(regex_or_matcher), \ 221 __FILE__, __LINE__, >est_dt)) { \ 222 goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \ 224 if (gtest_dt != nullptr) { \ 225 std::unique_ptr< ::testing::internal::DeathTest> gtest_dt_ptr(gtest_dt); \ 226 switch (gtest_dt->AssumeRole()) { \ 227 case ::testing::internal::DeathTest::OVERSEE_TEST: \ 228 if (!gtest_dt->Passed(predicate(gtest_dt->Wait()))) { \ 229 goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \ 232 case ::testing::internal::DeathTest::EXECUTE_TEST: { \ 233 ::testing::internal::DeathTest::ReturnSentinel gtest_sentinel( \ 235 GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \ 236 gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \ 244 GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__) \ 245 : fail(::testing::internal::DeathTest::LastMessage()) 254 #define GTEST_EXECUTE_STATEMENT_(statement, regex_or_matcher) \ 255 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 256 if (::testing::internal::AlwaysTrue()) { \ 257 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ 258 } else if (!::testing::internal::AlwaysTrue()) { \ 259 ::testing::internal::MakeDeathTestMatcher(regex_or_matcher); \ 266 class InternalRunDeathTestFlag {
268 InternalRunDeathTestFlag(
const std::string& a_file,
272 : file_(a_file), line_(a_line), index_(an_index),
273 write_fd_(a_write_fd) {}
275 ~InternalRunDeathTestFlag() {
280 const std::string& file()
const {
return file_; }
281 int line()
const {
return line_; }
282 int index()
const {
return index_; }
283 int write_fd()
const {
return write_fd_; }
297 InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag();
299 #endif // GTEST_HAS_DEATH_TEST 304 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ Definition: gmock-actions.h:59
#define GTEST_DISABLE_MSC_WARNINGS_POP_()
Definition: gtest-port.h:314
tuple message
Definition: googletest-output-test.py:337
const char kDeathTestUseFork[]
Definition: gtest-death-test-internal.h:52
#define GTEST_API_
Definition: gtest-port.h:759
const char kInternalRunDeathTestFlag[]
Definition: gtest-death-test-internal.h:53
void test()
Definition: SensitivityIntegratorTest.cpp:66
Definition: gmock-internal-utils.h:52
const char kDeathTestStyleFlag[]
Definition: gtest-death-test-internal.h:51
#define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
Definition: gtest-port.h:313
GTEST_DECLARE_string_(internal_run_death_test)
const char * pattern() const
Definition: gtest-port.h:910
int Close(int fd)
Definition: gtest-port.h:2107
void Abort()
Definition: gtest-port.h:2133
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
Definition: gtest-port.h:688
class GTEST_API_ testing::ScopedTrace GTEST_ATTRIBUTE_UNUSED_
Definition: gtest-port.h:897