-
Notifications
You must be signed in to change notification settings - Fork 177
Description
With the following little program, an uncaught exception is provoked.
#include "single_header/standalone/fakeit.hpp"
using namespace fakeit;
class NotDefaultConstructible
{
public:
NotDefaultConstructible(int a){}
};
class ToMock
{
public:
virtual NotDefaultConstructible MyFunc() = 0;
};
int main()
{
Mock<ToMock> myMock;
Fake(Method(myMock, MyFunc));
myMock.get().MyFunc();
}
If this exception is thrown when fakeit is used in combination with BOOST Test, the exception text of boost says: unknown type and with unknown type the exception type "DefaultValueInstatiationException" is meant. I don't know who is trying to catch such an exception type. It would be much more useful in this context to see a proper error description in the print output, which is already included in the .what().
I don't know if the following statement covers all use cases, but for me it would be easier to have a failing static_assertion if the return type of a faked function has no default constructor. This would therefore force the user to use "When" and to manually return something.
The check for this would look similar to this:
using ReturnType = decltype(myMock.get().MyFunc());
static_assert(std::is_constructible<ReturnType>());