dascandy / hippomocks

GNU Lesser General Public License v2.1
196 stars 67 forks source link

Add support for nice mocks #83

Closed APokorny closed 7 years ago

APokorny commented 7 years ago

Nice mocks do not complain when a method is called that is not expected. This is similar to the nice mock concept in GMock. To make use of that feature, just use NiceMock<Type>() instead of Mock<Type>().

APokorny commented 7 years ago

I based this proposal on the unique_ptr change because it touches the same code, and I think both are very useful..

dascandy commented 7 years ago

... Not looking at the build results so much, but how is this supposed to work? The called function cannot know what arguments there are so it can't remove them from the stack in callee-cleanup environments (MSVC).

APokorny commented 7 years ago

Build failed due to a missing file - but yes this is more than undefined behavior.

APokorny commented 7 years ago

I think this is extremely helpful when you construct mocks inside fixtures.. Do you have any ideas on how to make that portable?

dascandy commented 7 years ago
  1. This is very quickly undefined behaviour & crashing if you call a function that has a nontrivial return type
  2. This cannot be ported to Windows for anything other than functions without arguments
  3. Even in the case that you have a trivial return type, the return value is undefined

So this only actually allows you to call functions that have no return value on non-Windows, or functions that have no return value with no arguments reliably. Functions with a trivial return value will "work" but return uninitialized memory (so pointers are whatever rax held at the time of calling, floats can be NaN or denormal accidentally - or heck, an uninitialized FP register causing the FP stack to be unbalanced, other things).

This is why it was not added before.

APokorny commented 7 years ago

Ok all in all a bad idea without reflection.. So I will look into making it easy to specify a list of ignored methods..