diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2010-06-02 22:02:11 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2010-06-02 22:02:11 +0000 |
commit | 190f8ee25a6977ac6eb71b816498df42f17ad9a7 (patch) | |
tree | 658b8c02fce43448931b29c311631a0fda983ed6 /utils/unittest/googletest/include/gtest/internal/gtest-death-test-internal.h | |
parent | e4b9c93fc1b531fe0cfe25a042f6b81c1e7c15c0 (diff) |
Merge gtest-1.4.0.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@105353 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'utils/unittest/googletest/include/gtest/internal/gtest-death-test-internal.h')
-rw-r--r-- | utils/unittest/googletest/include/gtest/internal/gtest-death-test-internal.h | 75 |
1 files changed, 55 insertions, 20 deletions
diff --git a/utils/unittest/googletest/include/gtest/internal/gtest-death-test-internal.h b/utils/unittest/googletest/include/gtest/internal/gtest-death-test-internal.h index ff2e490efe..5aba1a0d68 100644 --- a/utils/unittest/googletest/include/gtest/internal/gtest-death-test-internal.h +++ b/utils/unittest/googletest/include/gtest/internal/gtest-death-test-internal.h @@ -39,10 +39,6 @@ #include <gtest/internal/gtest-internal.h> -#if GTEST_HAS_DEATH_TEST && GTEST_OS_WINDOWS -#include <io.h> -#endif // GTEST_HAS_DEATH_TEST && GTEST_OS_WINDOWS - namespace testing { namespace internal { @@ -157,7 +153,7 @@ bool ExitedUnsuccessfully(int exit_status); // ASSERT_EXIT*, and EXPECT_EXIT*. #define GTEST_DEATH_TEST_(statement, predicate, regex, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (true) { \ + if (::testing::internal::AlwaysTrue()) { \ const ::testing::internal::RE& gtest_regex = (regex); \ ::testing::internal::DeathTest* gtest_dt; \ if (!::testing::internal::DeathTest::Create(#statement, >est_regex, \ @@ -176,7 +172,7 @@ bool ExitedUnsuccessfully(int exit_status); case ::testing::internal::DeathTest::EXECUTE_TEST: { \ ::testing::internal::DeathTest::ReturnSentinel \ gtest_sentinel(gtest_dt); \ - GTEST_HIDE_UNREACHABLE_CODE_(statement); \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \ break; \ } \ @@ -196,32 +192,24 @@ class InternalRunDeathTestFlag { InternalRunDeathTestFlag(const String& file, int line, int index, - int status_fd) - : file_(file), line_(line), index_(index), status_fd_(status_fd) {} + int write_fd) + : file_(file), line_(line), index_(index), write_fd_(write_fd) {} ~InternalRunDeathTestFlag() { - if (status_fd_ >= 0) -// Suppress MSVC complaints about POSIX functions. -#ifdef _MSC_VER -#pragma warning(push) -#pragma warning(disable: 4996) -#endif // _MSC_VER - close(status_fd_); -#ifdef _MSC_VER -#pragma warning(pop) -#endif // _MSC_VER + if (write_fd_ >= 0) + posix::Close(write_fd_); } String file() const { return file_; } int line() const { return line_; } int index() const { return index_; } - int status_fd() const { return status_fd_; } + int write_fd() const { return write_fd_; } private: String file_; int line_; int index_; - int status_fd_; + int write_fd_; GTEST_DISALLOW_COPY_AND_ASSIGN_(InternalRunDeathTestFlag); }; @@ -231,6 +219,53 @@ 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. +#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::AlwaysFalse()) { \ + ::testing::internal::RE::PartialMatch(".*", (regex)); \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + terminator; \ + } else \ + ::testing::Message() + #endif // GTEST_HAS_DEATH_TEST } // namespace internal |