eranpeer / FakeIt

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

Do/AlwaysDo don't accept movable only arguments #145

Open reddwarf69 opened 6 years ago

reddwarf69 commented 6 years ago

I have to stub a function that returns a future. So I create a promise, get a future from it and pass this future to a lambda that returns it. The lambda itself is movable, but not copyable, because the future it contains is the same. This should not be an issue, but when passing (a r-value reference to) the lambda to Do()/AlwaysDo() FakeIt tries to copy the lambda, which fails.

ranty-fugue commented 5 years ago

I'm running into this, too.

Given an interface like this:

struct rvtest
{
    virtual ~rvtest() = default;
    virtual std::unique_ptr<int> ui() const = 0;
};

Adding the following to a test causes a compile error, where the code wants to call the copy constructor of unique_ptr:

Mock<rvtest> testDouble;
When(Method(testDouble, ui)).AlwaysReturn(std::unique_ptr<int>{});

(AlwaysReturn() relies on AlwaysDo)

Any thoughts on a possible resolution? This is a pretty common use case.