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

Fix Spy() to copy args and add SpyWithoutVerify() for move-only types #272

Closed FranckRJ closed 2 years ago

FranckRJ commented 2 years ago

Now Spy() copy arguments instead of forwarding them to the original method, so the arguments can be stored for Verify()ing them later. If an argument is move-only, the compiler should give a somewhat nice error message:

../include/fakeit/SpyFunctor.hpp:32:27: error: static assertion failed: Spy() cannot accept move-only args, use SpyWithoutVerify() instead which is able to forward these args but then they won't by available for Verify().
   32 |             static_assert(!std::is_same<R, R>::value, "Spy() cannot accept move-only args, use SpyWithoutVerify() instead which is able to forward these args but then they won't by available for Verify().");
      |                           ^~~~~~~~~~~~~~~~~~~~~~~~~~                           

As the error message said, there is a new function SpyWithoutVerify() that behave as the old Spy(), it forward the arguments, thus making them impossible to check with the Verify() function later.

Should fix #191 and #205.

FranckRJ commented 2 years ago

I'm not completely sure about the name of SpyWithoutVerify(), maybe it should be called SpyForwardArgs(), but then it isn't obvious that the function "disable" verification, so I don't know.

coveralls commented 2 years ago

Coverage Status

Coverage increased (+0.0005%) to 99.925% when pulling 3309735175e814cdbd8bb2be64dd64666aae00d9 on fix-spy into a64f1c795c5ce5493455185f08945bebadd57b19 on dev-2.2.0.

FranckRJ commented 2 years ago

After a bit of reflection I think I'll let it like that. If the name is proven to be bad it can always change, the old one will just stay here, deprecated.