rollbear / trompeloeil

Header only C++14 mocking framework
Boost Software License 1.0
802 stars 85 forks source link

Return any value #290

Closed RusYus closed 1 year ago

RusYus commented 1 year ago

Hello, If I use RETURN as this

using trompeloeil::_;
REQUIRE_CALL(*managerMock, calcAny(_)).RETURN(_);
context->calcAny(1);

I get the following error: 1>MyTest.obj : error LNK2019: unresolved external symbol "public: __thiscall trompeloeil::wildcard::operator<int> int &&(void)const " (??$?BH@wildcard@trompeloeil@@QBE$$QAHXZ) referenced in function "int __cdecl trompeloeil::trace_return<int,class <lambda_3aa1d22b1ded82218363c77ce10d4864>,class std::tuple<int &>,void>(class trompeloeil::trace_agent &,class <lambda_3aa1d22b1ded82218363c77ce10d4864> &,class std::tuple<int &> &)" (??$trace_return@HV<lambda_3aa1d22b1ded82218363c77ce10d4864>@@V?$tuple@AAH@std@@X@trompeloeil@@YAHAAVtrace_agent@0@AAV<lambda_3aa1d22b1ded82218363c77ce10d4864>@@AAV?$tuple@AAH@std@@@Z)

So it only works if I use ANY

REQUIRE_CALL(*managerMock, calcAny(_)).RETURN(ANY(int));

Is there a better way to set any return value in expectation? Basically, I need to check the call itself, don't care about any parameters.

rollbear commented 1 year ago

It doesn't work with ANY() either. It compiles, unfortunately, but you get a linker error. In the general case, it's impossible for the framework to return an arbitrary value of all types, so it's impossible to implement. Just write a value to return.

I'll try to ensure that it won't compile, hopefully with a meaningful compilation error message.

rollbear commented 1 year ago

Oh, my fault, I see that it actually does link with ANY(). It still shouldn't.

rollbear commented 1 year ago

I have now added static_asserts for these situations, explaining that it's not allowed. Closing now. I understand that this is not the resolution you were hoping for.