//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);}
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
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