diff options
author | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2009-09-11 06:59:42 (GMT) |
---|---|---|
committer | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2009-09-11 06:59:42 (GMT) |
commit | b2ee82ebf9b8f1be859d08611b768ae6c0700090 (patch) | |
tree | e9ef0e2d46fce05fcdf325c28b21c0c412567eda /include/gtest | |
parent | f6dd67a1550d25518cc37758364834f4f92a3570 (diff) | |
download | googletest-b2ee82ebf9b8f1be859d08611b768ae6c0700090.zip googletest-b2ee82ebf9b8f1be859d08611b768ae6c0700090.tar.gz googletest-b2ee82ebf9b8f1be859d08611b768ae6c0700090.tar.bz2 |
Improves EXPECT_DEATH_IF_SUPPORTED to allow streaming of messages and enforcing the validity of arguments (by Vlad Losev); adds samples for the event listener API (by Vlad Losev); simplifies the tests using EXPECT_DEATH_IF_SUPPORTED (by Zhanyong Wan).
Diffstat (limited to 'include/gtest')
-rw-r--r-- | include/gtest/gtest-death-test.h | 10 | ||||
-rw-r--r-- | include/gtest/internal/gtest-death-test-internal.h | 49 |
2 files changed, 52 insertions, 7 deletions
diff --git a/include/gtest/gtest-death-test.h b/include/gtest/gtest-death-test.h index 410654b..677e1e1 100644 --- a/include/gtest/gtest-death-test.h +++ b/include/gtest/gtest-death-test.h @@ -260,7 +260,7 @@ class KilledBySignal { // EXPECT_DEATH_IF_SUPPORTED(statement, regex) and // ASSERT_DEATH_IF_SUPPORTED(statement, regex) expand to real death tests if -// death tests are supported; otherwise they expand to empty. This is +// death tests are supported; otherwise they just issue a warning. This is // useful when you are combining death test assertions with normal test // assertions in one test. #if GTEST_HAS_DEATH_TEST @@ -270,13 +270,9 @@ class KilledBySignal { ASSERT_DEATH(statement, regex) #else #define EXPECT_DEATH_IF_SUPPORTED(statement, regex) \ - GTEST_LOG_(WARNING, \ - "Death tests are not supported on this platform. The statement" \ - " '" #statement "' can not be verified") + GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, ) #define ASSERT_DEATH_IF_SUPPORTED(statement, regex) \ - GTEST_LOG_(WARNING, \ - "Death tests are not supported on this platform. The statement" \ - " '" #statement "' can not be verified") + GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, return) #endif } // namespace testing diff --git a/include/gtest/internal/gtest-death-test-internal.h b/include/gtest/internal/gtest-death-test-internal.h index 143e58a..d87bfa9 100644 --- a/include/gtest/internal/gtest-death-test-internal.h +++ b/include/gtest/internal/gtest-death-test-internal.h @@ -219,6 +219,55 @@ class InternalRunDeathTestFlag { // the flag is specified; otherwise returns NULL. InternalRunDeathTestFlag* ParseInternalRunDeathTestFlag(); +#else // GTEST_HAS_DEATH_TEST + +// This macro is used for implementing macros such as +// EXPECT_DEATH_IF_SUPPORTED and ASSERT_DEATH_IF_SUPPORTED on systems where +// death tests are not supported. Those macros must compile on such systems +// iff EXPECT_DEATH and ASSERT_DEATH compile with the same parameters on +// systems that support death tests. This allows one to write such a macro +// on a system that does not support death tests and be sure that it will +// compile on a death-test supporting system. +// +// Parameters: +// statement - A statement that a macro such as EXPECT_DEATH would test +// for program termination. This macro has to make sure this +// statement is compiled but not executed, to ensure that +// EXPECT_DEATH_IF_SUPPORTED compiles with a certain +// parameter iff EXPECT_DEATH compiles with it. +// regex - A regex that a macro such as EXPECT_DEATH would use to test +// the output of statement. This parameter has to be +// compiled but not evaluated by this macro, to ensure that +// this macro only accepts expressions that a macro such as +// EXPECT_DEATH would accept. +// terminator - Must be an empty statement for EXPECT_DEATH_IF_SUPPORTED +// and a return statement for ASSERT_DEATH_IF_SUPPORTED. +// This ensures that ASSERT_DEATH_IF_SUPPORTED will not +// compile inside functions where ASSERT_DEATH doesn't +// compile. +// +// The branch that has an always false condition is used to ensure that +// statement and regex are compiled (and thus syntactically correct) but +// never executed. The unreachable code macro protects the terminator +// statement from generating an 'unreachable code' warning in case +// statement unconditionally returns or throws. The Message constructor at +// the end allows the syntax of streaming additional messages into the +// macro, for compilational compatibility with EXPECT_DEATH/ASSERT_DEATH. +// TODO(vladl@google.com): rename the GTEST_HIDE_UNREACHABLE_CODE_ macro to +// GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_. +#define GTEST_UNSUPPORTED_DEATH_TEST_(statement, regex, terminator) \ + GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ + if (::testing::internal::AlwaysTrue()) { \ + GTEST_LOG_(WARNING, \ + "Death tests are not supported on this platform.\n" \ + "Statement '" #statement "' cannot be verified."); \ + } else if (!::testing::internal::AlwaysTrue()) { \ + ::testing::internal::RE::PartialMatch(".*", (regex)); \ + GTEST_HIDE_UNREACHABLE_CODE_(statement); \ + terminator; \ + } else \ + ::testing::Message() + #endif // GTEST_HAS_DEATH_TEST } // namespace internal |