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

Crash using mock with unique_ptr #143

Closed ericlemes closed 5 years ago

ericlemes commented 6 years ago

Okay, there's a few issues about this, but I managed to capture creating a unit test in the FakeIt code base. It is very odd.

void production_takes_ownership_interface_with_more_methods() {
    Mock<SomeInterface2> m;

    Fake(Dtor(m));

    std::unique_ptr<SomeInterface2> ptr = std::unique_ptr<SomeInterface2>(&m.get());        
}

class SomeInterface2 {
public:
    virtual void DoSomething() = 0;
    virtual ~SomeInterface2() = default;
};

I noticed that not having the DoSomething() method makes the test working. Also inverting the order of the destructor and DoSomething fixes the crash.

Interestingly seems to be an undefined behaviour because it just aborts the test not throwing an exception or any other behaviour.

I appreciate any help.

This crash is happening in VS2017, version 15.7.1.

ericlemes commented 6 years ago

Proposed fix: https://github.com/eranpeer/FakeIt/pull/144