diff options
-rw-r--r-- | CMakeLists.txt | 23 | ||||
-rw-r--r-- | include/gtest/internal/gtest-port.h | 12 | ||||
-rw-r--r-- | src/gtest-port.cc | 5 | ||||
-rw-r--r-- | src/gtest.cc | 8 | ||||
-rw-r--r-- | test/gtest_unittest.cc | 25 |
5 files changed, 55 insertions, 18 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 95b6e16..5d3a402 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,8 +191,6 @@ if (build_all_gtest_tests) src/gtest-all.cc) cxx_library(gtest_main_no_rtti "${cxx_no_rtti}" src/gtest-all.cc src/gtest_main.cc) - cxx_library(gtest_main_use_own_tuple "${cxx_use_own_tuple}" - src/gtest-all.cc src/gtest_main.cc) find_package(Threads) # Defines CMAKE_THREAD_LIBS_INIT. cxx_test_with_flags(gtest-death-test_test "${cxx_default}" @@ -201,12 +199,23 @@ if (build_all_gtest_tests) cxx_test_with_flags(gtest_no_rtti_unittest "${cxx_no_rtti}" gtest_main_no_rtti test/gtest_unittest.cc) - cxx_test_with_flags(gtest-tuple_test "${cxx_use_own_tuple}" - gtest_main_use_own_tuple test/gtest-tuple_test.cc) + if (NOT(MSVC AND (MSVC_VERSION EQUAL 1600))) + # The C++ Standard specifies tuple_element<int, class>. + # Yet MSVC 10's <utility> declares tuple_element<size_t, class>. + # That declaration conflicts with our own standard-conforming + # tuple implementation. Therefore using our own tuple with + # MSVC 10 doesn't compile. + cxx_library(gtest_main_use_own_tuple "${cxx_use_own_tuple}" + src/gtest-all.cc src/gtest_main.cc) + + cxx_test_with_flags(gtest-tuple_test "${cxx_use_own_tuple}" + gtest_main_use_own_tuple test/gtest-tuple_test.cc) + + cxx_test_with_flags(gtest_use_own_tuple_test "${cxx_use_own_tuple}" + gtest_main_use_own_tuple + test/gtest-param-test_test.cc test/gtest-param-test2_test.cc) + endif() - cxx_test_with_flags(gtest_use_own_tuple_test "${cxx_use_own_tuple}" - gtest_main_use_own_tuple - test/gtest-param-test_test.cc test/gtest-param-test2_test.cc) endif() ############################################################ diff --git a/include/gtest/internal/gtest-port.h b/include/gtest/internal/gtest-port.h index 467f697..d94c379 100644 --- a/include/gtest/internal/gtest-port.h +++ b/include/gtest/internal/gtest-port.h @@ -77,7 +77,7 @@ // GTEST_OS_WINDOWS - Windows (Desktop, MinGW, or Mobile) // GTEST_OS_WINDOWS_DESKTOP - Windows Desktop // GTEST_OS_WINDOWS_MINGW - MinGW -// GTEST_OS_WINODWS_MOBILE - Windows Mobile +// GTEST_OS_WINDOWS_MOBILE - Windows Mobile // GTEST_OS_ZOS - z/OS // // Among the platforms, Cygwin, Linux, Max OS X, and Windows have the @@ -436,6 +436,12 @@ #endif // GTEST_HAS_CLONE +// Determines whether to support stream redirection. This is used to test +// output correctness and to implement death tests. +#if !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN +#define GTEST_HAS_STREAM_REDIRECTION_ 1 +#endif // !GTEST_OS_WINDOWS_MOBILE && !GTEST_OS_SYMBIAN + // Determines whether to support death tests. // Google Test does not support death tests for VC 7.1 and earlier as // abort() in a VC 7.1 application compiled as GUI in debug config @@ -696,7 +702,7 @@ class GTestLog { inline void LogToStderr() {} inline void FlushInfoLog() { fflush(NULL); } -#if !GTEST_OS_WINDOWS_MOBILE +#if GTEST_HAS_STREAM_REDIRECTION_ // Defines the stderr capturer: // CaptureStdout - starts capturing stdout. @@ -709,7 +715,7 @@ String GetCapturedStdout(); void CaptureStderr(); String GetCapturedStderr(); -#endif // !GTEST_OS_WINDOWS_MOBILE +#endif // GTEST_HAS_STREAM_REDIRECTION_ #if GTEST_HAS_DEATH_TEST diff --git a/src/gtest-port.cc b/src/gtest-port.cc index 1890a80..957595a 100644 --- a/src/gtest-port.cc +++ b/src/gtest-port.cc @@ -441,8 +441,7 @@ GTestLog::~GTestLog() { #pragma warning(disable: 4996) #endif // _MSC_VER -// Stream capturing is not supported on Windows Mobile. -#if !GTEST_OS_WINDOWS_MOBILE +#if GTEST_HAS_STREAM_REDIRECTION_ // Object that captures an output stream (stdout/stderr). class CapturedStream { @@ -575,7 +574,7 @@ String GetCapturedStdout() { return GetCapturedStream(&g_captured_stdout); } // Stops capturing stderr and returns the captured string. String GetCapturedStderr() { return GetCapturedStream(&g_captured_stderr); } -#endif // !GTEST_OS_WINDOWS_MOBILE +#endif // GTEST_HAS_STREAM_REDIRECTION_ #if GTEST_HAS_DEATH_TEST diff --git a/src/gtest.cc b/src/gtest.cc index f5de645..fb5bae9 100644 --- a/src/gtest.cc +++ b/src/gtest.cc @@ -2631,13 +2631,15 @@ void ColoredPrintf(GTestColor color, const char* fmt, ...) { GetConsoleScreenBufferInfo(stdout_handle, &buffer_info); const WORD old_color_attrs = buffer_info.wAttributes; + // We need to flush the stream buffers into the console before each + // SetConsoleTextAttribute call lest it affect the text that is already + // printed but has not yet reached the console. + fflush(stdout); SetConsoleTextAttribute(stdout_handle, GetColorAttribute(color) | FOREGROUND_INTENSITY); vprintf(fmt, args); - // Unless we flush stream buffers now the next SetConsoleTextAttribute - // call can reset the color before the output reaches the console. - fflush(stdout); + fflush(stdout); // Restores the text color. SetConsoleTextAttribute(stdout_handle, old_color_attrs); #else diff --git a/test/gtest_unittest.cc b/test/gtest_unittest.cc index 16de794..a593494 100644 --- a/test/gtest_unittest.cc +++ b/test/gtest_unittest.cc @@ -184,6 +184,11 @@ using testing::internal::kMaxRandomSeed; using testing::internal::kTestTypeIdInGoogleTest; using testing::internal::scoped_ptr; +#if GTEST_HAS_STREAM_REDIRECTION_ +using testing::internal::CaptureStdout; +using testing::internal::GetCapturedStdout; +#endif // GTEST_HAS_STREAM_REDIRECTION_ + class TestingVector : public Vector<int> { }; @@ -5471,9 +5476,17 @@ class InitGoogleTestTest : public Test { const bool saved_help_flag = ::testing::internal::g_help_flag; ::testing::internal::g_help_flag = false; +#if GTEST_HAS_STREAM_REDIRECTION_ + CaptureStdout(); +#endif // GTEST_HAS_STREAM_REDIRECTION_ + // Parses the command line. internal::ParseGoogleTestFlagsOnly(&argc1, const_cast<CharType**>(argv1)); +#if GTEST_HAS_STREAM_REDIRECTION_ + const String captured_stdout = GetCapturedStdout(); +#endif // GTEST_HAS_STREAM_REDIRECTION_ + // Verifies the flag values. CheckFlags(expected); @@ -5485,8 +5498,16 @@ class InitGoogleTestTest : public Test { // help message for the flags it recognizes. EXPECT_EQ(should_print_help, ::testing::internal::g_help_flag); - // TODO(vladl@google.com): Verify that the help output is not printed - // for recognized flags when stdout capturing is implemeted. +#if GTEST_HAS_STREAM_REDIRECTION_ + const char* const expected_help_fragment = + "This program contains tests written using"; + if (should_print_help) { + EXPECT_PRED_FORMAT2(IsSubstring, expected_help_fragment, captured_stdout); + } else { + EXPECT_PRED_FORMAT2(IsNotSubstring, + expected_help_fragment, captured_stdout); + } +#endif // GTEST_HAS_STREAM_REDIRECTION_ ::testing::internal::g_help_flag = saved_help_flag; } |