From 69c510fb5137160b532e1c7e9bec9e660c14b193 Mon Sep 17 00:00:00 2001 From: Vladimir Goncharov Date: Tue, 7 Jul 2020 19:01:58 +0300 Subject: [PATCH] Add a test for duplicate catch clauses in throw matchers, fix a couple of nitpicks. --- googlemock/include/gmock/gmock-matchers.h | 3 +-- googlemock/test/gmock-matchers_test.cc | 6 ++++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 708c7c87..36625209 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -4738,7 +4738,6 @@ class ExceptionMatcherImpl { ExceptionMatcherImpl(Matcher matcher) : matcher_(std::move(matcher)) {} - public: void DescribeTo(::std::ostream* os) const { *os << "throws an exception of type " << GetTypeName(); if (matcher_.GetDescriber() != nullptr) { @@ -4775,7 +4774,7 @@ class ExceptionMatcherImpl { *listener << "with description \"" << err.what() << "\""; return false; } catch (...) { - *listener << "throws an exception of some other type"; + *listener << "throws an exception of an unknown type"; return false; } *listener << "does not throw any exception"; diff --git a/googlemock/test/gmock-matchers_test.cc b/googlemock/test/gmock-matchers_test.cc index 07411873..cd89d81e 100644 --- a/googlemock/test/gmock-matchers_test.cc +++ b/googlemock/test/gmock-matchers_test.cc @@ -8139,6 +8139,12 @@ TEST(ThrowsTest, Examples) { Property(&std::runtime_error::what, HasSubstr("message")))); } +TEST(ThrowsTest, DoesNotGenerateDuplicateCatchClauseWarning) { + EXPECT_THAT( + []() { throw std::exception(); }, + Throws()); +} + TEST(ThrowsTest, Describe) { Matcher matcher = Throws(); std::stringstream ss;