From 81e1cc73c83265e54b2ec7edc17e77f4d1b89e86 Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Thu, 28 Jan 2010 21:50:29 +0000 Subject: Introduces macro GTEST_HAS_STREAM_REDIRECTION_ (by Vlad Losev); fixes unsynchronized color text output on Windows (by Vlad Losev); fixes the cmake script to work with MSVC 10 (by Manuel Klimek). --- test/gtest_unittest.cc | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'test/gtest_unittest.cc') diff --git a/test/gtest_unittest.cc b/test/gtest_unittest.cc index 16de794d..a5934946 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 { }; @@ -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(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; } -- cgit v1.2.3