eranpeer / FakeIt

C++ mocking made easy. A simple yet very expressive, headers only library for c++ mocking.
MIT License
1.22k stars 170 forks source link

Add Any verification specifier #247

Closed FranckRJ closed 2 years ago

FranckRJ commented 3 years ago

A flexible test may want to ignore invocations of trivial methods, like getters and read only functions. Such methods may be called any number of times, including none.

Currently FakeIt has no way to discard the invocations of a sequence of methods. Using ClearInvocationHistory would discard all the methods, trivial or not.

This new verification specifier, Any, marks a method or sequence of methods as verified, regardless of the number of invocations (including none).

Example:

Verify(Method(mock, important_method)).Exactly(3);
Verify(Method(mock, trivial_getter)).Any();
VerifyNoOtherInvocations(mock);

Using this modifier, a flexible test may white-list the trivial methods, and make sure that important methods are not called.

oriolarcas commented 2 years ago

Thank you @FranckRJ.

coveralls commented 2 years ago

Coverage Status

Coverage increased (+0.0002%) to 99.923% when pulling 0bb1d6e87447e168b4e24f3d3165c01e959e626a on any-verif-specifier into 80a446b8d9a8740a58e09b004d5ac0c3094400bb on dev-2.1.0.

FranckRJ commented 2 years ago

It's a bit weird that new lines aren't marked as red in coverage report... I probably missed something.

FranckRJ commented 2 years ago

But it looks like it was the same before I changed the CI. This coverage was made with the old CI and some lines aren't included not sure why : https://coveralls.io/builds/39617213/source?filename=include%2Ffakeit%2FSequenceVerificationExpectation.hpp#L23

It's compiled with -O0 so I guess these lines shouldn't be removed, don't know.