Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uncaught Exception can be hard to detect #347

Open
LamacunLama opened this issue Dec 3, 2024 · 0 comments
Open

Uncaught Exception can be hard to detect #347

LamacunLama opened this issue Dec 3, 2024 · 0 comments

Comments

@LamacunLama
Copy link

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>());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant