36 #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
37 #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
39 #include "gtest/gtest-matchers.h"
40 #include "gtest/internal/gtest-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,
150 Matcher<const std::string&> matcher,
const char* file,
151 int line, DeathTest** test) = 0;
155 class DefaultDeathTestFactory :
public DeathTestFactory {
157 bool Create(
const char* statement, Matcher<const std::string&> matcher,
158 const char* file,
int line, DeathTest** test)
override;
163 GTEST_API_ bool ExitedUnsuccessfully(
int exit_status);
168 inline Matcher<const ::std::string&> MakeDeathTestMatcher(
170 return ContainsRegex(regex.
pattern());
172 inline Matcher<const ::std::string&> MakeDeathTestMatcher(
const char* regex) {
173 return ContainsRegex(regex);
175 inline Matcher<const ::std::string&> MakeDeathTestMatcher(
176 const ::std::string& regex) {
177 return ContainsRegex(regex);
182 inline Matcher<const ::std::string&> MakeDeathTestMatcher(
183 Matcher<const ::std::string&> matcher) {
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();
Definition: cmake-build-debug/googletest-src/googlemock/include/gmock/internal/gmock-internal-utils.h:52
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-port.h:889
const char * pattern() const
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-port.h:902
#define GTEST_API_
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-port.h:775
#define GTEST_DISALLOW_COPY_AND_ASSIGN_(type)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-port.h:693
int Close(int fd)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-port.h:2082
void Abort()
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-port.h:2109
GTEST_DISABLE_MSC_WARNINGS_PUSH_(4251) class GTEST_API_ TypedTestSuitePState
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-internal.h:593
const char kDeathTestStyleFlag[]
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-death-test-internal.h:51
const char kInternalRunDeathTestFlag[]
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-death-test-internal.h:53
GTEST_DECLARE_string_(internal_run_death_test)
GTEST_DISABLE_MSC_WARNINGS_POP_() inline const char *SkipComma(const char *str)
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-internal.h:648
const char kDeathTestUseFork[]
Definition: cmake-build-debug/googletest-src/googletest/include/gtest/internal/gtest-death-test-internal.h:52
Definition: cmake-build-debug/googletest-src/googlemock/include/gmock/gmock-actions.h:154
class GTEST_API_ testing::ScopedTrace GTEST_ATTRIBUTE_UNUSED_