diff options
author | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2009-03-06 01:20:15 (GMT) |
---|---|---|
committer | zhanyong.wan <zhanyong.wan@861a406c-534a-0410-8894-cb66d6ee9925> | 2009-03-06 01:20:15 (GMT) |
commit | 4984c93490eeeb7d3d1979b30a39a21cad07cba5 (patch) | |
tree | ca3c2306a370dda3388a4cbd34d22331debaec87 /include | |
parent | 0af0709b02899f9177db55eba7929e65e5834b29 (diff) | |
download | googletest-4984c93490eeeb7d3d1979b30a39a21cad07cba5.zip googletest-4984c93490eeeb7d3d1979b30a39a21cad07cba5.tar.gz googletest-4984c93490eeeb7d3d1979b30a39a21cad07cba5.tar.bz2 |
Implements death tests on Windows (by Vlad Losev); enables POSIX regex on Mac and Cygwin; fixes build issue on some Linux versions due to PATH_MAX.
Diffstat (limited to 'include')
-rw-r--r-- | include/gtest/gtest-death-test.h | 2 | ||||
-rw-r--r-- | include/gtest/internal/gtest-death-test-internal.h | 51 | ||||
-rw-r--r-- | include/gtest/internal/gtest-port.h | 30 |
3 files changed, 66 insertions, 17 deletions
diff --git a/include/gtest/gtest-death-test.h b/include/gtest/gtest-death-test.h index bb306f2..dcb2b66 100644 --- a/include/gtest/gtest-death-test.h +++ b/include/gtest/gtest-death-test.h @@ -184,6 +184,7 @@ class ExitedWithCode { const int exit_code_; }; +#if !GTEST_OS_WINDOWS // Tests that an exit code describes an exit due to termination by a // given signal. class KilledBySignal { @@ -193,6 +194,7 @@ class KilledBySignal { private: const int signum_; }; +#endif // !GTEST_OS_WINDOWS // EXPECT_DEBUG_DEATH asserts that the given statements die in debug mode. // The death testing framework causes this to have interesting semantics, diff --git a/include/gtest/internal/gtest-death-test-internal.h b/include/gtest/internal/gtest-death-test-internal.h index 815a3b5..ff2e490 100644 --- a/include/gtest/internal/gtest-death-test-internal.h +++ b/include/gtest/internal/gtest-death-test-internal.h @@ -39,6 +39,10 @@ #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 { @@ -121,7 +125,12 @@ class DeathTest { // the last death test. static const char* LastMessage(); + static void set_last_death_test_message(const String& message); + private: + // A string containing a description of the outcome of the last death test. + static String last_death_test_message_; + GTEST_DISALLOW_COPY_AND_ASSIGN_(DeathTest); }; @@ -167,7 +176,7 @@ bool ExitedUnsuccessfully(int exit_status); case ::testing::internal::DeathTest::EXECUTE_TEST: { \ ::testing::internal::DeathTest::ReturnSentinel \ gtest_sentinel(gtest_dt); \ - { statement; } \ + GTEST_HIDE_UNREACHABLE_CODE_(statement); \ gtest_dt->Abort(::testing::internal::DeathTest::TEST_DID_NOT_DIE); \ break; \ } \ @@ -179,14 +188,42 @@ bool ExitedUnsuccessfully(int exit_status); // The symbol "fail" here expands to something into which a message // can be streamed. -// A struct representing the parsed contents of the +// A class representing the parsed contents of the // --gtest_internal_run_death_test flag, as it existed when // RUN_ALL_TESTS was called. -struct InternalRunDeathTestFlag { - String file; - int line; - int index; - int status_fd; +class InternalRunDeathTestFlag { + public: + InternalRunDeathTestFlag(const String& file, + int line, + int index, + int status_fd) + : file_(file), line_(line), index_(index), status_fd_(status_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 + } + + String file() const { return file_; } + int line() const { return line_; } + int index() const { return index_; } + int status_fd() const { return status_fd_; } + + private: + String file_; + int line_; + int index_; + int status_fd_; + + GTEST_DISALLOW_COPY_AND_ASSIGN_(InternalRunDeathTestFlag); }; // Returns a newly created InternalRunDeathTestFlag object with fields diff --git a/include/gtest/internal/gtest-port.h b/include/gtest/internal/gtest-port.h index 8f75e9a..c93ebd8 100644 --- a/include/gtest/internal/gtest-port.h +++ b/include/gtest/internal/gtest-port.h @@ -183,7 +183,7 @@ #define GTEST_OS_SOLARIS 1 #endif // _MSC_VER -#if GTEST_OS_LINUX +#if GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC // On some platforms, <regex.h> needs someone to define size_t, and // won't compile otherwise. We can #include it here as we already @@ -194,8 +194,8 @@ #else -// We are not on Linux, so <regex.h> may not be available. Use our -// own simple regex implementation instead. +// <regex.h> may not be available on this platform. Use our own +// simple regex implementation instead. #define GTEST_USES_SIMPLE_RE 1 #endif // GTEST_OS_LINUX @@ -367,12 +367,19 @@ #endif // GTEST_HAS_CLONE // Determines whether to support death tests. -#if GTEST_HAS_STD_STRING && GTEST_HAS_CLONE +// Google Test does not support death tests for VC 7.1 and earlier for +// these reasons: +// 1. std::vector does not build in VC 7.1 when exceptions are disabled. +// 2. std::string does not build in VC 7.1 when exceptions are disabled +// (this is covered by GTEST_HAS_STD_STRING guard). +// 3. abort() in a VC 7.1 application compiled as GUI in debug config +// pops up a dialog window that cannot be suppressed programmatically. +#if GTEST_HAS_STD_STRING && (GTEST_HAS_CLONE || \ + GTEST_OS_WINDOWS && _MSC_VER >= 1400) #define GTEST_HAS_DEATH_TEST 1 #include <vector> -#include <fcntl.h> -#include <sys/mman.h> -#endif // GTEST_HAS_STD_STRING && GTEST_HAS_CLONE +#endif // GTEST_HAS_STD_STRING && (GTEST_HAS_CLONE || + // GTEST_OS_WINDOWS && _MSC_VER >= 1400) // Determines whether to support value-parameterized tests. @@ -595,14 +602,17 @@ inline void FlushInfoLog() { fflush(NULL); } // CaptureStderr - starts capturing stderr. // GetCapturedStderr - stops capturing stderr and returns the captured string. +#if GTEST_HAS_STD_STRING +void CaptureStderr(); +::std::string GetCapturedStderr(); +#endif // GTEST_HAS_STD_STRING + #if GTEST_HAS_DEATH_TEST // A copy of all command line arguments. Set by InitGoogleTest(). extern ::std::vector<String> g_argvs; -void CaptureStderr(); // GTEST_HAS_DEATH_TEST implies we have ::std::string. -::std::string GetCapturedStderr(); const ::std::vector<String>& GetArgvs(); #endif // GTEST_HAS_DEATH_TEST @@ -692,7 +702,7 @@ struct is_pointer<T*> : public true_type {}; #if GTEST_OS_WINDOWS typedef __int64 BiggestInt; #else -typedef long long BiggestInt; // NOLINT +typedef long long BiggestInt; // NOLINT #endif // GTEST_OS_WINDOWS // The maximum number a BiggestInt can represent. This definition |