From 0354ccb049ea2b9e4696adb8b5a013287daf0c33 Mon Sep 17 00:00:00 2001 From: Jonny007-MKD Date: Thu, 13 Sep 2018 10:24:10 +0200 Subject: [PATCH 01/12] Added special catch for std::exception in GTEST_TEST_NO_THROW_ --- .../include/gtest/internal/gtest-internal.h | 23 ++++++++++++++++--- googletest/test/gtest_unittest.cc | 9 ++++++++ 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index b762f61f..b968fb1d 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -1189,6 +1189,19 @@ class NativeArray { GTEST_DISALLOW_ASSIGN_(NativeArray); }; +class AdditionalMessage +{ +public: + AdditionalMessage(const std::string& message) : value(message) {} + AdditionalMessage& operator=(const std::string& message) { value = message; return *this; } + operator bool() const { return ::testing::internal::AlwaysTrue(); } + + const std::string& get() const { return value; } + +private: + std::string value; +}; + } // namespace internal } // namespace testing @@ -1242,17 +1255,21 @@ class NativeArray { #define GTEST_TEST_NO_THROW_(statement, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (::testing::internal::AlwaysTrue()) { \ + if (::testing::internal::AdditionalMessage message = ".") { \ try { \ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ } \ + catch (const std::exception& e) { \ + message = std::string(": ") + e.what(); \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \ + } \ catch (...) { \ goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \ } \ } else \ GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \ - fail("Expected: " #statement " doesn't throw an exception.\n" \ - " Actual: it throws.") + fail(("Expected: " #statement " doesn't throw an exception.\n" \ + " Actual: it throws" + message.get()).c_str()) #define GTEST_TEST_ANY_THROW_(statement, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index fa102240..de194491 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -3330,6 +3330,9 @@ TEST_F(SingleEvaluationTest, OtherCases) { void ThrowAnInteger() { throw 1; } +void ThrowAnException(const char* what) { + throw std::runtime_error(what); +} // Tests that assertion arguments are evaluated exactly once. TEST_F(SingleEvaluationTest, ExceptionTests) { @@ -3812,6 +3815,9 @@ TEST(AssertionTest, ASSERT_NO_THROW) { EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnInteger()), "Expected: ThrowAnInteger() doesn't throw an exception." "\n Actual: it throws."); + EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnException("blablubb")), + "Expected: ThrowAnException(\"blablubb\") doesn't throw an exception." + "\n Actual: it throws: blablubb"); } // Tests ASSERT_ANY_THROW. @@ -4553,6 +4559,9 @@ TEST(ExpectTest, EXPECT_NO_THROW) { EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnInteger()), "Expected: ThrowAnInteger() doesn't throw an " "exception.\n Actual: it throws."); + EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnException("blablubb")), + "Expected: ThrowAnException(\"blablubb\") doesn't throw an " + "exception.\n Actual: it throws: blablubb"); } // Tests EXPECT_ANY_THROW. From 8c849c584c65a187ae472af466cb7cdaa98685d6 Mon Sep 17 00:00:00 2001 From: Jonny007-MKD Date: Thu, 13 Sep 2018 13:57:27 +0200 Subject: [PATCH 02/12] Try to fix gcc and clang issues --- googletest/include/gtest/internal/gtest-internal.h | 2 +- googletest/test/gtest_unittest.cc | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index b968fb1d..da3ebd2b 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -1192,7 +1192,7 @@ class NativeArray { class AdditionalMessage { public: - AdditionalMessage(const std::string& message) : value(message) {} + AdditionalMessage(const char* message) : value(message) {} AdditionalMessage& operator=(const std::string& message) { value = message; return *this; } operator bool() const { return ::testing::internal::AlwaysTrue(); } diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index de194491..2c970830 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -3748,6 +3748,19 @@ TEST(ExpectTest, ASSERT_EQ_0) { " 0\n 5.6"); } +TEST(AssertionTest, AdditionalMessage) { + ::testing::internal::AdditionalMessage m = "servus"; + EXPECT_EQ(m.get(), "servus"); + + const char* cc = "hello"; + m = cc; + EXPECT_EQ(m.get(), cc); + + std::string s = "hi"; + m = s; + EXPECT_EQ(m.get(), s); +} + // Tests ASSERT_NE. TEST(AssertionTest, ASSERT_NE) { ASSERT_NE(6, 7); From e86d1df3e177bb5782a97fd52a513b7b6983cea6 Mon Sep 17 00:00:00 2001 From: Jonny007-MKD Date: Thu, 13 Sep 2018 14:13:23 +0200 Subject: [PATCH 03/12] Avoid implicit move operator --- googletest/include/gtest/internal/gtest-internal.h | 1 + 1 file changed, 1 insertion(+) diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index da3ebd2b..7901cd3b 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -1199,6 +1199,7 @@ public: const std::string& get() const { return value; } private: + AdditionalMessage& operator=(AdditionalMessage&&); std::string value; }; From 82eeb009b25a4b607984cfd076e46094473ef090 Mon Sep 17 00:00:00 2001 From: Jonny007-MKD Date: Thu, 13 Sep 2018 14:49:15 +0200 Subject: [PATCH 04/12] Make it public again *sigh* --- googletest/include/gtest/internal/gtest-internal.h | 1 - googletest/test/gtest_unittest.cc | 13 ------------- 2 files changed, 14 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index 7901cd3b..da3ebd2b 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -1199,7 +1199,6 @@ public: const std::string& get() const { return value; } private: - AdditionalMessage& operator=(AdditionalMessage&&); std::string value; }; diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 2c970830..de194491 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -3748,19 +3748,6 @@ TEST(ExpectTest, ASSERT_EQ_0) { " 0\n 5.6"); } -TEST(AssertionTest, AdditionalMessage) { - ::testing::internal::AdditionalMessage m = "servus"; - EXPECT_EQ(m.get(), "servus"); - - const char* cc = "hello"; - m = cc; - EXPECT_EQ(m.get(), cc); - - std::string s = "hi"; - m = s; - EXPECT_EQ(m.get(), s); -} - // Tests ASSERT_NE. TEST(AssertionTest, ASSERT_NE) { ASSERT_NE(6, 7); From 6494f5232b130a29321e661166442bac324c4383 Mon Sep 17 00:00:00 2001 From: Jonny007-MKD Date: Fri, 14 Sep 2018 23:22:04 +0200 Subject: [PATCH 05/12] Print message of unexpected std::exception in EXPECT_THROW, too --- .../include/gtest/internal/gtest-internal.h | 38 ++++++++++++------- googletest/test/gtest_unittest.cc | 34 ++++++++++++++--- 2 files changed, 53 insertions(+), 19 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index da3ebd2b..5a1181aa 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -1194,7 +1194,7 @@ class AdditionalMessage public: AdditionalMessage(const char* message) : value(message) {} AdditionalMessage& operator=(const std::string& message) { value = message; return *this; } - operator bool() const { return ::testing::internal::AlwaysTrue(); } + operator bool() const { return true; } const std::string& get() const { return value; } @@ -1229,29 +1229,41 @@ private: #define GTEST_TEST_THROW_(statement, expected_exception, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (::testing::internal::ConstCharPtr gtest_msg = "") { \ + if (::testing::internal::AdditionalMessage message = "") { \ bool gtest_caught_expected = false; \ try { \ - GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + try { \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ + } \ + catch (expected_exception const&) { \ + gtest_caught_expected = true; \ + throw; \ + } \ } \ - catch (expected_exception const&) { \ - gtest_caught_expected = true; \ + catch (const std::exception& e) { \ + if (!gtest_caught_expected) { \ + message = \ + "it throws a different type " \ + "with message: " + std::string(e.what()); \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ + } \ } \ catch (...) { \ - gtest_msg.value = \ - "Expected: " #statement " throws an exception of type " \ - #expected_exception ".\n Actual: it throws a different type."; \ - goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ + if (!gtest_caught_expected) { \ + message = \ + "it throws a different type."; \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ + } \ } \ if (!gtest_caught_expected) { \ - gtest_msg.value = \ - "Expected: " #statement " throws an exception of type " \ - #expected_exception ".\n Actual: it throws nothing."; \ + message = \ + "it throws nothing."; \ goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ } \ } else \ GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \ - fail(gtest_msg.value) + fail(("Expected: " #statement " throws an exception of type " \ + #expected_exception ".\n Actual: " + message.get()).c_str()) #define GTEST_TEST_NO_THROW_(statement, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index bd1117b3..6b75ab47 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -3373,6 +3373,20 @@ TEST_F(SingleEvaluationTest, ExceptionTests) { // failed EXPECT_ANY_THROW EXPECT_NONFATAL_FAILURE(EXPECT_ANY_THROW(a_++), "it doesn't"); EXPECT_EQ(7, a_); + + // failed EXPECT_THROW std::exception, throws different + EXPECT_NONFATAL_FAILURE(EXPECT_THROW({ // NOLINT + a_++; + ThrowAnInteger(); + }, std::exception), "throws a different type"); + EXPECT_EQ(8, a_); + + // failed EXPECT_THROW, throws std::exception + EXPECT_NONFATAL_FAILURE(EXPECT_THROW({ // NOLINT + a_++; + ThrowAnException("blablubb"); + }, bool), "throws a different type with message: blablubb"); + EXPECT_EQ(9, a_); } #endif // GTEST_HAS_EXCEPTIONS @@ -3805,6 +3819,11 @@ TEST(AssertionTest, ASSERT_THROW) { ASSERT_THROW(ThrowNothing(), bool), "Expected: ThrowNothing() throws an exception of type bool.\n" " Actual: it throws nothing."); + + EXPECT_FATAL_FAILURE( + ASSERT_THROW(ThrowAnException("buuh"), bool), + "Expected: ThrowAnException(\"buuh\") throws an exception of type bool.\n" + " Actual: it throws a different type with message: buuh"); } // Tests ASSERT_NO_THROW. @@ -4542,13 +4561,16 @@ TEST(ExpectTest, EXPECT_GT) { // Tests EXPECT_THROW. TEST(ExpectTest, EXPECT_THROW) { EXPECT_THROW(ThrowAnInteger(), int); + EXPECT_THROW(ThrowAnException(""), std::exception); EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnInteger(), bool), - "Expected: ThrowAnInteger() throws an exception of " - "type bool.\n Actual: it throws a different type."); - EXPECT_NONFATAL_FAILURE( - EXPECT_THROW(ThrowNothing(), bool), - "Expected: ThrowNothing() throws an exception of type bool.\n" - " Actual: it throws nothing."); + "Expected: ThrowAnInteger() throws an exception of type bool.\n" + " Actual: it throws a different type."); + EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowNothing(), bool), + "Expected: ThrowNothing() throws an exception of type bool.\n" + " Actual: it throws nothing."); + EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnException("buuh"), bool), + "Expected: ThrowAnException(\"buuh\") throws an exception of type bool.\n" + " Actual: it throws a different type with message: buuh"); } // Tests EXPECT_NO_THROW. From c40f55a229f6d3d33f00c942585ea642135881db Mon Sep 17 00:00:00 2001 From: Jonny007-MKD Date: Sat, 15 Sep 2018 09:00:39 +0200 Subject: [PATCH 06/12] Avoid these ambiguities --- .../include/gtest/internal/gtest-internal.h | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index 5a1181aa..50bc52d5 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -1193,7 +1193,7 @@ class AdditionalMessage { public: AdditionalMessage(const char* message) : value(message) {} - AdditionalMessage& operator=(const std::string& message) { value = message; return *this; } + void set(const std::string& message) { value = message; } operator bool() const { return true; } const std::string& get() const { return value; } @@ -1242,22 +1242,22 @@ private: } \ catch (const std::exception& e) { \ if (!gtest_caught_expected) { \ - message = \ + message.set( \ "it throws a different type " \ - "with message: " + std::string(e.what()); \ + "with message: " + std::string(e.what())); \ goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ } \ } \ catch (...) { \ if (!gtest_caught_expected) { \ - message = \ - "it throws a different type."; \ + message.set( \ + "it throws a different type."); \ goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ } \ } \ if (!gtest_caught_expected) { \ - message = \ - "it throws nothing."; \ + message.set( \ + "it throws nothing."); \ goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ } \ } else \ @@ -1272,7 +1272,7 @@ private: GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ } \ catch (const std::exception& e) { \ - message = std::string(": ") + e.what(); \ + message.set(std::string(": ") + e.what()); \ goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \ } \ catch (...) { \ From 0a18c106ac0a794b9d912d46b5de20634b14703b Mon Sep 17 00:00:00 2001 From: Matthieu Longo Date: Tue, 18 Sep 2018 12:34:56 +0200 Subject: [PATCH 07/12] [msys] pass big object file option to assembler for target gmock-matchers_test --- googlemock/CMakeLists.txt | 3 +++ 1 file changed, 3 insertions(+) diff --git a/googlemock/CMakeLists.txt b/googlemock/CMakeLists.txt index 8a8de1f6..2a913080 100644 --- a/googlemock/CMakeLists.txt +++ b/googlemock/CMakeLists.txt @@ -157,6 +157,9 @@ if (gmock_build_tests) cxx_test(gmock-generated-matchers_test gmock_main) cxx_test(gmock-internal-utils_test gmock_main) cxx_test(gmock-matchers_test gmock_main) + if (MINGW) + target_compile_options(gmock-matchers_test PRIVATE "-Wa,-mbig-obj") + endif() cxx_test(gmock-more-actions_test gmock_main) cxx_test(gmock-nice-strict_test gmock_main) cxx_test(gmock-port_test gmock_main) From c9fe337ae255baac2c72b4a1099bbad4e181a3a8 Mon Sep 17 00:00:00 2001 From: Matthieu Longo Date: Mon, 17 Sep 2018 18:17:10 +0200 Subject: [PATCH 08/12] [msys] fix unittest ColoredOutputTest.UsesColorsWhenTermSupportsColors --- googletest/include/gtest/internal/gtest-port-arch.h | 5 +++-- googletest/test/gtest_unittest.cc | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-port-arch.h b/googletest/include/gtest/internal/gtest-port-arch.h index f83700e0..587ed5e5 100644 --- a/googletest/include/gtest/internal/gtest-port-arch.h +++ b/googletest/include/gtest/internal/gtest-port-arch.h @@ -38,14 +38,15 @@ // Determines the platform on which Google Test is compiled. #ifdef __CYGWIN__ # define GTEST_OS_CYGWIN 1 +# elif defined(__MINGW__) || defined(__MINGW32__) || defined(__MINGW64__) +# define GTEST_OS_WINDOWS_MINGW 1 +# define GTEST_OS_WINDOWS 1 #elif defined __SYMBIAN32__ # define GTEST_OS_SYMBIAN 1 #elif defined _WIN32 # define GTEST_OS_WINDOWS 1 # ifdef _WIN32_WCE # define GTEST_OS_WINDOWS_MOBILE 1 -# elif defined(__MINGW__) || defined(__MINGW32__) -# define GTEST_OS_WINDOWS_MINGW 1 # elif defined(WINAPI_FAMILY) # include # if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 701ba204..c03b3671 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -6826,7 +6826,7 @@ TEST(ColoredOutputTest, UsesColorsWhenStdoutIsTty) { TEST(ColoredOutputTest, UsesColorsWhenTermSupportsColors) { GTEST_FLAG(color) = "auto"; -#if GTEST_OS_WINDOWS +#if GTEST_OS_WINDOWS && !GTEST_OS_WINDOWS_MINGW // On Windows, we ignore the TERM variable as it's usually not set. SetEnv("TERM", "dumb"); From 6a1c3d9b788bedad993aa57690cc1c8cb4b871ba Mon Sep 17 00:00:00 2001 From: Jonny007-MKD Date: Tue, 18 Sep 2018 21:54:36 +0200 Subject: [PATCH 09/12] Removed some newlines --- googletest/include/gtest/internal/gtest-internal.h | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index 50bc52d5..0dbf100c 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -1242,22 +1242,19 @@ private: } \ catch (const std::exception& e) { \ if (!gtest_caught_expected) { \ - message.set( \ - "it throws a different type " \ + message.set("it throws a different type " \ "with message: " + std::string(e.what())); \ goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ } \ } \ catch (...) { \ if (!gtest_caught_expected) { \ - message.set( \ - "it throws a different type."); \ + message.set("it throws a different type."); \ goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ } \ } \ if (!gtest_caught_expected) { \ - message.set( \ - "it throws nothing."); \ + message.set("it throws nothing."); \ goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ } \ } else \ From 1b20bd176fb3bc6feef4ab17488a2ac8850f42dd Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 17 Sep 2018 10:42:55 -0400 Subject: [PATCH 10/12] Googletest export support printing std::reference_wrapper in gUnit PiperOrigin-RevId: 213270392 --- googletest/include/gtest/gtest-printers.h | 8 +++ .../include/gtest/internal/gtest-internal.h | 56 +++++-------------- googletest/test/googletest-printers-test.cc | 16 ++++++ googletest/test/gtest_unittest.cc | 43 ++------------ 4 files changed, 45 insertions(+), 78 deletions(-) diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index 51865f84..59d2d918 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -639,7 +639,15 @@ inline void PrintTo(absl::string_view sp, ::std::ostream* os) { #endif // GTEST_HAS_ABSL #if GTEST_LANG_CXX11 + inline void PrintTo(std::nullptr_t, ::std::ostream* os) { *os << "(nullptr)"; } + +template +void PrintTo(std::reference_wrapper ref, ::std::ostream* os) { + // Delegate to wrapped value. + PrintTo(ref.get(), os); +} + #endif // GTEST_LANG_CXX11 #if GTEST_HAS_TR1_TUPLE || GTEST_HAS_STD_TUPLE_ diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index 0dbf100c..b762f61f 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -1189,19 +1189,6 @@ class NativeArray { GTEST_DISALLOW_ASSIGN_(NativeArray); }; -class AdditionalMessage -{ -public: - AdditionalMessage(const char* message) : value(message) {} - void set(const std::string& message) { value = message; } - operator bool() const { return true; } - - const std::string& get() const { return value; } - -private: - std::string value; -}; - } // namespace internal } // namespace testing @@ -1229,56 +1216,43 @@ private: #define GTEST_TEST_THROW_(statement, expected_exception, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (::testing::internal::AdditionalMessage message = "") { \ + if (::testing::internal::ConstCharPtr gtest_msg = "") { \ bool gtest_caught_expected = false; \ try { \ - try { \ - GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ - } \ - catch (expected_exception const&) { \ - gtest_caught_expected = true; \ - throw; \ - } \ + GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ } \ - catch (const std::exception& e) { \ - if (!gtest_caught_expected) { \ - message.set("it throws a different type " \ - "with message: " + std::string(e.what())); \ - goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ - } \ + catch (expected_exception const&) { \ + gtest_caught_expected = true; \ } \ catch (...) { \ - if (!gtest_caught_expected) { \ - message.set("it throws a different type."); \ - goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ - } \ + gtest_msg.value = \ + "Expected: " #statement " throws an exception of type " \ + #expected_exception ".\n Actual: it throws a different type."; \ + goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ } \ if (!gtest_caught_expected) { \ - message.set("it throws nothing."); \ + gtest_msg.value = \ + "Expected: " #statement " throws an exception of type " \ + #expected_exception ".\n Actual: it throws nothing."; \ goto GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__); \ } \ } else \ GTEST_CONCAT_TOKEN_(gtest_label_testthrow_, __LINE__): \ - fail(("Expected: " #statement " throws an exception of type " \ - #expected_exception ".\n Actual: " + message.get()).c_str()) + fail(gtest_msg.value) #define GTEST_TEST_NO_THROW_(statement, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (::testing::internal::AdditionalMessage message = ".") { \ + if (::testing::internal::AlwaysTrue()) { \ try { \ GTEST_SUPPRESS_UNREACHABLE_CODE_WARNING_BELOW_(statement); \ } \ - catch (const std::exception& e) { \ - message.set(std::string(": ") + e.what()); \ - goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \ - } \ catch (...) { \ goto GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__); \ } \ } else \ GTEST_CONCAT_TOKEN_(gtest_label_testnothrow_, __LINE__): \ - fail(("Expected: " #statement " doesn't throw an exception.\n" \ - " Actual: it throws" + message.get()).c_str()) + fail("Expected: " #statement " doesn't throw an exception.\n" \ + " Actual: it throws.") #define GTEST_TEST_ANY_THROW_(statement, fail) \ GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc index ea8369d2..6e26274e 100644 --- a/googletest/test/googletest-printers-test.cc +++ b/googletest/test/googletest-printers-test.cc @@ -1112,9 +1112,25 @@ TEST(PrintStdTupleTest, NestedTuple) { #endif // GTEST_LANG_CXX11 #if GTEST_LANG_CXX11 + TEST(PrintNullptrT, Basic) { EXPECT_EQ("(nullptr)", Print(nullptr)); } + +TEST(PrintReferenceWrapper, Printable) { + int x = 5; + EXPECT_EQ("5", Print(std::ref(x))); + EXPECT_EQ("5", Print(std::cref(x))); +} + +TEST(PrintReferenceWrapper, Unprintable) { + ::foo::UnprintableInFoo up; + EXPECT_EQ("16-byte object ", + Print(std::ref(up))); + EXPECT_EQ("16-byte object ", + Print(std::cref(up))); +} + #endif // GTEST_LANG_CXX11 // Tests printing user-defined unprintable types. diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 6b75ab47..701ba204 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -3328,9 +3328,6 @@ TEST_F(SingleEvaluationTest, OtherCases) { void ThrowAnInteger() { throw 1; } -void ThrowAnException(const char* what) { - throw std::runtime_error(what); -} // Tests that assertion arguments are evaluated exactly once. TEST_F(SingleEvaluationTest, ExceptionTests) { @@ -3373,20 +3370,6 @@ TEST_F(SingleEvaluationTest, ExceptionTests) { // failed EXPECT_ANY_THROW EXPECT_NONFATAL_FAILURE(EXPECT_ANY_THROW(a_++), "it doesn't"); EXPECT_EQ(7, a_); - - // failed EXPECT_THROW std::exception, throws different - EXPECT_NONFATAL_FAILURE(EXPECT_THROW({ // NOLINT - a_++; - ThrowAnInteger(); - }, std::exception), "throws a different type"); - EXPECT_EQ(8, a_); - - // failed EXPECT_THROW, throws std::exception - EXPECT_NONFATAL_FAILURE(EXPECT_THROW({ // NOLINT - a_++; - ThrowAnException("blablubb"); - }, bool), "throws a different type with message: blablubb"); - EXPECT_EQ(9, a_); } #endif // GTEST_HAS_EXCEPTIONS @@ -3819,11 +3802,6 @@ TEST(AssertionTest, ASSERT_THROW) { ASSERT_THROW(ThrowNothing(), bool), "Expected: ThrowNothing() throws an exception of type bool.\n" " Actual: it throws nothing."); - - EXPECT_FATAL_FAILURE( - ASSERT_THROW(ThrowAnException("buuh"), bool), - "Expected: ThrowAnException(\"buuh\") throws an exception of type bool.\n" - " Actual: it throws a different type with message: buuh"); } // Tests ASSERT_NO_THROW. @@ -3832,9 +3810,6 @@ TEST(AssertionTest, ASSERT_NO_THROW) { EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnInteger()), "Expected: ThrowAnInteger() doesn't throw an exception." "\n Actual: it throws."); - EXPECT_FATAL_FAILURE(ASSERT_NO_THROW(ThrowAnException("blablubb")), - "Expected: ThrowAnException(\"blablubb\") doesn't throw an exception." - "\n Actual: it throws: blablubb"); } // Tests ASSERT_ANY_THROW. @@ -4561,16 +4536,13 @@ TEST(ExpectTest, EXPECT_GT) { // Tests EXPECT_THROW. TEST(ExpectTest, EXPECT_THROW) { EXPECT_THROW(ThrowAnInteger(), int); - EXPECT_THROW(ThrowAnException(""), std::exception); EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnInteger(), bool), - "Expected: ThrowAnInteger() throws an exception of type bool.\n" - " Actual: it throws a different type."); - EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowNothing(), bool), - "Expected: ThrowNothing() throws an exception of type bool.\n" - " Actual: it throws nothing."); - EXPECT_NONFATAL_FAILURE(EXPECT_THROW(ThrowAnException("buuh"), bool), - "Expected: ThrowAnException(\"buuh\") throws an exception of type bool.\n" - " Actual: it throws a different type with message: buuh"); + "Expected: ThrowAnInteger() throws an exception of " + "type bool.\n Actual: it throws a different type."); + EXPECT_NONFATAL_FAILURE( + EXPECT_THROW(ThrowNothing(), bool), + "Expected: ThrowNothing() throws an exception of type bool.\n" + " Actual: it throws nothing."); } // Tests EXPECT_NO_THROW. @@ -4579,9 +4551,6 @@ TEST(ExpectTest, EXPECT_NO_THROW) { EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnInteger()), "Expected: ThrowAnInteger() doesn't throw an " "exception.\n Actual: it throws."); - EXPECT_NONFATAL_FAILURE(EXPECT_NO_THROW(ThrowAnException("blablubb")), - "Expected: ThrowAnException(\"blablubb\") doesn't throw an " - "exception.\n Actual: it throws: blablubb"); } // Tests EXPECT_ANY_THROW. From 8c547cff2ece87eb478efc81b686dedcb1640a9e Mon Sep 17 00:00:00 2001 From: misterg Date: Thu, 20 Sep 2018 10:54:59 -0400 Subject: [PATCH 11/12] Googletest export Fixing broken OSS build, add missing include PiperOrigin-RevId: 213812210 --- googletest/include/gtest/gtest-printers.h | 1 + 1 file changed, 1 insertion(+) diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h index 59d2d918..39c5c463 100644 --- a/googletest/include/gtest/gtest-printers.h +++ b/googletest/include/gtest/gtest-printers.h @@ -100,6 +100,7 @@ #ifndef GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ #define GTEST_INCLUDE_GTEST_GTEST_PRINTERS_H_ +#include #include // NOLINT #include #include From a35326be0436bda8af2fc5542303ad0ee3627da1 Mon Sep 17 00:00:00 2001 From: Gennadiy Civil Date: Thu, 20 Sep 2018 14:12:48 -0400 Subject: [PATCH 12/12] Revert "Added special catch for std::exception in GTEST_TEST_NO_THROW_"