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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user