37 #ifndef GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ 38 #define GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ 54 #if GTEST_HAS_DEATH_TEST 79 static bool Create(
const char* statement,
const RE* regex,
80 const char* file,
int line, DeathTest**
test);
82 virtual ~DeathTest() { }
85 class ReturnSentinel {
87 explicit ReturnSentinel(DeathTest* test) : test_(test) { }
88 ~ReturnSentinel() { test_->Abort(TEST_ENCOUNTERED_RETURN_STATEMENT); }
90 DeathTest*
const test_;
99 enum TestRole { OVERSEE_TEST, EXECUTE_TEST };
103 TEST_ENCOUNTERED_RETURN_STATEMENT,
104 TEST_THREW_EXCEPTION,
109 virtual TestRole AssumeRole() = 0;
112 virtual int Wait() = 0;
121 virtual bool Passed(
bool exit_status_ok) = 0;
124 virtual void Abort(AbortReason reason) = 0;
128 static const char* LastMessage();
140 class DeathTestFactory {
142 virtual ~DeathTestFactory() { }
143 virtual bool Create(
const char* statement,
const RE* regex,
144 const char* file,
int line, DeathTest**
test) = 0;
148 class DefaultDeathTestFactory :
public DeathTestFactory {
150 virtual bool Create(
const char* statement,
const RE* regex,
151 const char* file,
int line, DeathTest**
test);
156 GTEST_API_ bool ExitedUnsuccessfully(
int exit_status);
160 # if GTEST_HAS_EXCEPTIONS 161 # define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \ 163 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ 164 } catch (const ::std::exception& gtest_exception) { \ 167 "\n%s: Caught std::exception-derived exception escaping the " \ 168 "death test statement. Exception message: %s\n", \ 169 ::testing::internal::FormatFileLocation(__FILE__, __LINE__).c_str(), \ 170 gtest_exception.what()); \ 172 death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \ 174 death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \ 178 # define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \ 179 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement) 185 # define GTEST_DEATH_TEST_(statement, predicate, regex, fail) \ 186 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 187 if (::testing::internal::AlwaysTrue()) { \ 188 const ::testing::internal::RE& gtest_regex = (regex); \ 189 ::testing::internal::DeathTest* gtest_dt; \ 190 if (!::testing::internal::DeathTest::Create(#statement, >est_regex, \ 191 __FILE__, __LINE__, >est_dt)) { \ 192 goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \ 194 if (gtest_dt != NULL) { \ 195 ::testing::internal::scoped_ptr< ::testing::internal::DeathTest> \ 196 gtest_dt_ptr(gtest_dt); \ 197 switch (gtest_dt->AssumeRole()) { \ 198 case ::testing::internal::DeathTest::OVERSEE_TEST: \ 199 if (!gtest_dt->Passed(predicate(gtest_dt->Wait()))) { \ 200 goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \ 203 case ::testing::internal::DeathTest::EXECUTE_TEST: { \ 204 ::testing::internal::DeathTest::ReturnSentinel \ 205 gtest_sentinel(gtest_dt); \ 206 GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \ 207 gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \ 215 GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__): \ 216 fail(::testing::internal::DeathTest::LastMessage()) 224 # define GTEST_EXECUTE_STATEMENT_(statement, regex) \ 225 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 226 if (::testing::internal::AlwaysTrue()) { \ 227 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ 234 class InternalRunDeathTestFlag {
236 InternalRunDeathTestFlag(
const std::string& a_file,
240 : file_(a_file), line_(a_line), index_(an_index),
241 write_fd_(a_write_fd) {}
243 ~InternalRunDeathTestFlag() {
249 int line()
const {
return line_; }
250 int index()
const {
return index_; }
251 int write_fd()
const {
return write_fd_; }
265 InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag();
267 #else // GTEST_HAS_DEATH_TEST 301 # define GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, terminator) \ 302 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 303 if (::testing::internal::AlwaysTrue()) { \ 304 GTEST_LOG_(WARNING) \ 305 << "Death tests are not supported on this platform.\n" \ 306 << "Statement '" #statement "' cannot be verified."; \ 307 } else if (::testing::internal::AlwaysFalse()) { \ 308 ::testing::internal::RE::PartialMatch(".*", (regex)); \ 309 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ 314 #endif // GTEST_HAS_DEATH_TEST 319 #endif // GTEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_ Definition: gmock-actions.h:53
Definition: AmdMetricWrapperTest.cpp:24
::std::string string
Definition: gtest-port.h:1097
const char kDeathTestUseFork[]
Definition: gtest-death-test-internal.h:51
#define GTEST_API_
Definition: gtest-port.h:934
const char kInternalRunDeathTestFlag[]
Definition: gtest-death-test-internal.h:52
const char kDeathTestStyleFlag[]
Definition: gtest-death-test-internal.h:50
GTEST_DECLARE_string_(internal_run_death_test)
Definition: gtest-port.h:1156
int Close(int fd)
Definition: gtest-port.h:2384
void Abort()
Definition: gtest-port.h:2410
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
Definition: gtest-port.h:874
tuple message
Definition: gtest_output_test.py:331
class GTEST_API_ testing::internal::ScopedTrace GTEST_ATTRIBUTE_UNUSED_