1bf215546Sopenharmony_ci// Copyright 2005, Google Inc. 2bf215546Sopenharmony_ci// All rights reserved. 3bf215546Sopenharmony_ci// 4bf215546Sopenharmony_ci// Redistribution and use in source and binary forms, with or without 5bf215546Sopenharmony_ci// modification, are permitted provided that the following conditions are 6bf215546Sopenharmony_ci// met: 7bf215546Sopenharmony_ci// 8bf215546Sopenharmony_ci// * Redistributions of source code must retain the above copyright 9bf215546Sopenharmony_ci// notice, this list of conditions and the following disclaimer. 10bf215546Sopenharmony_ci// * Redistributions in binary form must reproduce the above 11bf215546Sopenharmony_ci// copyright notice, this list of conditions and the following disclaimer 12bf215546Sopenharmony_ci// in the documentation and/or other materials provided with the 13bf215546Sopenharmony_ci// distribution. 14bf215546Sopenharmony_ci// * Neither the name of Google Inc. nor the names of its 15bf215546Sopenharmony_ci// contributors may be used to endorse or promote products derived from 16bf215546Sopenharmony_ci// this software without specific prior written permission. 17bf215546Sopenharmony_ci// 18bf215546Sopenharmony_ci// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19bf215546Sopenharmony_ci// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20bf215546Sopenharmony_ci// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21bf215546Sopenharmony_ci// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22bf215546Sopenharmony_ci// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23bf215546Sopenharmony_ci// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24bf215546Sopenharmony_ci// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25bf215546Sopenharmony_ci// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26bf215546Sopenharmony_ci// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27bf215546Sopenharmony_ci// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28bf215546Sopenharmony_ci// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29bf215546Sopenharmony_ci 30bf215546Sopenharmony_ci// 31bf215546Sopenharmony_ci// The Google C++ Testing and Mocking Framework (Google Test) 32bf215546Sopenharmony_ci// 33bf215546Sopenharmony_ci// This header file defines the public API for death tests. It is 34bf215546Sopenharmony_ci// #included by gtest.h so a user doesn't need to include this 35bf215546Sopenharmony_ci// directly. 36bf215546Sopenharmony_ci// GOOGLETEST_CM0001 DO NOT DELETE 37bf215546Sopenharmony_ci 38bf215546Sopenharmony_ci#ifndef GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_ 39bf215546Sopenharmony_ci#define GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_ 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ci#include "gtest/internal/gtest-death-test-internal.h" 42bf215546Sopenharmony_ci 43bf215546Sopenharmony_cinamespace testing { 44bf215546Sopenharmony_ci 45bf215546Sopenharmony_ci// This flag controls the style of death tests. Valid values are "threadsafe", 46bf215546Sopenharmony_ci// meaning that the death test child process will re-execute the test binary 47bf215546Sopenharmony_ci// from the start, running only a single death test, or "fast", 48bf215546Sopenharmony_ci// meaning that the child process will execute the test logic immediately 49bf215546Sopenharmony_ci// after forking. 50bf215546Sopenharmony_ciGTEST_DECLARE_string_(death_test_style); 51bf215546Sopenharmony_ci 52bf215546Sopenharmony_ci#if GTEST_HAS_DEATH_TEST 53bf215546Sopenharmony_ci 54bf215546Sopenharmony_cinamespace internal { 55bf215546Sopenharmony_ci 56bf215546Sopenharmony_ci// Returns a Boolean value indicating whether the caller is currently 57bf215546Sopenharmony_ci// executing in the context of the death test child process. Tools such as 58bf215546Sopenharmony_ci// Valgrind heap checkers may need this to modify their behavior in death 59bf215546Sopenharmony_ci// tests. IMPORTANT: This is an internal utility. Using it may break the 60bf215546Sopenharmony_ci// implementation of death tests. User code MUST NOT use it. 61bf215546Sopenharmony_ciGTEST_API_ bool InDeathTestChild(); 62bf215546Sopenharmony_ci 63bf215546Sopenharmony_ci} // namespace internal 64bf215546Sopenharmony_ci 65bf215546Sopenharmony_ci// The following macros are useful for writing death tests. 66bf215546Sopenharmony_ci 67bf215546Sopenharmony_ci// Here's what happens when an ASSERT_DEATH* or EXPECT_DEATH* is 68bf215546Sopenharmony_ci// executed: 69bf215546Sopenharmony_ci// 70bf215546Sopenharmony_ci// 1. It generates a warning if there is more than one active 71bf215546Sopenharmony_ci// thread. This is because it's safe to fork() or clone() only 72bf215546Sopenharmony_ci// when there is a single thread. 73bf215546Sopenharmony_ci// 74bf215546Sopenharmony_ci// 2. The parent process clone()s a sub-process and runs the death 75bf215546Sopenharmony_ci// test in it; the sub-process exits with code 0 at the end of the 76bf215546Sopenharmony_ci// death test, if it hasn't exited already. 77bf215546Sopenharmony_ci// 78bf215546Sopenharmony_ci// 3. The parent process waits for the sub-process to terminate. 79bf215546Sopenharmony_ci// 80bf215546Sopenharmony_ci// 4. The parent process checks the exit code and error message of 81bf215546Sopenharmony_ci// the sub-process. 82bf215546Sopenharmony_ci// 83bf215546Sopenharmony_ci// Examples: 84bf215546Sopenharmony_ci// 85bf215546Sopenharmony_ci// ASSERT_DEATH(server.SendMessage(56, "Hello"), "Invalid port number"); 86bf215546Sopenharmony_ci// for (int i = 0; i < 5; i++) { 87bf215546Sopenharmony_ci// EXPECT_DEATH(server.ProcessRequest(i), 88bf215546Sopenharmony_ci// "Invalid request .* in ProcessRequest()") 89bf215546Sopenharmony_ci// << "Failed to die on request " << i; 90bf215546Sopenharmony_ci// } 91bf215546Sopenharmony_ci// 92bf215546Sopenharmony_ci// ASSERT_EXIT(server.ExitNow(), ::testing::ExitedWithCode(0), "Exiting"); 93bf215546Sopenharmony_ci// 94bf215546Sopenharmony_ci// bool KilledBySIGHUP(int exit_code) { 95bf215546Sopenharmony_ci// return WIFSIGNALED(exit_code) && WTERMSIG(exit_code) == SIGHUP; 96bf215546Sopenharmony_ci// } 97bf215546Sopenharmony_ci// 98bf215546Sopenharmony_ci// ASSERT_EXIT(client.HangUpServer(), KilledBySIGHUP, "Hanging up!"); 99bf215546Sopenharmony_ci// 100bf215546Sopenharmony_ci// On the regular expressions used in death tests: 101bf215546Sopenharmony_ci// 102bf215546Sopenharmony_ci// GOOGLETEST_CM0005 DO NOT DELETE 103bf215546Sopenharmony_ci// On POSIX-compliant systems (*nix), we use the <regex.h> library, 104bf215546Sopenharmony_ci// which uses the POSIX extended regex syntax. 105bf215546Sopenharmony_ci// 106bf215546Sopenharmony_ci// On other platforms (e.g. Windows or Mac), we only support a simple regex 107bf215546Sopenharmony_ci// syntax implemented as part of Google Test. This limited 108bf215546Sopenharmony_ci// implementation should be enough most of the time when writing 109bf215546Sopenharmony_ci// death tests; though it lacks many features you can find in PCRE 110bf215546Sopenharmony_ci// or POSIX extended regex syntax. For example, we don't support 111bf215546Sopenharmony_ci// union ("x|y"), grouping ("(xy)"), brackets ("[xy]"), and 112bf215546Sopenharmony_ci// repetition count ("x{5,7}"), among others. 113bf215546Sopenharmony_ci// 114bf215546Sopenharmony_ci// Below is the syntax that we do support. We chose it to be a 115bf215546Sopenharmony_ci// subset of both PCRE and POSIX extended regex, so it's easy to 116bf215546Sopenharmony_ci// learn wherever you come from. In the following: 'A' denotes a 117bf215546Sopenharmony_ci// literal character, period (.), or a single \\ escape sequence; 118bf215546Sopenharmony_ci// 'x' and 'y' denote regular expressions; 'm' and 'n' are for 119bf215546Sopenharmony_ci// natural numbers. 120bf215546Sopenharmony_ci// 121bf215546Sopenharmony_ci// c matches any literal character c 122bf215546Sopenharmony_ci// \\d matches any decimal digit 123bf215546Sopenharmony_ci// \\D matches any character that's not a decimal digit 124bf215546Sopenharmony_ci// \\f matches \f 125bf215546Sopenharmony_ci// \\n matches \n 126bf215546Sopenharmony_ci// \\r matches \r 127bf215546Sopenharmony_ci// \\s matches any ASCII whitespace, including \n 128bf215546Sopenharmony_ci// \\S matches any character that's not a whitespace 129bf215546Sopenharmony_ci// \\t matches \t 130bf215546Sopenharmony_ci// \\v matches \v 131bf215546Sopenharmony_ci// \\w matches any letter, _, or decimal digit 132bf215546Sopenharmony_ci// \\W matches any character that \\w doesn't match 133bf215546Sopenharmony_ci// \\c matches any literal character c, which must be a punctuation 134bf215546Sopenharmony_ci// . matches any single character except \n 135bf215546Sopenharmony_ci// A? matches 0 or 1 occurrences of A 136bf215546Sopenharmony_ci// A* matches 0 or many occurrences of A 137bf215546Sopenharmony_ci// A+ matches 1 or many occurrences of A 138bf215546Sopenharmony_ci// ^ matches the beginning of a string (not that of each line) 139bf215546Sopenharmony_ci// $ matches the end of a string (not that of each line) 140bf215546Sopenharmony_ci// xy matches x followed by y 141bf215546Sopenharmony_ci// 142bf215546Sopenharmony_ci// If you accidentally use PCRE or POSIX extended regex features 143bf215546Sopenharmony_ci// not implemented by us, you will get a run-time failure. In that 144bf215546Sopenharmony_ci// case, please try to rewrite your regular expression within the 145bf215546Sopenharmony_ci// above syntax. 146bf215546Sopenharmony_ci// 147bf215546Sopenharmony_ci// This implementation is *not* meant to be as highly tuned or robust 148bf215546Sopenharmony_ci// as a compiled regex library, but should perform well enough for a 149bf215546Sopenharmony_ci// death test, which already incurs significant overhead by launching 150bf215546Sopenharmony_ci// a child process. 151bf215546Sopenharmony_ci// 152bf215546Sopenharmony_ci// Known caveats: 153bf215546Sopenharmony_ci// 154bf215546Sopenharmony_ci// A "threadsafe" style death test obtains the path to the test 155bf215546Sopenharmony_ci// program from argv[0] and re-executes it in the sub-process. For 156bf215546Sopenharmony_ci// simplicity, the current implementation doesn't search the PATH 157bf215546Sopenharmony_ci// when launching the sub-process. This means that the user must 158bf215546Sopenharmony_ci// invoke the test program via a path that contains at least one 159bf215546Sopenharmony_ci// path separator (e.g. path/to/foo_test and 160bf215546Sopenharmony_ci// /absolute/path/to/bar_test are fine, but foo_test is not). This 161bf215546Sopenharmony_ci// is rarely a problem as people usually don't put the test binary 162bf215546Sopenharmony_ci// directory in PATH. 163bf215546Sopenharmony_ci// 164bf215546Sopenharmony_ci 165bf215546Sopenharmony_ci// Asserts that a given statement causes the program to exit, with an 166bf215546Sopenharmony_ci// integer exit status that satisfies predicate, and emitting error output 167bf215546Sopenharmony_ci// that matches regex. 168bf215546Sopenharmony_ci# define ASSERT_EXIT(statement, predicate, regex) \ 169bf215546Sopenharmony_ci GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_FATAL_FAILURE_) 170bf215546Sopenharmony_ci 171bf215546Sopenharmony_ci// Like ASSERT_EXIT, but continues on to successive tests in the 172bf215546Sopenharmony_ci// test suite, if any: 173bf215546Sopenharmony_ci# define EXPECT_EXIT(statement, predicate, regex) \ 174bf215546Sopenharmony_ci GTEST_DEATH_TEST_(statement, predicate, regex, GTEST_NONFATAL_FAILURE_) 175bf215546Sopenharmony_ci 176bf215546Sopenharmony_ci// Asserts that a given statement causes the program to exit, either by 177bf215546Sopenharmony_ci// explicitly exiting with a nonzero exit code or being killed by a 178bf215546Sopenharmony_ci// signal, and emitting error output that matches regex. 179bf215546Sopenharmony_ci# define ASSERT_DEATH(statement, regex) \ 180bf215546Sopenharmony_ci ASSERT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex) 181bf215546Sopenharmony_ci 182bf215546Sopenharmony_ci// Like ASSERT_DEATH, but continues on to successive tests in the 183bf215546Sopenharmony_ci// test suite, if any: 184bf215546Sopenharmony_ci# define EXPECT_DEATH(statement, regex) \ 185bf215546Sopenharmony_ci EXPECT_EXIT(statement, ::testing::internal::ExitedUnsuccessfully, regex) 186bf215546Sopenharmony_ci 187bf215546Sopenharmony_ci// Two predicate classes that can be used in {ASSERT,EXPECT}_EXIT*: 188bf215546Sopenharmony_ci 189bf215546Sopenharmony_ci// Tests that an exit code describes a normal exit with a given exit code. 190bf215546Sopenharmony_ciclass GTEST_API_ ExitedWithCode { 191bf215546Sopenharmony_ci public: 192bf215546Sopenharmony_ci explicit ExitedWithCode(int exit_code); 193bf215546Sopenharmony_ci bool operator()(int exit_status) const; 194bf215546Sopenharmony_ci private: 195bf215546Sopenharmony_ci // No implementation - assignment is unsupported. 196bf215546Sopenharmony_ci void operator=(const ExitedWithCode& other); 197bf215546Sopenharmony_ci 198bf215546Sopenharmony_ci const int exit_code_; 199bf215546Sopenharmony_ci}; 200bf215546Sopenharmony_ci 201bf215546Sopenharmony_ci# if !GTEST_OS_WINDOWS && !GTEST_OS_FUCHSIA 202bf215546Sopenharmony_ci// Tests that an exit code describes an exit due to termination by a 203bf215546Sopenharmony_ci// given signal. 204bf215546Sopenharmony_ci// GOOGLETEST_CM0006 DO NOT DELETE 205bf215546Sopenharmony_ciclass GTEST_API_ KilledBySignal { 206bf215546Sopenharmony_ci public: 207bf215546Sopenharmony_ci explicit KilledBySignal(int signum); 208bf215546Sopenharmony_ci bool operator()(int exit_status) const; 209bf215546Sopenharmony_ci private: 210bf215546Sopenharmony_ci const int signum_; 211bf215546Sopenharmony_ci}; 212bf215546Sopenharmony_ci# endif // !GTEST_OS_WINDOWS 213bf215546Sopenharmony_ci 214bf215546Sopenharmony_ci// EXPECT_DEBUG_DEATH asserts that the given statements die in debug mode. 215bf215546Sopenharmony_ci// The death testing framework causes this to have interesting semantics, 216bf215546Sopenharmony_ci// since the sideeffects of the call are only visible in opt mode, and not 217bf215546Sopenharmony_ci// in debug mode. 218bf215546Sopenharmony_ci// 219bf215546Sopenharmony_ci// In practice, this can be used to test functions that utilize the 220bf215546Sopenharmony_ci// LOG(DFATAL) macro using the following style: 221bf215546Sopenharmony_ci// 222bf215546Sopenharmony_ci// int DieInDebugOr12(int* sideeffect) { 223bf215546Sopenharmony_ci// if (sideeffect) { 224bf215546Sopenharmony_ci// *sideeffect = 12; 225bf215546Sopenharmony_ci// } 226bf215546Sopenharmony_ci// LOG(DFATAL) << "death"; 227bf215546Sopenharmony_ci// return 12; 228bf215546Sopenharmony_ci// } 229bf215546Sopenharmony_ci// 230bf215546Sopenharmony_ci// TEST(TestSuite, TestDieOr12WorksInDgbAndOpt) { 231bf215546Sopenharmony_ci// int sideeffect = 0; 232bf215546Sopenharmony_ci// // Only asserts in dbg. 233bf215546Sopenharmony_ci// EXPECT_DEBUG_DEATH(DieInDebugOr12(&sideeffect), "death"); 234bf215546Sopenharmony_ci// 235bf215546Sopenharmony_ci// #ifdef NDEBUG 236bf215546Sopenharmony_ci// // opt-mode has sideeffect visible. 237bf215546Sopenharmony_ci// EXPECT_EQ(12, sideeffect); 238bf215546Sopenharmony_ci// #else 239bf215546Sopenharmony_ci// // dbg-mode no visible sideeffect. 240bf215546Sopenharmony_ci// EXPECT_EQ(0, sideeffect); 241bf215546Sopenharmony_ci// #endif 242bf215546Sopenharmony_ci// } 243bf215546Sopenharmony_ci// 244bf215546Sopenharmony_ci// This will assert that DieInDebugReturn12InOpt() crashes in debug 245bf215546Sopenharmony_ci// mode, usually due to a DCHECK or LOG(DFATAL), but returns the 246bf215546Sopenharmony_ci// appropriate fallback value (12 in this case) in opt mode. If you 247bf215546Sopenharmony_ci// need to test that a function has appropriate side-effects in opt 248bf215546Sopenharmony_ci// mode, include assertions against the side-effects. A general 249bf215546Sopenharmony_ci// pattern for this is: 250bf215546Sopenharmony_ci// 251bf215546Sopenharmony_ci// EXPECT_DEBUG_DEATH({ 252bf215546Sopenharmony_ci// // Side-effects here will have an effect after this statement in 253bf215546Sopenharmony_ci// // opt mode, but none in debug mode. 254bf215546Sopenharmony_ci// EXPECT_EQ(12, DieInDebugOr12(&sideeffect)); 255bf215546Sopenharmony_ci// }, "death"); 256bf215546Sopenharmony_ci// 257bf215546Sopenharmony_ci# ifdef NDEBUG 258bf215546Sopenharmony_ci 259bf215546Sopenharmony_ci# define EXPECT_DEBUG_DEATH(statement, regex) \ 260bf215546Sopenharmony_ci GTEST_EXECUTE_STATEMENT_(statement, regex) 261bf215546Sopenharmony_ci 262bf215546Sopenharmony_ci# define ASSERT_DEBUG_DEATH(statement, regex) \ 263bf215546Sopenharmony_ci GTEST_EXECUTE_STATEMENT_(statement, regex) 264bf215546Sopenharmony_ci 265bf215546Sopenharmony_ci# else 266bf215546Sopenharmony_ci 267bf215546Sopenharmony_ci# define EXPECT_DEBUG_DEATH(statement, regex) \ 268bf215546Sopenharmony_ci EXPECT_DEATH(statement, regex) 269bf215546Sopenharmony_ci 270bf215546Sopenharmony_ci# define ASSERT_DEBUG_DEATH(statement, regex) \ 271bf215546Sopenharmony_ci ASSERT_DEATH(statement, regex) 272bf215546Sopenharmony_ci 273bf215546Sopenharmony_ci# endif // NDEBUG for EXPECT_DEBUG_DEATH 274bf215546Sopenharmony_ci#endif // GTEST_HAS_DEATH_TEST 275bf215546Sopenharmony_ci 276bf215546Sopenharmony_ci// This macro is used for implementing macros such as 277bf215546Sopenharmony_ci// EXPECT_DEATH_IF_SUPPORTED and ASSERT_DEATH_IF_SUPPORTED on systems where 278bf215546Sopenharmony_ci// death tests are not supported. Those macros must compile on such systems 279bf215546Sopenharmony_ci// if and only if EXPECT_DEATH and ASSERT_DEATH compile with the same parameters 280bf215546Sopenharmony_ci// on systems that support death tests. This allows one to write such a macro on 281bf215546Sopenharmony_ci// a system that does not support death tests and be sure that it will compile 282bf215546Sopenharmony_ci// on a death-test supporting system. It is exposed publicly so that systems 283bf215546Sopenharmony_ci// that have death-tests with stricter requirements than GTEST_HAS_DEATH_TEST 284bf215546Sopenharmony_ci// can write their own equivalent of EXPECT_DEATH_IF_SUPPORTED and 285bf215546Sopenharmony_ci// ASSERT_DEATH_IF_SUPPORTED. 286bf215546Sopenharmony_ci// 287bf215546Sopenharmony_ci// Parameters: 288bf215546Sopenharmony_ci// statement - A statement that a macro such as EXPECT_DEATH would test 289bf215546Sopenharmony_ci// for program termination. This macro has to make sure this 290bf215546Sopenharmony_ci// statement is compiled but not executed, to ensure that 291bf215546Sopenharmony_ci// EXPECT_DEATH_IF_SUPPORTED compiles with a certain 292bf215546Sopenharmony_ci// parameter if and only if EXPECT_DEATH compiles with it. 293bf215546Sopenharmony_ci// regex - A regex that a macro such as EXPECT_DEATH would use to test 294bf215546Sopenharmony_ci// the output of statement. This parameter has to be 295bf215546Sopenharmony_ci// compiled but not evaluated by this macro, to ensure that 296bf215546Sopenharmony_ci// this macro only accepts expressions that a macro such as 297bf215546Sopenharmony_ci// EXPECT_DEATH would accept. 298bf215546Sopenharmony_ci// terminator - Must be an empty statement for EXPECT_DEATH_IF_SUPPORTED 299bf215546Sopenharmony_ci// and a return statement for ASSERT_DEATH_IF_SUPPORTED. 300bf215546Sopenharmony_ci// This ensures that ASSERT_DEATH_IF_SUPPORTED will not 301bf215546Sopenharmony_ci// compile inside functions where ASSERT_DEATH doesn't 302bf215546Sopenharmony_ci// compile. 303bf215546Sopenharmony_ci// 304bf215546Sopenharmony_ci// The branch that has an always false condition is used to ensure that 305bf215546Sopenharmony_ci// statement and regex are compiled (and thus syntactically correct) but 306bf215546Sopenharmony_ci// never executed. The unreachable code macro protects the terminator 307bf215546Sopenharmony_ci// statement from generating an 'unreachable code' warning in case 308bf215546Sopenharmony_ci// statement unconditionally returns or throws. The Message constructor at 309bf215546Sopenharmony_ci// the end allows the syntax of streaming additional messages into the 310bf215546Sopenharmony_ci// macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH. 311bf215546Sopenharmony_ci# define GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, terminator) \ 312bf215546Sopenharmony_ci GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ 313bf215546Sopenharmony_ci if (::testing::internal::AlwaysTrue()) { \ 314bf215546Sopenharmony_ci GTEST_LOG_(WARNING) \ 315bf215546Sopenharmony_ci << "Death tests are not supported on this platform.\n" \ 316bf215546Sopenharmony_ci << "Statement '" #statement "' cannot be verified."; \ 317bf215546Sopenharmony_ci } else if (::testing::internal::AlwaysFalse()) { \ 318bf215546Sopenharmony_ci ::testing::internal::RE::PartialMatch(".*", (regex)); \ 319bf215546Sopenharmony_ci GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ 320bf215546Sopenharmony_ci terminator; \ 321bf215546Sopenharmony_ci } else \ 322bf215546Sopenharmony_ci ::testing::Message() 323bf215546Sopenharmony_ci 324bf215546Sopenharmony_ci// EXPECT_DEATH_IF_SUPPORTED(statement, regex) and 325bf215546Sopenharmony_ci// ASSERT_DEATH_IF_SUPPORTED(statement, regex) expand to real death tests if 326bf215546Sopenharmony_ci// death tests are supported; otherwise they just issue a warning. This is 327bf215546Sopenharmony_ci// useful when you are combining death test assertions with normal test 328bf215546Sopenharmony_ci// assertions in one test. 329bf215546Sopenharmony_ci#if GTEST_HAS_DEATH_TEST 330bf215546Sopenharmony_ci# define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ 331bf215546Sopenharmony_ci EXPECT_DEATH(statement, regex) 332bf215546Sopenharmony_ci# define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ 333bf215546Sopenharmony_ci ASSERT_DEATH(statement, regex) 334bf215546Sopenharmony_ci#else 335bf215546Sopenharmony_ci# define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ 336bf215546Sopenharmony_ci GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, ) 337bf215546Sopenharmony_ci# define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ 338bf215546Sopenharmony_ci GTEST_UNSUPPORTED_DEATH_TEST(statement, regex, return) 339bf215546Sopenharmony_ci#endif 340bf215546Sopenharmony_ci 341bf215546Sopenharmony_ci} // namespace testing 342bf215546Sopenharmony_ci 343bf215546Sopenharmony_ci#endif // GTEST_INCLUDE_GTEST_GTEST_DEATH_TEST_H_ 344