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

Using works inside When but do not work inside Verify #168

Closed artemyv closed 2 years ago

artemyv commented 5 years ago

I have written following test (I could not make a code look like code so here is the link to commit) https://github.com/artemyv/Helloworld/blob/3fdfb7f06d806f4660b434cdf434ead023a9f983/TestCatch2/Test.cpp

//downloaded from https://github.com/catchorg/Catch2/tree/master/single_include/catch2 // Catch v2.6.1 Generated: 2019-02-12 19:52:52.262497 #include "catch.hpp"

//downloaded from https://github.com/eranpeer/FakeIt/tree/master/single_header/catch // FakeIt - A Simplified C++ Mocking Framework // Generated: 2018-08-17 00:22:40.428924 #include "fakeit.hpp"

using namespace fakeit; #include <string>

struct InterfaceSample { virtual int bar(const std::string&) const = 0; };

int func_sample(const InterfaceSample& i, const std::string& val) { return i.bar(val); }

TEST_CASE("Fakeit.Verify", "[Fake]") { Mock mock; SECTION("Good") { When(Method(mock, bar).Using("1")).Return(100); REQUIRE(func_sample(mock.get(), "1") == 100); Verify(Method(mock, bar).Using("1")).Once(); } }

And got following result `$ TestCatch2.exe - s - r compact test.cpp(22) : passed: func_sample(mock.get(), "1") == 100 for : 100 == 100 test.cpp(23) : failed: mock.bar(1) with 1 message : 'test.cpp(23): Verification error Expected pattern : mock.bar(1) Expected matches : exactly 1 Actual matches : 0 Actual sequence : total of 1 actual invocations : mock.bar()' Failed 1 test case, failed 1 assertion.

So it looks like Using("1") worked well inside When but failed to match the call inside Verify

ranty-fugue commented 5 years ago

I've noticed this, too, using near-identical code. Is there something we're doing wrong, @eranpeer ?

FranckRJ commented 2 years ago

I'll centralize the discussion about this known bug in a new issue: #274