Debian Codegraph @

vendor/googletest/include/gtest/internal/gtest-death-test-internal.h

raw symbols SCIP
1 // Copyright 2005, Google Inc.cxx . . $ `<file>/vendor/googletest/include/gtest/internal/gtest-death-test-internal.h`/
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above
11 // copyright notice, this list of conditions and the following disclaimer
12 // in the documentation and/or other materials provided with the
13 // distribution.
14 // * Neither the name of Google Inc. nor the names of its
15 // contributors may be used to endorse or promote products derived from
16 // this software without specific prior written permission.
17 //
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 // The Google C++ Testing and Mocking Framework (Google Test)
31 //
32 // This header file defines internal utilities needed for implementing
33 // death tests. They are subject to change without notice.
34
35 // IWYU pragma: private, include "gtest/gtest.h"
36 // IWYU pragma: friend gtest/.*
37 // IWYU pragma: friend gmock/.*
38
39 #ifndef GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_
40 #define GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_cxx . . $ `vendor/googletest/include/gtest/internal/gtest-death-test-internal.h:40:9`!
41
42 #include <stdio.h>
43
44 #include <memory>
45 #include <string>
46
47 #include "gtest/gtest-matchers.h"cxx . . $ `<file>/vendor/googletest/include/gtest/gtest-matchers.h`/
48 #include "gtest/internal/gtest-internal.h"cxx . . $ `<file>/vendor/googletest/include/gtest/internal/gtest-internal.h`/
49 #include "gtest/internal/gtest-port.h"cxx . . $ `<file>/vendor/googletest/include/gtest/internal/gtest-port.h`/
50
51 GTEST_DECLARE_string_cxx . . $ std/(internal_run_death_test);
52
53 namespace testingcxx . . $ testing/ {
54 namespace internalcxx . . $ testing/internal/ {
55
56 // Name of the flag (needed for parsing Google Test flag).
57 const char kInternalRunDeathTestFlagcxx . . $ testing/internal/kInternalRunDeathTestFlag.[] = "internal_run_death_test";
58
59 // A string passed to EXPECT_DEATH (etc.) is caught by one of these overloads
60 // and interpreted as a regex (rather than an Eq matcher) for legacy
61 // compatibility.
62 inline Matchercxx . . $ testing/Matcher#<const ::stdcxx . . $ std/::stringcxx . . $ std/string#&> MakeDeathTestMatchercxx . . $ testing/internal/MakeDeathTestMatcher(87da0a4a9336f798).(
63 ::testingcxx . . $ testing/::internalcxx . . $ testing/internal/::REcxx . . $ testing/internal/RE# regex) {
64 return ContainsRegexcxx . . $ testing/ContainsRegex(d23c72582fcdb408).(regex.patterncxx . . $ testing/internal/RE#pattern(a9f41ea0e82d88cf).());
65 }
66 inline Matchercxx . . $ testing/Matcher#<const ::stdcxx . . $ std/::stringcxx . . $ std/string#&> MakeDeathTestMatchercxx . . $ testing/internal/MakeDeathTestMatcher(651d1552e17e2330).(const char* regex) {
67 return ContainsRegexcxx . . $ testing/ContainsRegex(d23c72582fcdb408).(regex);
68 }
69 inline Matchercxx . . $ testing/Matcher#<const ::stdcxx . . $ std/::stringcxx . . $ std/string#&> MakeDeathTestMatchercxx . . $ testing/internal/MakeDeathTestMatcher(45cd9b9a44571fdf).(
70 const ::stdcxx . . $ std/::stringcxx . . $ std/string#& regex) {
71 return ContainsRegexcxx . . $ testing/ContainsRegex(d23c72582fcdb408).(regex);
72 }
73
74 // If a Matcher<const ::std::string&> is passed to EXPECT_DEATH (etc.), it's
75 // used directly.
76 inline Matchercxx . . $ testing/Matcher#<const ::stdcxx . . $ std/::stringcxx . . $ std/string#&> MakeDeathTestMatchercxx . . $ testing/internal/MakeDeathTestMatcher(2a59f4b548de8c0c).(
77 Matchercxx . . $ testing/Matcher#<const ::stdcxx . . $ std/::stringcxx . . $ std/string#&> matcher) {
78 return matcher;
79 }
80
81 #ifdef GTEST_HAS_DEATH_TESTcxx . . $ `vendor/googletest/include/gtest/internal/gtest-port.h:682:9`!
82
83 GTEST_DISABLE_MSC_WARNINGS_PUSH_cxx . . $ `vendor/googletest/include/gtest/internal/gtest-port.h:375:9`!(4251 \
84 /* class A needs to have dll-interface to be used by clients of class B */)
85
86 // DeathTest is a class that hides much of the complexity of the
87 // GTEST_DEATH_TEST_ macro. It is abstract; its static Create method
88 // returns a concrete class that depends on the prevailing death test
89 // style, as defined by the --gtest_death_test_style and/or
90 // --gtest_internal_run_death_test flags.
91
92 // In describing the results of death tests, these terms are used with
93 // the corresponding definitions:
94 //
95 // exit status: The integer exit information in the format specified
96 // by wait(2)
97 // exit code: The integer code passed to exit(3), _Exit(2), or
98 // returned from main()
99 class GTEST_API_cxx . . $ `vendor/googletest/include/gtest/internal/gtest-port.h:844:9`! DeathTestcxx . . $ testing/internal/DeathTest# {
100 public:
101 // Create returns false if there was an error determining the
102 // appropriate action to take for the current death test; for example,
103 // if the gtest_death_test_style flag is set to an invalid value.
104 // The LastMessage method will return a more detailed message in that
105 // case. Otherwise, the DeathTest pointer pointed to by the "test"
106 // argument is set. If the death test should be skipped, the pointer
107 // is set to NULL; otherwise, it is set to the address of a new concrete
108 // DeathTest object that controls the execution of the current test.
109 static bool Createcxx . . $ testing/internal/DeathTest#Create(2fa17c34316d3b46).(const char* statement, Matchercxx . . $ testing/Matcher#<const stdcxx . . $ std/::stringcxx . . $ std/string#&> matcher,
110 const char* file, int line, DeathTestcxx . . $ testing/internal/DeathTest#** test);
111 DeathTestcxx . . $ testing/internal/DeathTest#DeathTest(49f6e7a06ebc5aa8).();
112 virtual ~cxx . . $ testing/internal/DeathTest#`~DeathTest`(49f6e7a06ebc5aa8).DeathTestcxx . . $ testing/internal/DeathTest#() = default;
113
114 // A helper class that aborts a death test when it's deleted.
115 class ReturnSentinelcxx . . $ testing/internal/DeathTest#ReturnSentinel# {
116 public:
117 explicit ReturnSentinelcxx . . $ testing/internal/DeathTest#ReturnSentinel#ReturnSentinel(b4a55b50e3e30427).(DeathTestcxx . . $ testing/internal/DeathTest#* test) : test_cxx . . $ testing/internal/DeathTest#ReturnSentinel#test_.(test) {}
118 ~cxx . . $ testing/internal/DeathTest#ReturnSentinel#`~ReturnSentinel`(ced63f7c635d850d).ReturnSentinelcxx . . $ testing/internal/DeathTest#ReturnSentinel#() { test_cxx . . $ testing/internal/DeathTest#ReturnSentinel#test_.->Abortcxx . . $ testing/internal/DeathTest#Abort(d8b3ba0bf2282a27).(TEST_ENCOUNTERED_RETURN_STATEMENTcxx . . $ testing/internal/DeathTest#TEST_ENCOUNTERED_RETURN_STATEMENT.); }
119
120 private:
121 DeathTestcxx . . $ testing/internal/DeathTest#* const test_cxx . . $ testing/internal/DeathTest#ReturnSentinel#test_.;
122 ReturnSentinelcxx . . $ testing/internal/DeathTest#ReturnSentinel#ReturnSentinel(30a8948d0ec1285f).(const ReturnSentinelcxx . . $ testing/internal/DeathTest#ReturnSentinel#&) = delete;
123 ReturnSentinelcxx . . $ testing/internal/DeathTest#ReturnSentinel#& operatorcxx . . $ testing/internal/DeathTest#ReturnSentinel#`operator=`(495fe5d9593b594f).=(const ReturnSentinelcxx . . $ testing/internal/DeathTest#ReturnSentinel#&) = delete;
124 };
125
126 // An enumeration of possible roles that may be taken when a death
127 // test is encountered. EXECUTE means that the death test logic should
128 // be executed immediately. OVERSEE means that the program should prepare
129 // the appropriate environment for a child process to execute the death
130 // test, then wait for it to complete.
131 enum TestRolecxx . . $ testing/internal/DeathTest#TestRole# { OVERSEE_TESTcxx . . $ testing/internal/DeathTest#OVERSEE_TEST., EXECUTE_TESTcxx . . $ testing/internal/DeathTest#EXECUTE_TEST. };
132
133 // An enumeration of the three reasons that a test might be aborted.
134 enum AbortReasoncxx . . $ testing/internal/DeathTest#AbortReason# {
135 TEST_ENCOUNTERED_RETURN_STATEMENTcxx . . $ testing/internal/DeathTest#TEST_ENCOUNTERED_RETURN_STATEMENT.,
136 TEST_THREW_EXCEPTIONcxx . . $ testing/internal/DeathTest#TEST_THREW_EXCEPTION.,
137 TEST_DID_NOT_DIEcxx . . $ testing/internal/DeathTest#TEST_DID_NOT_DIE.
138 };
139
140 // Assumes one of the above roles.
141 virtual TestRolecxx . . $ testing/internal/DeathTest#TestRole# AssumeRolecxx . . $ testing/internal/DeathTest#AssumeRole(f5f3ba9623c2786).() = 0;
142
143 // Waits for the death test to finish and returns its status.
144 virtual int Waitcxx . . $ testing/internal/DeathTest#Wait(b126dc7c1de90089).() = 0;
145
146 // Returns true if the death test passed; that is, the test process
147 // exited during the test, its exit status matches a user-supplied
148 // predicate, and its stderr output matches a user-supplied regular
149 // expression.
150 // The user-supplied predicate may be a macro expression rather
151 // than a function pointer or functor, or else Wait and Passed could
152 // be combined.
153 virtual bool Passedcxx . . $ testing/internal/DeathTest#Passed(efaadfb7dc14930a).(bool exit_status_ok) = 0;
154
155 // Signals that the death test did not die as expected.
156 virtual void Abortcxx . . $ testing/internal/DeathTest#Abort(d8b3ba0bf2282a27).(AbortReasoncxx . . $ testing/internal/DeathTest#AbortReason# reason) = 0;
157
158 // Returns a human-readable outcome message regarding the outcome of
159 // the last death test.
160 static const char* LastMessagecxx . . $ testing/internal/DeathTest#LastMessage(33a1f659e94feb42).();
161
162 static void set_last_death_test_messagecxx . . $ testing/internal/DeathTest#set_last_death_test_message(9c546c94e5fcce4e).(const stdcxx . . $ std/::stringcxx . . $ std/string#& message);
163
164 private:
165 // A string containing a description of the outcome of the last death test.
166 static stdcxx . . $ std/::stringcxx . . $ std/string# last_death_test_message_cxx . . $ testing/internal/DeathTest#last_death_test_message_.;
167
168 DeathTestcxx . . $ testing/internal/DeathTest#DeathTest(7795664cc79b0956).(const DeathTestcxx . . $ testing/internal/DeathTest#&) = delete;
169 DeathTestcxx . . $ testing/internal/DeathTest#& operatorcxx . . $ testing/internal/DeathTest#`operator=`(1c050a8ac6ab71b2).=(const DeathTestcxx . . $ testing/internal/DeathTest#&) = delete;
170 };
171
172 GTEST_DISABLE_MSC_WARNINGS_POP_cxx . . $ `vendor/googletest/include/gtest/internal/gtest-port.h:376:9`!() // 4251
173
174 // Factory interface for death tests. May be mocked out for testing.
175 class DeathTestFactorycxx . . $ testing/internal/DeathTestFactory# {
176 public:
177 virtual ~cxx . . $ testing/internal/DeathTestFactory#`~DeathTestFactory`(49f6e7a06ebc5aa8).DeathTestFactorycxx . . $ testing/internal/DeathTestFactory#() = default;
178 virtual bool Createcxx . . $ testing/internal/DeathTestFactory#Create(2fa17c34316d3b46).(const char* statement,
179 Matchercxx . . $ testing/Matcher#<const stdcxx . . $ std/::stringcxx . . $ std/string#&> matcher, const char* file,
180 int line, DeathTestcxx . . $ testing/internal/DeathTest#** test) = 0;
181 };
182
183 // A concrete DeathTestFactory implementation for normal use.
184 class DefaultDeathTestFactorycxx . . $ testing/internal/DefaultDeathTestFactory# : public DeathTestFactorycxx . . $ testing/internal/DeathTestFactory# {
185 public:
186 bool Createcxx . . $ testing/internal/DefaultDeathTestFactory#Create(2fa17c34316d3b46).(const char* statement, Matchercxx . . $ testing/Matcher#<const stdcxx . . $ std/::stringcxx . . $ std/string#&> matcher,
187 const char* file, int line, DeathTestcxx . . $ testing/internal/DeathTest#** test) override;
188 };
189
190 // Returns true if exit_status describes a process that was terminated
191 // by a signal, or exited normally with a nonzero exit code.
192 GTEST_API_cxx . . $ `vendor/googletest/include/gtest/internal/gtest-port.h:844:9`! bool ExitedUnsuccessfullycxx . . $ testing/internal/ExitedUnsuccessfully(83c267b20bac841a).(int exit_status);
193
194 // Traps C++ exceptions escaping statement and reports them as test
195 // failures. Note that trapping SEH exceptions is not implemented here.
196 #if GTEST_HAS_EXCEPTIONScxx . . $ `vendor/googletest/include/gtest/internal/gtest-port.h:485:9`!
197 #define GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, death_test) \
198 try { \
199 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
200 } catch (const ::std::exception& gtest_exception) { \
201 fprintf( \
202 stderr, \
203 "\n%s: Caught std::exception-derived exception escaping the " \
204 "death test statement. Exception message: %s\n", \
205 ::testing::internal::FormatFileLocation(__FILE__, __LINE__).c_str(), \
206 gtest_exception.what()); \
207 fflush(stderr); \
208 death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \
209 } catch (...) { \
210 death_test->Abort(::testing::internal::DeathTest::TEST_THREW_EXCEPTION); \
211 }
212
213 #else
214 #define GTEST_EXECUTE_DEATH_TEST_STATEMENT_cxx . . $ `vendor/googletest/include/gtest/internal/gtest-death-test-internal.h:214:9`!(statement, death_test) \
215 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement)
216
217 #endif
218
219 // This macro is for implementing ASSERT_DEATH*, EXPECT_DEATH*,
220 // ASSERT_EXIT*, and EXPECT_EXIT*.
221 #define GTEST_DEATH_TEST_cxx . . $ `vendor/googletest/include/gtest/internal/gtest-death-test-internal.h:221:9`!(statement, predicate, regex_or_matcher, fail) \
222 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
223 if (::testing::internal::AlwaysTrue()) { \
224 ::testing::internal::DeathTest* gtest_dt; \
225 if (!::testing::internal::DeathTest::Create( \
226 #statement, \
227 ::testing::internal::MakeDeathTestMatcher(regex_or_matcher), \
228 __FILE__, __LINE__, &gtest_dt)) { \
229 goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \
230 } \
231 if (gtest_dt != nullptr) { \
232 std::unique_ptr< ::testing::internal::DeathTest> gtest_dt_ptr(gtest_dt); \
233 switch (gtest_dt->AssumeRole()) { \
234 case ::testing::internal::DeathTest::OVERSEE_TEST: \
235 if (!gtest_dt->Passed(predicate(gtest_dt->Wait()))) { \
236 goto GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__); \
237 } \
238 break; \
239 case ::testing::internal::DeathTest::EXECUTE_TEST: { \
240 const ::testing::internal::DeathTest::ReturnSentinel gtest_sentinel( \
241 gtest_dt); \
242 GTEST_EXECUTE_DEATH_TEST_STATEMENT_(statement, gtest_dt); \
243 gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \
244 break; \
245 } \
246 } \
247 } \
248 } else \
249 GTEST_CONCAT_TOKEN_(gtest_label_, __LINE__) \
250 : fail(::testing::internal::DeathTest::LastMessage())
251 // The symbol "fail" here expands to something into which a message
252 // can be streamed.
253
254 // This macro is for implementing ASSERT/EXPECT_DEBUG_DEATH when compiled in
255 // NDEBUG mode. In this case we need the statements to be executed and the macro
256 // must accept a streamed message even though the message is never printed.
257 // The regex object is not evaluated, but it is used to prevent "unused"
258 // warnings and to avoid an expression that doesn't compile in debug mode.
259 #define GTEST_EXECUTE_STATEMENT_cxx . . $ `vendor/googletest/include/gtest/internal/gtest-death-test-internal.h:259:9`!(statement, regex_or_matcher) \
260 GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
261 if (::testing::internal::AlwaysTrue()) { \
262 GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \
263 } else if (!::testing::internal::AlwaysTrue()) { \
264 ::testing::internal::MakeDeathTestMatcher(regex_or_matcher); \
265 } else \
266 ::testing::Message()
267
268 // A class representing the parsed contents of the
269 // --gtest_internal_run_death_test flag, as it existed when
270 // RUN_ALL_TESTS was called.
271 class InternalRunDeathTestFlagcxx . . $ testing/internal/InternalRunDeathTestFlag# {
272 public:
273 InternalRunDeathTestFlagcxx . . $ testing/internal/InternalRunDeathTestFlag#InternalRunDeathTestFlag(5265c6da66af4605).(const stdcxx . . $ std/::stringcxx . . $ std/string#& a_file, int a_line, int an_index,
274 int a_write_fd)
275 : file_cxx . . $ std/__cxx11/basic_string#basic_string(a47f53d4115f6ce5).(a_file), line_cxx . . $ testing/internal/InternalRunDeathTestFlag#line_.(a_line), index_cxx . . $ testing/internal/InternalRunDeathTestFlag#index_.(an_index), write_fd_cxx . . $ testing/internal/InternalRunDeathTestFlag#write_fd_.(a_write_fd) {}
276
277 ~cxx . . $ testing/internal/InternalRunDeathTestFlag#`~InternalRunDeathTestFlag`(ced63f7c635d850d).InternalRunDeathTestFlagcxx . . $ testing/internal/InternalRunDeathTestFlag#() {
278 if (write_fd_cxx . . $ testing/internal/InternalRunDeathTestFlag#write_fd_. >= 0) posixcxx . . $ testing/internal/posix/::Closecxx . . $ testing/internal/posix/Close(7864480464b09eea).(write_fd_cxx . . $ testing/internal/InternalRunDeathTestFlag#write_fd_.);
279 }
280
281 const stdcxx . . $ std/::stringcxx . . $ std/string#& filecxx . . $ testing/internal/InternalRunDeathTestFlag#file(f4fff0029955a25f).() const { return file_cxx . . $ testing/internal/InternalRunDeathTestFlag#file_.; }
282 int linecxx . . $ testing/internal/InternalRunDeathTestFlag#line(455f465bc33b4cdf).() const { return line_cxx . . $ testing/internal/InternalRunDeathTestFlag#line_.; }
283 int indexcxx . . $ testing/internal/InternalRunDeathTestFlag#index(455f465bc33b4cdf).() const { return index_cxx . . $ testing/internal/InternalRunDeathTestFlag#index_.; }
284 int write_fdcxx . . $ testing/internal/InternalRunDeathTestFlag#write_fd(455f465bc33b4cdf).() const { return write_fd_cxx . . $ testing/internal/InternalRunDeathTestFlag#write_fd_.; }
285
286 private:
287 stdcxx . . $ std/::stringcxx . . $ std/string# file_cxx . . $ testing/internal/InternalRunDeathTestFlag#file_.;
288 int line_cxx . . $ testing/internal/InternalRunDeathTestFlag#line_.;
289 int index_cxx . . $ testing/internal/InternalRunDeathTestFlag#index_.;
290 int write_fd_cxx . . $ testing/internal/InternalRunDeathTestFlag#write_fd_.;
291
292 InternalRunDeathTestFlagcxx . . $ testing/internal/InternalRunDeathTestFlag#InternalRunDeathTestFlag(e4f9562d95436b4d).(const InternalRunDeathTestFlagcxx . . $ testing/internal/InternalRunDeathTestFlag#&) = delete;
293 InternalRunDeathTestFlagcxx . . $ testing/internal/InternalRunDeathTestFlag#& operatorcxx . . $ testing/internal/InternalRunDeathTestFlag#`operator=`(8552bcde7bef9a78).=(const InternalRunDeathTestFlagcxx . . $ testing/internal/InternalRunDeathTestFlag#&) = delete;
294 };
295
296 // Returns a newly created InternalRunDeathTestFlag object with fields
297 // initialized from the GTEST_FLAG(internal_run_death_test) flag if
298 // the flag is specified; otherwise returns NULL.
299 InternalRunDeathTestFlagcxx . . $ testing/internal/InternalRunDeathTestFlag#* ParseInternalRunDeathTestFlagcxx . . $ testing/internal/ParseInternalRunDeathTestFlag(8dcd156610684952).();
300
301 #endif // GTEST_HAS_DEATH_TEST
302
303 } // namespace internal
304 } // namespace testing
305
306 #endif // GOOGLETEST_INCLUDE_GTEST_INTERNAL_GTEST_DEATH_TEST_INTERNAL_H_