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

Quickstart spy example does not work as expected #307

Open
dschulze42 opened this issue Jan 23, 2023 · 2 comments
Open

Quickstart spy example does not work as expected #307

dschulze42 opened this issue Jan 23, 2023 · 2 comments
Labels

Comments

@dschulze42
Copy link

#include <stdio.h>
#include "fakeit.hpp"

using namespace fakeit;

SCENARIO("example", "[]")
{
	GIVEN("example")
	{
		class SomeClass {
		public:
			virtual int func1(int arg) {
					return arg;
			}
			virtual int func2(int arg) {
					return arg;
			}
		};

		SomeClass obj;
		Mock<SomeClass> spy(obj);

		When(Method(spy, func1)).AlwaysReturn(10); // Override to return 10
		Spy(Method(spy, func2)); // Spying func2 without changing any behavior

		SomeClass& i = spy.get();
		std::cout << i.func1(1) << std::endl; // will print 10.
		std::cout << i.func2(1) << std::endl; // func2 is not stubbed.
	}
}

That's exactly the example from the quickstart document.
When compiled with mingw gcc (v.10.2.0) the output is

10
25163300

Shouldn't the func2 call output 1?

When compiled with mingw clang (v.10.0.0) the output is

10

So the executable crashes.
It seem to crash in class RecordedMethodBody::handleMethodInvocation but I don't get a usable exeption/error message and am not good enough at C++ to fully understand what the problem could be.

We are using fakeit v2.3.2

@FranckRJ
Copy link
Collaborator

FranckRJ commented Jan 29, 2023

I've tried with clang 14.0.6 and gcc 12.2.0 on Linux and the examples work. The library isn't tested with mingw, maybe it's not compatible with it. I don't have a mingw setup right now so I can't really test, but I'll try to when I can.

@malcolmdavey
Copy link
Contributor

Wondering if it might be related to either of these window problems (mingw is a gcc on windows)

#279
#212

@FranckRJ FranckRJ added the bug label Mar 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants