Simplifies implementation by defining a POSIX portability layer; adds the death test style flag to --help.
This commit is contained in:
		@@ -39,12 +39,6 @@
 | 
			
		||||
 | 
			
		||||
#include <gtest/internal/gtest-internal.h>
 | 
			
		||||
 | 
			
		||||
#if GTEST_HAS_DEATH_TEST && GTEST_OS_WINDOWS
 | 
			
		||||
#include <io.h>
 | 
			
		||||
#elif GTEST_HAS_DEATH_TEST
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#endif  // GTEST_HAS_DEATH_TEST && GTEST_OS_WINDOWS
 | 
			
		||||
 | 
			
		||||
namespace testing {
 | 
			
		||||
namespace internal {
 | 
			
		||||
 | 
			
		||||
@@ -203,15 +197,7 @@ class InternalRunDeathTestFlag {
 | 
			
		||||
 | 
			
		||||
  ~InternalRunDeathTestFlag() {
 | 
			
		||||
    if (write_fd_ >= 0)
 | 
			
		||||
// Suppress MSVC complaints about POSIX functions.
 | 
			
		||||
#ifdef _MSC_VER
 | 
			
		||||
#pragma warning(push)
 | 
			
		||||
#pragma warning(disable: 4996)
 | 
			
		||||
#endif  // _MSC_VER
 | 
			
		||||
      close(write_fd_);
 | 
			
		||||
#ifdef _MSC_VER
 | 
			
		||||
#pragma warning(pop)
 | 
			
		||||
#endif  // _MSC_VER
 | 
			
		||||
      posix::close(write_fd_);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  String file() const { return file_; }
 | 
			
		||||
 
 | 
			
		||||
@@ -149,7 +149,10 @@
 | 
			
		||||
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <iostream>  // Used for GTEST_CHECK_
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
 | 
			
		||||
#include <iostream>  // NOLINT
 | 
			
		||||
 | 
			
		||||
#define GTEST_DEV_EMAIL_ "googletestframework@@googlegroups.com"
 | 
			
		||||
#define GTEST_FLAG_PREFIX_ "gtest_"
 | 
			
		||||
@@ -192,8 +195,21 @@
 | 
			
		||||
// included <stdlib.h>, which is guaranteed to define size_t through
 | 
			
		||||
// <stddef.h>.
 | 
			
		||||
#include <regex.h>  // NOLINT
 | 
			
		||||
#include <strings.h>  // NOLINT
 | 
			
		||||
#include <sys/types.h>  // NOLINT
 | 
			
		||||
#include <unistd.h>  // NOLINT
 | 
			
		||||
 | 
			
		||||
#define GTEST_USES_POSIX_RE 1
 | 
			
		||||
 | 
			
		||||
#elif GTEST_OS_WINDOWS
 | 
			
		||||
 | 
			
		||||
#include <direct.h>  // NOLINT
 | 
			
		||||
#include <io.h>  // NOLINT
 | 
			
		||||
 | 
			
		||||
// <regex.h> is not available on Windows.  Use our own simple regex
 | 
			
		||||
// implementation instead.
 | 
			
		||||
#define GTEST_USES_SIMPLE_RE 1
 | 
			
		||||
 | 
			
		||||
#else
 | 
			
		||||
 | 
			
		||||
// <regex.h> may not be available on this platform.  Use our own
 | 
			
		||||
@@ -381,7 +397,7 @@
 | 
			
		||||
                             GTEST_OS_CYGWIN || \
 | 
			
		||||
                             (GTEST_OS_WINDOWS && _MSC_VER >= 1400))
 | 
			
		||||
#define GTEST_HAS_DEATH_TEST 1
 | 
			
		||||
#include <vector>
 | 
			
		||||
#include <vector>  // NOLINT
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
// Determines whether to support value-parameterized tests.
 | 
			
		||||
@@ -701,18 +717,108 @@ struct is_pointer<T*> : public true_type {};
 | 
			
		||||
 | 
			
		||||
#if GTEST_OS_WINDOWS
 | 
			
		||||
#define GTEST_PATH_SEP_ "\\"
 | 
			
		||||
#else
 | 
			
		||||
#define GTEST_PATH_SEP_ "/"
 | 
			
		||||
#endif  // GTEST_OS_WINDOWS
 | 
			
		||||
 | 
			
		||||
// Defines BiggestInt as the biggest signed integer type the compiler
 | 
			
		||||
// supports.
 | 
			
		||||
#if GTEST_OS_WINDOWS
 | 
			
		||||
// The biggest signed integer type the compiler supports.
 | 
			
		||||
typedef __int64 BiggestInt;
 | 
			
		||||
#else
 | 
			
		||||
#define GTEST_PATH_SEP_ "/"
 | 
			
		||||
typedef long long BiggestInt;  // NOLINT
 | 
			
		||||
#endif  // GTEST_OS_WINDOWS
 | 
			
		||||
 | 
			
		||||
// The testing::internal::posix namespace holds wrappers for common
 | 
			
		||||
// POSIX functions.  These wrappers hide the differences between
 | 
			
		||||
// Windows/MSVC and POSIX systems.
 | 
			
		||||
namespace posix {
 | 
			
		||||
 | 
			
		||||
// Functions with a different name on Windows.
 | 
			
		||||
 | 
			
		||||
#if GTEST_OS_WINDOWS
 | 
			
		||||
 | 
			
		||||
typedef struct _stat stat_struct;
 | 
			
		||||
 | 
			
		||||
inline int chdir(const char* dir) { return ::_chdir(dir); }
 | 
			
		||||
inline int fileno(FILE* file) { return _fileno(file); }
 | 
			
		||||
inline int isatty(int fd) { return ::_isatty(fd); }
 | 
			
		||||
inline int stat(const char* path, stat_struct* buf) { return ::_stat(path, buf); }
 | 
			
		||||
inline int strcasecmp(const char* s1, const char* s2) {
 | 
			
		||||
  return ::_stricmp(s1, s2);
 | 
			
		||||
}
 | 
			
		||||
inline const char* strdup(const char* src) { return ::_strdup(src); }
 | 
			
		||||
inline int rmdir(const char* dir) { return ::_rmdir(dir); }
 | 
			
		||||
inline bool IsDir(const stat_struct& st) {
 | 
			
		||||
  return (_S_IFDIR & st.st_mode) != 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#else
 | 
			
		||||
 | 
			
		||||
typedef struct stat stat_struct;
 | 
			
		||||
 | 
			
		||||
using ::chdir;
 | 
			
		||||
using ::fileno;
 | 
			
		||||
using ::isatty;
 | 
			
		||||
using ::stat;
 | 
			
		||||
using ::strcasecmp;
 | 
			
		||||
using ::strdup;
 | 
			
		||||
using ::rmdir;
 | 
			
		||||
inline bool IsDir(const stat_struct& st) { return S_ISDIR(st.st_mode); }
 | 
			
		||||
 | 
			
		||||
#endif  // GTEST_OS_WINDOWS
 | 
			
		||||
 | 
			
		||||
// Functions deprecated by MSVC 8.0.
 | 
			
		||||
 | 
			
		||||
#ifdef _MSC_VER
 | 
			
		||||
// Temporarily disable warning 4996 (deprecated function).
 | 
			
		||||
#pragma warning(push)
 | 
			
		||||
#pragma warning(disable:4996)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
inline const char* strncpy(char* dest, const char* src, size_t n) {
 | 
			
		||||
  return ::strncpy(dest, src, n);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
inline FILE* fopen(const char* path, const char* mode) {
 | 
			
		||||
  return ::fopen(path, mode);
 | 
			
		||||
}
 | 
			
		||||
inline FILE *freopen(const char *path, const char *mode, FILE *stream) {
 | 
			
		||||
  return ::freopen(path, mode, stream);
 | 
			
		||||
}
 | 
			
		||||
inline FILE* fdopen(int fd, const char* mode) {
 | 
			
		||||
  return ::fdopen(fd, mode);
 | 
			
		||||
}
 | 
			
		||||
inline int fclose(FILE *fp) { return ::fclose(fp); }
 | 
			
		||||
 | 
			
		||||
inline int read(int fd, void* buf, size_t count) {
 | 
			
		||||
  return static_cast<int>(::read(fd, buf, count));
 | 
			
		||||
}
 | 
			
		||||
inline int write(int fd, const void* buf, size_t count) {
 | 
			
		||||
  return static_cast<int>(::write(fd, buf, count));
 | 
			
		||||
}
 | 
			
		||||
inline int close(int fd) { return ::close(fd); }
 | 
			
		||||
 | 
			
		||||
inline const char* strerror(int errnum) { return ::strerror(errnum); }
 | 
			
		||||
 | 
			
		||||
inline const char* getenv(const char* name) {
 | 
			
		||||
#ifdef _WIN32_WCE  // We are on Windows CE, which has no environment variables.
 | 
			
		||||
  return NULL;
 | 
			
		||||
#else
 | 
			
		||||
  return ::getenv(name);
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef _MSC_VER
 | 
			
		||||
#pragma warning(pop)  // Restores the warning state.
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef _WIN32_WCE
 | 
			
		||||
// Windows CE has no C library. The abort() function is used in
 | 
			
		||||
// several places in Google Test. This implementation provides a reasonable
 | 
			
		||||
// imitation of standard behaviour.
 | 
			
		||||
void abort();
 | 
			
		||||
#else
 | 
			
		||||
using ::abort;
 | 
			
		||||
#endif  // _WIN32_WCE
 | 
			
		||||
 | 
			
		||||
}  // namespace posix
 | 
			
		||||
 | 
			
		||||
// The maximum number a BiggestInt can represent.  This definition
 | 
			
		||||
// works no matter BiggestInt is represented in one's complement or
 | 
			
		||||
// two's complement.
 | 
			
		||||
@@ -783,32 +889,6 @@ typedef TypeWithSize<8>::Int TimeInMillis;  // Represents time in milliseconds.
 | 
			
		||||
 | 
			
		||||
// Utilities for command line flags and environment variables.
 | 
			
		||||
 | 
			
		||||
// A wrapper for getenv() that works on Linux, Windows, and Mac OS.
 | 
			
		||||
inline const char* GetEnv(const char* name) {
 | 
			
		||||
#ifdef _WIN32_WCE  // We are on Windows CE.
 | 
			
		||||
  // CE has no environment variables.
 | 
			
		||||
  return NULL;
 | 
			
		||||
#elif GTEST_OS_WINDOWS  // We are on Windows proper.
 | 
			
		||||
  // MSVC 8 deprecates getenv(), so we want to suppress warning 4996
 | 
			
		||||
  // (deprecated function) there.
 | 
			
		||||
#pragma warning(push)          // Saves the current warning state.
 | 
			
		||||
#pragma warning(disable:4996)  // Temporarily disables warning 4996.
 | 
			
		||||
  return getenv(name);
 | 
			
		||||
#pragma warning(pop)           // Restores the warning state.
 | 
			
		||||
#else  // We are on Linux or Mac OS.
 | 
			
		||||
  return getenv(name);
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#ifdef _WIN32_WCE
 | 
			
		||||
// Windows CE has no C library. The abort() function is used in
 | 
			
		||||
// several places in Google Test. This implementation provides a reasonable
 | 
			
		||||
// imitation of standard behaviour.
 | 
			
		||||
void abort();
 | 
			
		||||
#else
 | 
			
		||||
inline void abort() { ::abort(); }
 | 
			
		||||
#endif  // _WIN32_WCE
 | 
			
		||||
 | 
			
		||||
// INTERNAL IMPLEMENTATION - DO NOT USE.
 | 
			
		||||
//
 | 
			
		||||
// GTEST_CHECK_ is an all-mode assert. It aborts the program if the condition
 | 
			
		||||
 
 | 
			
		||||
@@ -48,7 +48,6 @@
 | 
			
		||||
#if GTEST_OS_WINDOWS
 | 
			
		||||
#include <windows.h>
 | 
			
		||||
#else
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#include <sys/mman.h>
 | 
			
		||||
#include <sys/wait.h>
 | 
			
		||||
#endif  // GTEST_OS_WINDOWS
 | 
			
		||||
@@ -205,15 +204,7 @@ void DeathTestAbort(const String& message) {
 | 
			
		||||
  const InternalRunDeathTestFlag* const flag =
 | 
			
		||||
      GetUnitTestImpl()->internal_run_death_test_flag();
 | 
			
		||||
  if (flag != NULL) {
 | 
			
		||||
#ifdef _MSC_VER
 | 
			
		||||
#pragma warning(push)
 | 
			
		||||
#pragma warning(disable: 4996)  // Suppresses deprecation warning
 | 
			
		||||
                                // about POSIX functions in MSVC.
 | 
			
		||||
#endif  // _MSC_VER
 | 
			
		||||
    FILE* parent = fdopen(flag->write_fd(), "w");
 | 
			
		||||
#ifdef _MSC_VER
 | 
			
		||||
#pragma warning(pop)
 | 
			
		||||
#endif  // _MSC_VER
 | 
			
		||||
    FILE* parent = posix::fdopen(flag->write_fd(), "w");
 | 
			
		||||
    fputc(kDeathTestInternalError, parent);
 | 
			
		||||
    fprintf(parent, "%s", message.c_str());
 | 
			
		||||
    fflush(parent);
 | 
			
		||||
@@ -258,15 +249,7 @@ void DeathTestAbort(const String& message) {
 | 
			
		||||
 | 
			
		||||
// Returns the message describing the last system error in errno.
 | 
			
		||||
String GetLastErrnoDescription() {
 | 
			
		||||
#ifdef _MSC_VER
 | 
			
		||||
#pragma warning(push)
 | 
			
		||||
#pragma warning(disable: 4996)  // Suppresses deprecation warning
 | 
			
		||||
                                // about POSIX functions in MSVC.
 | 
			
		||||
#endif  // _MSC_VER
 | 
			
		||||
    return String(errno == 0 ? "" : strerror(errno));
 | 
			
		||||
#ifdef _MSC_VER
 | 
			
		||||
#pragma warning(pop)
 | 
			
		||||
#endif  // _MSC_VER
 | 
			
		||||
    return String(errno == 0 ? "" : posix::strerror(errno));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// This is called from a death test parent process to read a failure
 | 
			
		||||
@@ -279,15 +262,7 @@ static void FailFromInternalError(int fd) {
 | 
			
		||||
  int num_read;
 | 
			
		||||
 | 
			
		||||
  do {
 | 
			
		||||
#ifdef _MSC_VER
 | 
			
		||||
#pragma warning(push)
 | 
			
		||||
#pragma warning(disable: 4996)  // Suppresses deprecation warning
 | 
			
		||||
                                // about POSIX functions in MSVC.
 | 
			
		||||
#endif  // _MSC_VER
 | 
			
		||||
    while ((num_read = static_cast<int>(read(fd, buffer, 255))) > 0) {
 | 
			
		||||
#ifdef _MSC_VER
 | 
			
		||||
#pragma warning(pop)
 | 
			
		||||
#endif  // _MSC_VER
 | 
			
		||||
    while ((num_read = posix::read(fd, buffer, 255)) > 0) {
 | 
			
		||||
      buffer[num_read] = '\0';
 | 
			
		||||
      error << buffer;
 | 
			
		||||
    }
 | 
			
		||||
@@ -397,11 +372,6 @@ class DeathTestImpl : public DeathTest {
 | 
			
		||||
// member, and closes read_fd_.  Outputs diagnostics and terminates in
 | 
			
		||||
// case of unexpected codes.
 | 
			
		||||
void DeathTestImpl::ReadAndInterpretStatusByte() {
 | 
			
		||||
#ifdef _MSC_VER
 | 
			
		||||
#pragma warning(push)
 | 
			
		||||
#pragma warning(disable: 4996)  // Suppresses deprecation warning
 | 
			
		||||
                                // about POSIX functions in MSVC.
 | 
			
		||||
#endif  // _MSC_VER
 | 
			
		||||
  char flag;
 | 
			
		||||
  int bytes_read;
 | 
			
		||||
 | 
			
		||||
@@ -410,7 +380,7 @@ void DeathTestImpl::ReadAndInterpretStatusByte() {
 | 
			
		||||
  // its success), so it's okay to call this in the parent before
 | 
			
		||||
  // the child process has exited.
 | 
			
		||||
  do {
 | 
			
		||||
    bytes_read = static_cast<int>(read(read_fd(), &flag, 1));
 | 
			
		||||
    bytes_read = posix::read(read_fd(), &flag, 1);
 | 
			
		||||
  } while (bytes_read == -1 && errno == EINTR);
 | 
			
		||||
 | 
			
		||||
  if (bytes_read == 0) {
 | 
			
		||||
@@ -437,11 +407,8 @@ void DeathTestImpl::ReadAndInterpretStatusByte() {
 | 
			
		||||
               Message() << "Read from death test child process failed: "
 | 
			
		||||
                         << GetLastErrnoDescription());
 | 
			
		||||
  }
 | 
			
		||||
  GTEST_DEATH_TEST_CHECK_SYSCALL_(close(read_fd()));
 | 
			
		||||
  GTEST_DEATH_TEST_CHECK_SYSCALL_(posix::close(read_fd()));
 | 
			
		||||
  set_read_fd(-1);
 | 
			
		||||
#ifdef _MSC_VER
 | 
			
		||||
#pragma warning(pop)
 | 
			
		||||
#endif  // _MSC_VER
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// Signals that the death test code which should have exited, didn't.
 | 
			
		||||
@@ -454,18 +421,8 @@ void DeathTestImpl::Abort(AbortReason reason) {
 | 
			
		||||
  // to the pipe, then exit.
 | 
			
		||||
  const char status_ch =
 | 
			
		||||
      reason == TEST_DID_NOT_DIE ? kDeathTestLived : kDeathTestReturned;
 | 
			
		||||
 | 
			
		||||
#ifdef _MSC_VER
 | 
			
		||||
#pragma warning(push)
 | 
			
		||||
#pragma warning(disable: 4996)  // Suppresses deprecation warning
 | 
			
		||||
                                // about POSIX functions.
 | 
			
		||||
#endif  // _MSC_VER
 | 
			
		||||
  GTEST_DEATH_TEST_CHECK_SYSCALL_(write(write_fd(), &status_ch, 1));
 | 
			
		||||
  GTEST_DEATH_TEST_CHECK_SYSCALL_(close(write_fd()));
 | 
			
		||||
#ifdef _MSC_VER
 | 
			
		||||
#pragma warning(pop)
 | 
			
		||||
#endif  // _MSC_VER
 | 
			
		||||
 | 
			
		||||
  GTEST_DEATH_TEST_CHECK_SYSCALL_(posix::write(write_fd(), &status_ch, 1));
 | 
			
		||||
  GTEST_DEATH_TEST_CHECK_SYSCALL_(posix::close(write_fd()));
 | 
			
		||||
  _exit(1);  // Exits w/o any normal exit hooks (we were supposed to crash)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -33,22 +33,17 @@
 | 
			
		||||
#include <gtest/internal/gtest-port.h>
 | 
			
		||||
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
 | 
			
		||||
#ifdef _WIN32_WCE
 | 
			
		||||
#include <windows.h>
 | 
			
		||||
#elif GTEST_OS_WINDOWS
 | 
			
		||||
#include <direct.h>
 | 
			
		||||
#include <io.h>
 | 
			
		||||
#include <sys/stat.h>
 | 
			
		||||
#elif GTEST_OS_SYMBIAN
 | 
			
		||||
// Symbian OpenC has PATH_MAX in sys/syslimits.h
 | 
			
		||||
#include <sys/syslimits.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#else
 | 
			
		||||
#include <limits.h>
 | 
			
		||||
#include <sys/stat.h>  // NOLINT
 | 
			
		||||
#include <unistd.h>  // NOLINT
 | 
			
		||||
#include <climits>  // Some Linux distributions define PATH_MAX here.
 | 
			
		||||
#endif  // _WIN32_WCE or _WIN32
 | 
			
		||||
 | 
			
		||||
@@ -172,13 +167,9 @@ bool FilePath::FileOrDirectoryExists() const {
 | 
			
		||||
  const DWORD attributes = GetFileAttributes(unicode);
 | 
			
		||||
  delete [] unicode;
 | 
			
		||||
  return attributes != kInvalidFileAttributes;
 | 
			
		||||
#elif GTEST_OS_WINDOWS
 | 
			
		||||
  struct _stat file_stat = {};
 | 
			
		||||
  return _stat(pathname_.c_str(), &file_stat) == 0;
 | 
			
		||||
#else
 | 
			
		||||
  struct stat file_stat;
 | 
			
		||||
  memset(&file_stat, 0, sizeof(file_stat));
 | 
			
		||||
  return stat(pathname_.c_str(), &file_stat) == 0;
 | 
			
		||||
  posix::stat_struct file_stat;
 | 
			
		||||
  return posix::stat(pathname_.c_str(), &file_stat) == 0;
 | 
			
		||||
#endif  // _WIN32_WCE
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -191,6 +182,10 @@ bool FilePath::DirectoryExists() const {
 | 
			
		||||
  // Windows (like "C:\\").
 | 
			
		||||
  const FilePath& path(IsRootDirectory() ? *this :
 | 
			
		||||
                                           RemoveTrailingPathSeparator());
 | 
			
		||||
#else
 | 
			
		||||
  const FilePath& path(*this);
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef _WIN32_WCE
 | 
			
		||||
  LPCWSTR unicode = String::AnsiToUtf16(path.c_str());
 | 
			
		||||
  const DWORD attributes = GetFileAttributes(unicode);
 | 
			
		||||
@@ -200,16 +195,11 @@ bool FilePath::DirectoryExists() const {
 | 
			
		||||
    result = true;
 | 
			
		||||
  }
 | 
			
		||||
#else
 | 
			
		||||
  struct _stat file_stat = {};
 | 
			
		||||
  result = _stat(path.c_str(), &file_stat) == 0 &&
 | 
			
		||||
      (_S_IFDIR & file_stat.st_mode) != 0;
 | 
			
		||||
  posix::stat_struct file_stat;
 | 
			
		||||
  result = posix::stat(path.c_str(), &file_stat) == 0 &&
 | 
			
		||||
      posix::IsDir(file_stat);
 | 
			
		||||
#endif  // _WIN32_WCE
 | 
			
		||||
#else
 | 
			
		||||
  struct stat file_stat;
 | 
			
		||||
  memset(&file_stat, 0, sizeof(file_stat));
 | 
			
		||||
  result = stat(pathname_.c_str(), &file_stat) == 0 &&
 | 
			
		||||
      S_ISDIR(file_stat.st_mode);
 | 
			
		||||
#endif  // GTEST_OS_WINDOWS
 | 
			
		||||
 | 
			
		||||
  return result;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -42,10 +42,6 @@
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
#endif  // GTEST_OS_WINDOWS
 | 
			
		||||
 | 
			
		||||
#if GTEST_USES_SIMPLE_RE
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef _WIN32_WCE
 | 
			
		||||
#include <windows.h>  // For TerminateProcess()
 | 
			
		||||
#endif  // _WIN32_WCE
 | 
			
		||||
@@ -350,11 +346,7 @@ bool RE::PartialMatch(const char* str, const RE& re) {
 | 
			
		||||
void RE::Init(const char* regex) {
 | 
			
		||||
  pattern_ = full_pattern_ = NULL;
 | 
			
		||||
  if (regex != NULL) {
 | 
			
		||||
#if GTEST_OS_WINDOWS
 | 
			
		||||
    pattern_ = _strdup(regex);
 | 
			
		||||
#else
 | 
			
		||||
    pattern_ = strdup(regex);
 | 
			
		||||
#endif
 | 
			
		||||
    pattern_ = posix::strdup(regex);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  is_valid_ = ValidateRegex(regex);
 | 
			
		||||
@@ -510,17 +502,9 @@ void CaptureStderr() {
 | 
			
		||||
::std::string GetCapturedStderr() {
 | 
			
		||||
  g_captured_stderr->StopCapture();
 | 
			
		||||
 | 
			
		||||
// Disables Microsoft deprecation warning for fopen and fclose.
 | 
			
		||||
#ifdef _MSC_VER
 | 
			
		||||
#pragma warning(push)
 | 
			
		||||
#pragma warning(disable: 4996)
 | 
			
		||||
#endif  // _MSC_VER
 | 
			
		||||
  FILE* const file = fopen(g_captured_stderr->filename().c_str(), "r");
 | 
			
		||||
  FILE* const file = posix::fopen(g_captured_stderr->filename().c_str(), "r");
 | 
			
		||||
  const ::std::string content = ReadEntireFile(file);
 | 
			
		||||
  fclose(file);
 | 
			
		||||
#ifdef _MSC_VER
 | 
			
		||||
#pragma warning(pop)
 | 
			
		||||
#endif  // _MSC_VER
 | 
			
		||||
  posix::fclose(file);
 | 
			
		||||
 | 
			
		||||
  delete g_captured_stderr;
 | 
			
		||||
  g_captured_stderr = NULL;
 | 
			
		||||
@@ -541,10 +525,12 @@ const ::std::vector<String>& GetArgvs() { return g_argvs; }
 | 
			
		||||
#endif  // GTEST_HAS_DEATH_TEST
 | 
			
		||||
 | 
			
		||||
#ifdef _WIN32_WCE
 | 
			
		||||
namespace posix {
 | 
			
		||||
void abort() {
 | 
			
		||||
  DebugBreak();
 | 
			
		||||
  TerminateProcess(GetCurrentProcess(), 1);
 | 
			
		||||
}
 | 
			
		||||
}  // namespace posix
 | 
			
		||||
#endif  // _WIN32_WCE
 | 
			
		||||
 | 
			
		||||
// Returns the name of the environment variable corresponding to the
 | 
			
		||||
@@ -609,7 +595,7 @@ bool ParseInt32(const Message& src_text, const char* str, Int32* value) {
 | 
			
		||||
// The value is considered true iff it's not "0".
 | 
			
		||||
bool BoolFromGTestEnv(const char* flag, bool default_value) {
 | 
			
		||||
  const String env_var = FlagToEnvVar(flag);
 | 
			
		||||
  const char* const string_value = GetEnv(env_var.c_str());
 | 
			
		||||
  const char* const string_value = posix::getenv(env_var.c_str());
 | 
			
		||||
  return string_value == NULL ?
 | 
			
		||||
      default_value : strcmp(string_value, "0") != 0;
 | 
			
		||||
}
 | 
			
		||||
@@ -619,7 +605,7 @@ bool BoolFromGTestEnv(const char* flag, bool default_value) {
 | 
			
		||||
// doesn't represent a valid 32-bit integer, returns default_value.
 | 
			
		||||
Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) {
 | 
			
		||||
  const String env_var = FlagToEnvVar(flag);
 | 
			
		||||
  const char* const string_value = GetEnv(env_var.c_str());
 | 
			
		||||
  const char* const string_value = posix::getenv(env_var.c_str());
 | 
			
		||||
  if (string_value == NULL) {
 | 
			
		||||
    // The environment variable is not set.
 | 
			
		||||
    return default_value;
 | 
			
		||||
@@ -641,7 +627,7 @@ Int32 Int32FromGTestEnv(const char* flag, Int32 default_value) {
 | 
			
		||||
// the given flag; if it's not set, returns default_value.
 | 
			
		||||
const char* StringFromGTestEnv(const char* flag, const char* default_value) {
 | 
			
		||||
  const String env_var = FlagToEnvVar(flag);
 | 
			
		||||
  const char* const value = GetEnv(env_var.c_str());
 | 
			
		||||
  const char* const value = posix::getenv(env_var.c_str());
 | 
			
		||||
  return value == NULL ? default_value : value;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -81,7 +81,7 @@ void TestPartResultArray::Append(const TestPartResult& result) {
 | 
			
		||||
const TestPartResult& TestPartResultArray::GetTestPartResult(int index) const {
 | 
			
		||||
  if (index < 0 || index >= size()) {
 | 
			
		||||
    printf("\nInvalid index (%d) into TestPartResultArray.\n", index);
 | 
			
		||||
    internal::abort();
 | 
			
		||||
    internal::posix::abort();
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const internal::ListNode<TestPartResult>* p = list_->Head();
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										81
									
								
								src/gtest.cc
									
									
									
									
									
								
							
							
						
						
									
										81
									
								
								src/gtest.cc
									
									
									
									
									
								
							@@ -39,7 +39,6 @@
 | 
			
		||||
#include <stdarg.h>
 | 
			
		||||
#include <stdio.h>
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <wchar.h>
 | 
			
		||||
#include <wctype.h>
 | 
			
		||||
 | 
			
		||||
@@ -125,8 +124,6 @@
 | 
			
		||||
#undef GTEST_IMPLEMENTATION_
 | 
			
		||||
 | 
			
		||||
#if GTEST_OS_WINDOWS
 | 
			
		||||
#define fileno _fileno
 | 
			
		||||
#define isatty _isatty
 | 
			
		||||
#define vsnprintf _vsnprintf
 | 
			
		||||
#endif  // GTEST_OS_WINDOWS
 | 
			
		||||
 | 
			
		||||
@@ -806,16 +803,7 @@ static char* CloneString(const char* str, size_t length) {
 | 
			
		||||
    return NULL;
 | 
			
		||||
  } else {
 | 
			
		||||
    char* const clone = new char[length + 1];
 | 
			
		||||
    // MSVC 8 deprecates strncpy(), so we want to suppress warning
 | 
			
		||||
    // 4996 (deprecated function) there.
 | 
			
		||||
#if GTEST_OS_WINDOWS  // We are on Windows.
 | 
			
		||||
#pragma warning(push)          // Saves the current warning state.
 | 
			
		||||
#pragma warning(disable:4996)  // Temporarily disables warning 4996.
 | 
			
		||||
    strncpy(clone, str, length);
 | 
			
		||||
#pragma warning(pop)           // Restores the warning state.
 | 
			
		||||
#else  // We are on Linux or Mac OS.
 | 
			
		||||
    strncpy(clone, str, length);
 | 
			
		||||
#endif  // GTEST_OS_WINDOWS
 | 
			
		||||
    posix::strncpy(clone, str, length);
 | 
			
		||||
    clone[length] = '\0';
 | 
			
		||||
    return clone;
 | 
			
		||||
  }
 | 
			
		||||
@@ -1455,17 +1443,8 @@ char* CodePointToUtf8(UInt32 code_point, char* str) {
 | 
			
		||||
    // the terminating nul character). We are asking for 32 character
 | 
			
		||||
    // buffer just in case. This is also enough for strncpy to
 | 
			
		||||
    // null-terminate the destination string.
 | 
			
		||||
    // MSVC 8 deprecates strncpy(), so we want to suppress warning
 | 
			
		||||
    // 4996 (deprecated function) there.
 | 
			
		||||
#if GTEST_OS_WINDOWS  // We are on Windows.
 | 
			
		||||
#pragma warning(push)          // Saves the current warning state.
 | 
			
		||||
#pragma warning(disable:4996)  // Temporarily disables warning 4996.
 | 
			
		||||
#endif
 | 
			
		||||
    strncpy(str, String::Format("(Invalid Unicode 0x%X)", code_point).c_str(),
 | 
			
		||||
            32);
 | 
			
		||||
#if GTEST_OS_WINDOWS  // We are on Windows.
 | 
			
		||||
#pragma warning(pop)  // Restores the warning state.
 | 
			
		||||
#endif
 | 
			
		||||
    posix::strncpy(
 | 
			
		||||
        str, String::Format("(Invalid Unicode 0x%X)", code_point).c_str(), 32);
 | 
			
		||||
    str[31] = '\0';  // Makes sure no change in the format to strncpy leaves
 | 
			
		||||
                     // the result unterminated.
 | 
			
		||||
  }
 | 
			
		||||
@@ -1603,15 +1582,11 @@ AssertionResult CmpHelperSTRNE(const char* s1_expression,
 | 
			
		||||
// NULL C string is considered different to any non-NULL C string,
 | 
			
		||||
// including the empty string.
 | 
			
		||||
bool String::CaseInsensitiveCStringEquals(const char * lhs, const char * rhs) {
 | 
			
		||||
  if ( lhs == NULL ) return rhs == NULL;
 | 
			
		||||
 | 
			
		||||
  if ( rhs == NULL ) return false;
 | 
			
		||||
 | 
			
		||||
#if GTEST_OS_WINDOWS
 | 
			
		||||
  return _stricmp(lhs, rhs) == 0;
 | 
			
		||||
#else  // GTEST_OS_WINDOWS
 | 
			
		||||
  return strcasecmp(lhs, rhs) == 0;
 | 
			
		||||
#endif  // GTEST_OS_WINDOWS
 | 
			
		||||
  if (lhs == NULL)
 | 
			
		||||
    return rhs == NULL;
 | 
			
		||||
  if (rhs == NULL)
 | 
			
		||||
    return false;
 | 
			
		||||
  return posix::strcasecmp(lhs, rhs) == 0;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
  // Compares two wide C strings, ignoring case.  Returns true iff they
 | 
			
		||||
@@ -2519,7 +2494,7 @@ bool ShouldUseColor(bool stdout_is_tty) {
 | 
			
		||||
    return stdout_is_tty;
 | 
			
		||||
#else
 | 
			
		||||
    // On non-Windows platforms, we rely on the TERM variable.
 | 
			
		||||
    const char* const term = GetEnv("TERM");
 | 
			
		||||
    const char* const term = posix::getenv("TERM");
 | 
			
		||||
    const bool term_supports_color =
 | 
			
		||||
        String::CStringEquals(term, "xterm") ||
 | 
			
		||||
        String::CStringEquals(term, "xterm-color") ||
 | 
			
		||||
@@ -2549,7 +2524,7 @@ void ColoredPrintf(GTestColor color, const char* fmt, ...) {
 | 
			
		||||
  const bool use_color = false;
 | 
			
		||||
#else
 | 
			
		||||
  static const bool in_color_mode =
 | 
			
		||||
      ShouldUseColor(isatty(fileno(stdout)) != 0);
 | 
			
		||||
      ShouldUseColor(posix::isatty(posix::fileno(stdout)) != 0);
 | 
			
		||||
  const bool use_color = in_color_mode && (color != COLOR_DEFAULT);
 | 
			
		||||
#endif  // defined(_WIN32_WCE) || GTEST_OS_SYMBIAN || GTEST_OS_ZOS
 | 
			
		||||
  // The '!= 0' comparison is necessary to satisfy MSVC 7.1.
 | 
			
		||||
@@ -2631,8 +2606,8 @@ void PrettyUnitTestResultPrinter::OnUnitTestStart(
 | 
			
		||||
  if (internal::ShouldShard(kTestTotalShards, kTestShardIndex, false)) {
 | 
			
		||||
    ColoredPrintf(COLOR_YELLOW,
 | 
			
		||||
                  "Note: This is test shard %s of %s.\n",
 | 
			
		||||
                  internal::GetEnv(kTestShardIndex),
 | 
			
		||||
                  internal::GetEnv(kTestTotalShards));
 | 
			
		||||
                  internal::posix::getenv(kTestShardIndex),
 | 
			
		||||
                  internal::posix::getenv(kTestTotalShards));
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  const internal::UnitTestImpl* const impl = unit_test->impl();
 | 
			
		||||
@@ -2950,17 +2925,7 @@ void XmlUnitTestResultPrinter::OnUnitTestEnd(const UnitTest* unit_test) {
 | 
			
		||||
  internal::FilePath output_dir(output_file.RemoveFileName());
 | 
			
		||||
 | 
			
		||||
  if (output_dir.CreateDirectoriesRecursively()) {
 | 
			
		||||
  // MSVC 8 deprecates fopen(), so we want to suppress warning 4996
 | 
			
		||||
  // (deprecated function) there.
 | 
			
		||||
#if GTEST_OS_WINDOWS
 | 
			
		||||
  // We are on Windows.
 | 
			
		||||
#pragma warning(push)          // Saves the current warning state.
 | 
			
		||||
#pragma warning(disable:4996)  // Temporarily disables warning 4996.
 | 
			
		||||
    xmlout = fopen(output_file_.c_str(), "w");
 | 
			
		||||
#pragma warning(pop)           // Restores the warning state.
 | 
			
		||||
#else  // We are on Linux or Mac OS.
 | 
			
		||||
    xmlout = fopen(output_file_.c_str(), "w");
 | 
			
		||||
#endif  // GTEST_OS_WINDOWS
 | 
			
		||||
    xmlout = internal::posix::fopen(output_file_.c_str(), "w");
 | 
			
		||||
  }
 | 
			
		||||
  if (xmlout == NULL) {
 | 
			
		||||
    // TODO(wan): report the reason of the failure.
 | 
			
		||||
@@ -3697,17 +3662,9 @@ int UnitTestImpl::RunAllTests() {
 | 
			
		||||
// function will write over it. If the variable is present, but the file cannot
 | 
			
		||||
// be created, prints an error and exits.
 | 
			
		||||
void WriteToShardStatusFileIfNeeded() {
 | 
			
		||||
  const char* const test_shard_file = GetEnv(kTestShardStatusFile);
 | 
			
		||||
  const char* const test_shard_file = posix::getenv(kTestShardStatusFile);
 | 
			
		||||
  if (test_shard_file != NULL) {
 | 
			
		||||
#ifdef _MSC_VER  // MSVC 8 deprecates fopen().
 | 
			
		||||
#pragma warning(push)          // Saves the current warning state.
 | 
			
		||||
#pragma warning(disable:4996)  // Temporarily disables warning on
 | 
			
		||||
                               // deprecated functions.
 | 
			
		||||
#endif
 | 
			
		||||
    FILE* const file = fopen(test_shard_file, "w");
 | 
			
		||||
#ifdef _MSC_VER
 | 
			
		||||
#pragma warning(pop)           // Restores the warning state.
 | 
			
		||||
#endif
 | 
			
		||||
    FILE* const file = posix::fopen(test_shard_file, "w");
 | 
			
		||||
    if (file == NULL) {
 | 
			
		||||
      ColoredPrintf(COLOR_RED,
 | 
			
		||||
                    "Could not write to the test shard status file \"%s\" "
 | 
			
		||||
@@ -3772,7 +3729,7 @@ bool ShouldShard(const char* total_shards_env,
 | 
			
		||||
// returns default_val. If it is not an Int32, prints an error
 | 
			
		||||
// and aborts.
 | 
			
		||||
Int32 Int32FromEnvOrDie(const char* const var, Int32 default_val) {
 | 
			
		||||
  const char* str_val = GetEnv(var);
 | 
			
		||||
  const char* str_val = posix::getenv(var);
 | 
			
		||||
  if (str_val == NULL) {
 | 
			
		||||
    return default_val;
 | 
			
		||||
  }
 | 
			
		||||
@@ -4175,7 +4132,11 @@ static const char kColorEncodedHelpMessage[] =
 | 
			
		||||
"      Generate an XML report in the given directory or with the given file\n"
 | 
			
		||||
"      name. @YFILE_PATH@D defaults to @Gtest_details.xml@D.\n"
 | 
			
		||||
"\n"
 | 
			
		||||
"Failure Behavior:\n"
 | 
			
		||||
"Assertion Behavior:\n"
 | 
			
		||||
#if GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS
 | 
			
		||||
"  @G--" GTEST_FLAG_PREFIX_ "death_test_style=@Y(@Gfast@Y|@Gthreadsafe@Y)@D\n"
 | 
			
		||||
"      Set the default death test style.\n"
 | 
			
		||||
#endif  // GTEST_HAS_DEATH_TEST && !GTEST_OS_WINDOWS
 | 
			
		||||
"  @G--" GTEST_FLAG_PREFIX_ "break_on_failure@D\n"
 | 
			
		||||
"      Turn assertion failures into debugger break-points.\n"
 | 
			
		||||
"  @G--" GTEST_FLAG_PREFIX_ "throw_on_failure@D\n"
 | 
			
		||||
 
 | 
			
		||||
@@ -60,8 +60,9 @@
 | 
			
		||||
#include "src/gtest-internal-inl.h"
 | 
			
		||||
#undef GTEST_IMPLEMENTATION_
 | 
			
		||||
 | 
			
		||||
using testing::Message;
 | 
			
		||||
namespace posix = ::testing::internal::posix;
 | 
			
		||||
 | 
			
		||||
using testing::Message;
 | 
			
		||||
using testing::internal::DeathTest;
 | 
			
		||||
using testing::internal::DeathTestFactory;
 | 
			
		||||
using testing::internal::FilePath;
 | 
			
		||||
@@ -105,11 +106,7 @@ class TestForDeathTest : public testing::Test {
 | 
			
		||||
  TestForDeathTest() : original_dir_(FilePath::GetCurrentDir()) {}
 | 
			
		||||
 | 
			
		||||
  virtual ~TestForDeathTest() {
 | 
			
		||||
#if GTEST_OS_WINDOWS
 | 
			
		||||
    _chdir(original_dir_.c_str());
 | 
			
		||||
#else
 | 
			
		||||
    chdir(original_dir_.c_str());
 | 
			
		||||
#endif
 | 
			
		||||
    posix::chdir(original_dir_.c_str());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  // A static member function that's expected to die.
 | 
			
		||||
@@ -348,13 +345,7 @@ TEST_F(TestForDeathTest, MemberFunctionFastStyle) {
 | 
			
		||||
  EXPECT_DEATH(MemberFunction(), "inside.*MemberFunction");
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ChangeToRootDir() {
 | 
			
		||||
#if GTEST_OS_WINDOWS
 | 
			
		||||
  _chdir("\\");
 | 
			
		||||
#else
 | 
			
		||||
  chdir("/");
 | 
			
		||||
#endif  // GTEST_OS_WINDOWS
 | 
			
		||||
}
 | 
			
		||||
void ChangeToRootDir() { posix::chdir(GTEST_PATH_SEP_); }
 | 
			
		||||
 | 
			
		||||
// Tests that death tests work even if the current directory has been
 | 
			
		||||
// changed.
 | 
			
		||||
 
 | 
			
		||||
@@ -86,18 +86,17 @@ TEST(GetCurrentDirTest, ReturnsCurrentDir) {
 | 
			
		||||
  const FilePath original_dir = FilePath::GetCurrentDir();
 | 
			
		||||
  EXPECT_FALSE(original_dir.IsEmpty());
 | 
			
		||||
 | 
			
		||||
#if GTEST_OS_WINDOWS
 | 
			
		||||
  _chdir(GTEST_PATH_SEP_);
 | 
			
		||||
  posix::chdir(GTEST_PATH_SEP_);
 | 
			
		||||
  const FilePath cwd = FilePath::GetCurrentDir();
 | 
			
		||||
  _chdir(original_dir.c_str());
 | 
			
		||||
  posix::chdir(original_dir.c_str());
 | 
			
		||||
 | 
			
		||||
#if GTEST_OS_WINDOWS
 | 
			
		||||
  // Skips the ":".
 | 
			
		||||
  const char* const cwd_without_drive = strchr(cwd.c_str(), ':');
 | 
			
		||||
  ASSERT_TRUE(cwd_without_drive != NULL);
 | 
			
		||||
  EXPECT_STREQ(GTEST_PATH_SEP_, cwd_without_drive + 1);
 | 
			
		||||
#else
 | 
			
		||||
  chdir(GTEST_PATH_SEP_);
 | 
			
		||||
  EXPECT_STREQ(GTEST_PATH_SEP_, FilePath::GetCurrentDir().c_str());
 | 
			
		||||
  chdir(original_dir.c_str());
 | 
			
		||||
  EXPECT_STREQ(GTEST_PATH_SEP_, cwd.c_str());
 | 
			
		||||
#endif
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -436,22 +435,14 @@ class DirectoryCreationTest : public Test {
 | 
			
		||||
    remove(testdata_file_.c_str());
 | 
			
		||||
    remove(unique_file0_.c_str());
 | 
			
		||||
    remove(unique_file1_.c_str());
 | 
			
		||||
#if GTEST_OS_WINDOWS
 | 
			
		||||
    _rmdir(testdata_path_.c_str());
 | 
			
		||||
#else
 | 
			
		||||
    rmdir(testdata_path_.c_str());
 | 
			
		||||
#endif  // GTEST_OS_WINDOWS
 | 
			
		||||
    posix::rmdir(testdata_path_.c_str());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  virtual void TearDown() {
 | 
			
		||||
    remove(testdata_file_.c_str());
 | 
			
		||||
    remove(unique_file0_.c_str());
 | 
			
		||||
    remove(unique_file1_.c_str());
 | 
			
		||||
#if GTEST_OS_WINDOWS
 | 
			
		||||
    _rmdir(testdata_path_.c_str());
 | 
			
		||||
#else
 | 
			
		||||
    rmdir(testdata_path_.c_str());
 | 
			
		||||
#endif  // GTEST_OS_WINDOWS
 | 
			
		||||
    posix::rmdir(testdata_path_.c_str());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  String TempDir() const {
 | 
			
		||||
@@ -459,13 +450,7 @@ class DirectoryCreationTest : public Test {
 | 
			
		||||
    return String("\\temp\\");
 | 
			
		||||
 | 
			
		||||
#elif GTEST_OS_WINDOWS
 | 
			
		||||
    // MSVC 8 deprecates getenv(), so we want to suppress warning 4996
 | 
			
		||||
    // (deprecated function) there.
 | 
			
		||||
#pragma warning(push)          // Saves the current warning state.
 | 
			
		||||
#pragma warning(disable:4996)  // Temporarily disables warning 4996.
 | 
			
		||||
    const char* temp_dir = getenv("TEMP");
 | 
			
		||||
#pragma warning(pop)           // Restores the warning state.
 | 
			
		||||
 | 
			
		||||
    const char* temp_dir = posix::getenv("TEMP");
 | 
			
		||||
    if (temp_dir == NULL || temp_dir[0] == '\0')
 | 
			
		||||
      return String("\\temp\\");
 | 
			
		||||
    else if (String(temp_dir).EndsWith("\\"))
 | 
			
		||||
@@ -478,16 +463,7 @@ class DirectoryCreationTest : public Test {
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void CreateTextFile(const char* filename) {
 | 
			
		||||
#if GTEST_OS_WINDOWS
 | 
			
		||||
    // MSVC 8 deprecates fopen(), so we want to suppress warning 4996
 | 
			
		||||
    // (deprecated function) there.#pragma warning(push)
 | 
			
		||||
#pragma warning(push)          // Saves the current warning state.
 | 
			
		||||
#pragma warning(disable:4996)  // Temporarily disables warning 4996.
 | 
			
		||||
    FILE* f = fopen(filename, "w");
 | 
			
		||||
#pragma warning(pop)           // Restores the warning state.
 | 
			
		||||
#else  // We are on Linux or Mac OS.
 | 
			
		||||
    FILE* f = fopen(filename, "w");
 | 
			
		||||
#endif  // GTEST_OS_WINDOWS
 | 
			
		||||
    FILE* f = posix::fopen(filename, "w");
 | 
			
		||||
    fprintf(f, "text\n");
 | 
			
		||||
    fclose(f);
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
@@ -150,22 +150,14 @@ class XmlOutputChangeDirTest : public Test {
 | 
			
		||||
 protected:
 | 
			
		||||
  virtual void SetUp() {
 | 
			
		||||
    original_working_dir_ = FilePath::GetCurrentDir();
 | 
			
		||||
    ChDir("..");
 | 
			
		||||
    posix::chdir("..");
 | 
			
		||||
    // This will make the test fail if run from the root directory.
 | 
			
		||||
    EXPECT_STRNE(original_working_dir_.c_str(),
 | 
			
		||||
                 FilePath::GetCurrentDir().c_str());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  virtual void TearDown() {
 | 
			
		||||
    ChDir(original_working_dir_.c_str());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  void ChDir(const char* dir) {
 | 
			
		||||
#if GTEST_OS_WINDOWS
 | 
			
		||||
    _chdir(dir);
 | 
			
		||||
#else
 | 
			
		||||
    chdir(dir);
 | 
			
		||||
#endif
 | 
			
		||||
    posix::chdir(original_working_dir_.c_str());
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  FilePath original_working_dir_;
 | 
			
		||||
 
 | 
			
		||||
@@ -55,6 +55,7 @@ else:
 | 
			
		||||
PROGRAM_PATH = os.path.join(gtest_test_utils.GetBuildDir(), PROGRAM)
 | 
			
		||||
FLAG_PREFIX = '--gtest_'
 | 
			
		||||
CATCH_EXCEPTIONS_FLAG = FLAG_PREFIX + 'catch_exceptions'
 | 
			
		||||
DEATH_TEST_STYLE_FLAG = FLAG_PREFIX + 'death_test_style'
 | 
			
		||||
 | 
			
		||||
# The help message must match this regex.
 | 
			
		||||
HELP_REGEX = re.compile(
 | 
			
		||||
@@ -99,8 +100,10 @@ class GTestHelpTest(unittest.TestCase):
 | 
			
		||||
    self.assert_(HELP_REGEX.search(output), output)
 | 
			
		||||
    if IS_WINDOWS:
 | 
			
		||||
      self.assert_(CATCH_EXCEPTIONS_FLAG in output, output)
 | 
			
		||||
      self.assert_(DEATH_TEST_STYLE_FLAG not in output, output)
 | 
			
		||||
    else:
 | 
			
		||||
      self.assert_(CATCH_EXCEPTIONS_FLAG not in output, output)
 | 
			
		||||
      self.assert_(DEATH_TEST_STYLE_FLAG in output, output)
 | 
			
		||||
 | 
			
		||||
  def testPrintsHelpWithFullFlag(self):
 | 
			
		||||
    self.TestHelpFlag('--help')
 | 
			
		||||
 
 | 
			
		||||
@@ -60,6 +60,7 @@
 | 
			
		||||
using testing::ScopedFakeTestPartResultReporter;
 | 
			
		||||
using testing::TestPartResultArray;
 | 
			
		||||
 | 
			
		||||
namespace posix = ::testing::internal::posix;
 | 
			
		||||
using testing::internal::String;
 | 
			
		||||
 | 
			
		||||
// Tests catching fatal failures.
 | 
			
		||||
@@ -989,16 +990,9 @@ int main(int argc, char **argv) {
 | 
			
		||||
    // Skip the usual output capturing if we're running as the child
 | 
			
		||||
    // process of an threadsafe-style death test.
 | 
			
		||||
#if GTEST_OS_WINDOWS
 | 
			
		||||
#ifdef _MSC_VER
 | 
			
		||||
#pragma warning(push)
 | 
			
		||||
#pragma warning(disable:4996)
 | 
			
		||||
#endif  // _MSC_VER
 | 
			
		||||
    freopen("nul:", "w", stdout);
 | 
			
		||||
#ifdef _MSC_VER
 | 
			
		||||
#pragma warning(pop)
 | 
			
		||||
#endif  // _MSC_VER
 | 
			
		||||
    posix::freopen("nul:", "w", stdout);
 | 
			
		||||
#else
 | 
			
		||||
    freopen("/dev/null", "w", stdout);
 | 
			
		||||
    posix::freopen("/dev/null", "w", stdout);
 | 
			
		||||
#endif  // GTEST_OS_WINDOWS
 | 
			
		||||
    return RUN_ALL_TESTS();
 | 
			
		||||
  }
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user