From 44a041b711ff4a5b5f341f21127aed46dbfe38ad Mon Sep 17 00:00:00 2001 From: "zhanyong.wan" Date: Wed, 11 Mar 2009 18:31:26 +0000 Subject: [PATCH] Fixes death-test-related tests on Windows, by Vlad Losev. --- include/gtest/internal/gtest-internal.h | 1 + include/gtest/internal/gtest-port.h | 2 +- src/gtest-internal-inl.h | 7 ++++--- src/gtest-typed-test.cc | 1 + test/gtest-death-test_test.cc | 9 ++++++--- test/gtest-typed-test_test.cc | 8 ++++---- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h index 5908b760..f61d502f 100644 --- a/include/gtest/internal/gtest-internal.h +++ b/include/gtest/internal/gtest-internal.h @@ -616,6 +616,7 @@ class TypedTestCasePState { fprintf(stderr, "%s Test %s must be defined before " "REGISTER_TYPED_TEST_CASE_P(%s, ...).\n", FormatFileLocation(file, line).c_str(), test_name, case_name); + fflush(stderr); abort(); } defined_test_names_.insert(test_name); diff --git a/include/gtest/internal/gtest-port.h b/include/gtest/internal/gtest-port.h index c93ebd8a..0b4e7211 100644 --- a/include/gtest/internal/gtest-port.h +++ b/include/gtest/internal/gtest-port.h @@ -198,7 +198,7 @@ // simple regex implementation instead. #define GTEST_USES_SIMPLE_RE 1 -#endif // GTEST_OS_LINUX +#endif // GTEST_OS_CYGWIN || GTEST_OS_LINUX || GTEST_OS_MAC // Defines GTEST_HAS_EXCEPTIONS to 1 if exceptions are enabled, or 0 // otherwise. diff --git a/src/gtest-internal-inl.h b/src/gtest-internal-inl.h index de5124d7..d079a3e1 100644 --- a/src/gtest-internal-inl.h +++ b/src/gtest-internal-inl.h @@ -49,16 +49,17 @@ #include #include // For strtoll/_strtoul64. +#include + +#include + #if GTEST_OS_WINDOWS #include // For DWORD. #endif // GTEST_OS_WINDOWS -#include #include #include -#include - namespace testing { // Declares the flags. diff --git a/src/gtest-typed-test.cc b/src/gtest-typed-test.cc index cb91f2b2..e45e2abb 100644 --- a/src/gtest-typed-test.cc +++ b/src/gtest-typed-test.cc @@ -85,6 +85,7 @@ const char* TypedTestCasePState::VerifyRegisteredTestNames( if (errors_str != "") { fprintf(stderr, "%s %s", FormatFileLocation(file, line).c_str(), errors_str.c_str()); + fflush(stderr); abort(); } diff --git a/test/gtest-death-test_test.cc b/test/gtest-death-test_test.cc index 4151ef0e..e794a09e 100644 --- a/test/gtest-death-test_test.cc +++ b/test/gtest-death-test_test.cc @@ -46,6 +46,7 @@ #include #include #include + #include // Indicates that this translation unit is part of Google Test's @@ -284,14 +285,16 @@ void DieWithEmbeddedNul() { _exit(1); } +#if GTEST_USES_PCRE // Tests that EXPECT_DEATH and ASSERT_DEATH work when the error // message has a NUL character in it. -TEST_F(TestForDeathTest, DISABLED_EmbeddedNulInMessage) { +TEST_F(TestForDeathTest, EmbeddedNulInMessage) { // TODO(wan@google.com): doesn't support matching strings // with embedded NUL characters - find a way to workaround it. EXPECT_DEATH(DieWithEmbeddedNul(), "w.*ld"); ASSERT_DEATH(DieWithEmbeddedNul(), "w.*ld"); } +#endif // GTEST_USES_PCRE // Tests that death test macros expand to code which interacts well with switch // statements. @@ -594,7 +597,7 @@ void ExpectDebugDeathHelper(bool* aborted) { } #if GTEST_OS_WINDOWS -TEST(TestForPopUps, DoesNotShowPopUpOnAbort) { +TEST(PopUpDeathTest, DoesNotShowPopUpOnAbort) { printf("This test should be considered failing if it shows " "any pop-up dialogs.\n"); fflush(stdout); @@ -605,7 +608,7 @@ TEST(TestForPopUps, DoesNotShowPopUpOnAbort) { }, ""); } -TEST(TestForPopUps, DoesNotShowPopUpOnThrow) { +TEST(PopUpDeathTest, DoesNotShowPopUpOnThrow) { printf("This test should be considered failing if it shows " "any pop-up dialogs.\n"); fflush(stdout); diff --git a/test/gtest-typed-test_test.cc b/test/gtest-typed-test_test.cc index 9ba9675f..eb921a06 100644 --- a/test/gtest-typed-test_test.cc +++ b/test/gtest-typed-test_test.cc @@ -205,19 +205,19 @@ typedef TypedTestCasePStateTest TypedTestCasePStateDeathTest; TEST_F(TypedTestCasePStateDeathTest, DetectsDuplicates) { EXPECT_DEATH( state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, A, C"), - "foo\\.cc:1: Test A is listed more than once\\."); + "foo\\.cc.1.?: Test A is listed more than once\\."); } TEST_F(TypedTestCasePStateDeathTest, DetectsExtraTest) { EXPECT_DEATH( state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, C, D"), - "foo\\.cc:1: No test named D can be found in this test case\\."); + "foo\\.cc.1.?: No test named D can be found in this test case\\."); } TEST_F(TypedTestCasePStateDeathTest, DetectsMissedTest) { EXPECT_DEATH( state_.VerifyRegisteredTestNames("foo.cc", 1, "A, C"), - "foo\\.cc:1: You forgot to list test B\\."); + "foo\\.cc.1.?: You forgot to list test B\\."); } // Tests that defining a test for a parameterized test case generates @@ -226,7 +226,7 @@ TEST_F(TypedTestCasePStateDeathTest, DetectsTestAfterRegistration) { state_.VerifyRegisteredTestNames("foo.cc", 1, "A, B, C"); EXPECT_DEATH( state_.AddTestName("foo.cc", 2, "FooTest", "D"), - "foo\\.cc:2: Test D must be defined before REGISTER_TYPED_TEST_CASE_P" + "foo\\.cc.2.?: Test D must be defined before REGISTER_TYPED_TEST_CASE_P" "\\(FooTest, \\.\\.\\.\\)\\."); }