ProgramFan / googlemock

Automatically exported from code.google.com/p/googlemock
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Throwing an exception as default breaks call count expectation #171

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
using gmock 1.7.0, gtest 1.7.0 on linux x64 (ubuntu 14.10)

Example:

----
class MyMock {
public:
  MOCK_METHOD0(func, void());
};

TEST(MyTest, testMock) {
  MyMock mock;
  ON_CALL(mock, func()).WillByDefault(Throw(std::logic_error("error")));
  EXPECT_CALL(mock, func()).Times(0);
  try {
    mock.func();
  } catch (std::logic_error &e) {
  }
}
----

The test is green and passes. I expect it to fail, because the mock function is 
called once but I expect it not to be..

I assume in the gmock implementation, the call counter is incremented after the 
function returns and throwing an exception jumps over this piece of code.

Original issue reported on code.google.com by heinzis...@gmail.com on 20 Nov 2014 at 11:33