Proposing these changes, please review

Slightly better names and cleaner tests.
Please review
This commit is contained in:
Gennadiy Civil 2017-08-20 15:15:31 -04:00 committed by GitHub
parent 35737ac7ac
commit 026735daf3

View File

@ -62,10 +62,10 @@ using testing::internal::CaptureStdout;
using testing::internal::GetCapturedStdout; using testing::internal::GetCapturedStdout;
#endif #endif
// Dummy class without default constructor. // Class without default constructor.
class Dummy { class NotDefaultConstructible {
public: public:
Dummy(int) {} NotDefaultConstructible(int) {}
}; };
// Defines some mock classes needed by the tests. // Defines some mock classes needed by the tests.
@ -85,7 +85,7 @@ class MockFoo : public Foo {
MOCK_METHOD0(DoThis, void()); MOCK_METHOD0(DoThis, void());
MOCK_METHOD1(DoThat, int(bool flag)); MOCK_METHOD1(DoThat, int(bool flag));
MOCK_METHOD0(ReturnSomething, Dummy()); MOCK_METHOD0(ReturnNonDefaultConstructible, NotDefaultConstructible());
private: private:
GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo); GTEST_DISALLOW_COPY_AND_ASSIGN_(MockFoo);
@ -214,23 +214,20 @@ TEST(NiceMockTest, AllowsExpectedCall) {
nice_foo.DoThis(); nice_foo.DoThis();
} }
// Tests that an unexpected call on a nice mock which returns a non-built in // Tests that an unexpected call on a nice mock which returns a not-default-constructible
// default value throws an exception and the exception contains the name of // type throws an exception and the exception contains the method's name.
// the method.
TEST(NiceMockTest, ThrowsExceptionForUnknownReturnTypes) { TEST(NiceMockTest, ThrowsExceptionForUnknownReturnTypes) {
NiceMock<MockFoo> nice_foo; NiceMock<MockFoo> nice_foo;
#if GTEST_HAS_EXCEPTIONS #if GTEST_HAS_EXCEPTIONS
try { try {
nice_foo.ReturnSomething(); nice_foo.ReturnNonDefaultConstructible();
FAIL(); FAIL();
} catch (const std::runtime_error& ex) { } catch (const std::runtime_error& ex) {
const std::string exception_msg(ex.what()); const std::string exception_msg(ex.what());
EXPECT_NE(exception_msg.find("ReturnSomething"), std::string::npos); EXPECT_THAT(ex.what(), HasSubstr("ReturnNonDefaultConstructible"));
} }
#else #else
EXPECT_DEATH_IF_SUPPORTED({ EXPECT_DEATH_IF_SUPPORTED({ nice_foo.ReturnNonDefaultConstructible(); }, "");
nice_foo.ReturnSomething();
}, "");
#endif #endif
} }