Skip to content

Commit

Permalink
Merge branch 'dev-2.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
FranckRJ committed Jun 12, 2022
2 parents ded6e47 + ea7dcc5 commit 78ca536
Show file tree
Hide file tree
Showing 21 changed files with 10,620 additions and 609 deletions.
75 changes: 12 additions & 63 deletions config/catch/CatchFakeit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,74 +3,23 @@
#include "fakeit/DefaultFakeit.hpp"
#include "fakeit/EventHandler.hpp"
#include "mockutils/to_string.hpp"
#if __has_include("catch2/catch.hpp")
# include <catch2/catch.hpp>
#elif __has_include("catch2/catch_all.hpp")
# include <catch2/catch_assertion_result.hpp>
# include <catch2/catch_test_macros.hpp>
#elif __has_include("catch_amalgamated.hpp")
# include <catch_amalgamated.hpp>
#if defined __has_include
# if __has_include("catch2/catch.hpp")
# include <catch2/catch.hpp>
# elif __has_include("catch2/catch_all.hpp")
# include <catch2/catch_assertion_result.hpp>
# include <catch2/catch_test_macros.hpp>
# elif __has_include("catch_amalgamated.hpp")
# include <catch_amalgamated.hpp>
# else
# include <catch.hpp>
# endif
#else
# include <catch.hpp>
# include <catch2/catch.hpp>
#endif

namespace fakeit {

struct VerificationException : public FakeitException {
virtual ~VerificationException() = default;

void setFileInfo(const char *file, int line, const char *callingMethod) {
_file = file;
_callingMethod = callingMethod;
_line = line;
}

const char *file() const {
return _file;
}

int line() const {
return _line;
}

const char *callingMethod() const {
return _callingMethod;
}

private:
const char *_file;
int _line;
const char *_callingMethod;
};

struct NoMoreInvocationsVerificationException : public VerificationException {

NoMoreInvocationsVerificationException(std::string format) : //
_format(format) { //
}

virtual std::string what() const override {
return _format;
}

private:
std::string _format;
};

struct SequenceVerificationException : public VerificationException {
SequenceVerificationException(const std::string &format) : //
_format(format) //
{
}

virtual std::string what() const override {
return _format;
}

private:
std::string _format;
};

class CatchAdapter : public EventHandler {
EventFormatter &_formatter;

Expand Down
73 changes: 73 additions & 0 deletions config/doctest/DoctestFakeit.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#pragma once

#include "fakeit/DefaultFakeit.hpp"
#include "fakeit/EventHandler.hpp"
#include "mockutils/to_string.hpp"
#include <doctest.h>

namespace fakeit
{
class DoctestAdapter : public EventHandler
{
EventFormatter &_formatter;

public:
virtual ~DoctestAdapter() = default;

DoctestAdapter(EventFormatter &formatter)
: _formatter(formatter) {}

void fail(const char* fileName,
int lineNumber,
std::string fomattedMessage,
bool fatalFailure)
{
if (fatalFailure)
{
DOCTEST_ADD_FAIL_AT(fileName, lineNumber, fomattedMessage);
}
else
{
DOCTEST_ADD_FAIL_CHECK_AT(fileName, lineNumber, fomattedMessage);
}
}

void handle(const UnexpectedMethodCallEvent &evt) override
{
fail("Unknown file", 0, _formatter.format(evt), true);
}

void handle(const SequenceVerificationEvent &evt) override
{
fail(evt.file(), evt.line(), _formatter.format(evt), false);
}

void handle(const NoMoreInvocationsVerificationEvent &evt) override
{
fail(evt.file(), evt.line(), _formatter.format(evt), false);
}
};

class DoctestFakeit : public DefaultFakeit
{
public:
virtual ~DoctestFakeit() = default;

DoctestFakeit() : _doctestAdapter(*this) {}

static DoctestFakeit &getInstance()
{
static DoctestFakeit instance;
return instance;
}

protected:
fakeit::EventHandler &accessTestingFrameworkAdapter() override
{
return _doctestAdapter;
}

private:
DoctestAdapter _doctestAdapter;
};
}
7 changes: 7 additions & 0 deletions config/doctest/fakeit.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef fakeit_h__
#define fakeit_h__

#include "fakeit_instance.hpp"
#include "fakeit/fakeit_root.hpp"

#endif
5 changes: 5 additions & 0 deletions config/doctest/fakeit_instance.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#pragma once

#include "DoctestFakeit.hpp"

static fakeit::DefaultFakeit& Fakeit = fakeit::DoctestFakeit::getInstance();
10 changes: 9 additions & 1 deletion include/fakeit/MatchersCollector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ namespace fakeit {
template<std::size_t N>
using NakedArgType = typename naked_type<ArgType<index>>::type;

template <typename MatcherCreatorT, typename = void>
struct IsMatcherCreatorTypeCompatible : std::false_type {};

template <typename MatcherCreatorT>
struct IsMatcherCreatorTypeCompatible<MatcherCreatorT, typename std::enable_if<MatcherCreatorT::template IsTypeCompatible<NakedArgType<index>>::value, void>::type> : std::true_type {};

MatchersCollector(std::vector<Destructible *> &matchers)
: _matchers(matchers) {
}
Expand All @@ -43,6 +49,8 @@ namespace fakeit {

template<typename Head>
typename std::enable_if< //
!std::is_same<AnyMatcher, typename naked_type<Head>::type>::value &&
!IsMatcherCreatorTypeCompatible<typename naked_type<Head>::type>::value &&
std::is_constructible<NakedArgType<index>, Head&&>::value, void> //
::type CollectMatchers(Head &&value) {

Expand All @@ -52,7 +60,7 @@ namespace fakeit {

template<typename Head>
typename std::enable_if< //
naked_type<Head>::type::template IsTypeCompatible<NakedArgType<index>>::value, void> //
IsMatcherCreatorTypeCompatible<typename naked_type<Head>::type>::value, void> //
::type CollectMatchers(Head &&creator) {
TypedMatcher<NakedArgType<index>> *d = creator.template createMatcher<NakedArgType<index>>();
_matchers.push_back(d);
Expand Down
2 changes: 1 addition & 1 deletion include/fakeit/StubbingProgress.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ namespace fakeit {
template <typename T, int N>
struct ArgValue
{
ArgValue(T &&v): value { std::forward<T>(v) } {}
ArgValue(T &&v): value ( std::forward<T>(v) ) {}
constexpr static int pos = N;
T value;
};
Expand Down
1 change: 1 addition & 0 deletions include/fakeit/argument_matchers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
#pragma once

#include <cmath>
#include <cstring>

#include "mockutils/type_utils.hpp"
Expand Down
15 changes: 12 additions & 3 deletions single_header/boost/fakeit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/*
* FakeIt - A Simplified C++ Mocking Framework
* Copyright (c) Eran Pe'er 2013
* Generated: 2022-05-22 19:04:08.688985
* Generated: 2022-06-12 10:26:04.711108
* Distributed under the MIT License. Please refer to the LICENSE file at:
* https://github.com/eranpeer/FakeIt
*/
Expand Down Expand Up @@ -6372,6 +6372,7 @@ namespace fakeit {
};

}
#include <cmath>
#include <cstring>


Expand Down Expand Up @@ -7777,7 +7778,7 @@ namespace fakeit {
template <typename T, int N>
struct ArgValue
{
ArgValue(T &&v): value { std::forward<T>(v) } {}
ArgValue(T &&v): value ( std::forward<T>(v) ) {}
constexpr static int pos = N;
T value;
};
Expand Down Expand Up @@ -8070,6 +8071,12 @@ namespace fakeit {
template<std::size_t N>
using NakedArgType = typename naked_type<ArgType<index>>::type;

template <typename MatcherCreatorT, typename = void>
struct IsMatcherCreatorTypeCompatible : std::false_type {};

template <typename MatcherCreatorT>
struct IsMatcherCreatorTypeCompatible<MatcherCreatorT, typename std::enable_if<MatcherCreatorT::template IsTypeCompatible<NakedArgType<index>>::value, void>::type> : std::true_type {};

MatchersCollector(std::vector<Destructible *> &matchers)
: _matchers(matchers) {
}
Expand All @@ -8079,6 +8086,8 @@ namespace fakeit {

template<typename Head>
typename std::enable_if<
!std::is_same<AnyMatcher, typename naked_type<Head>::type>::value &&
!IsMatcherCreatorTypeCompatible<typename naked_type<Head>::type>::value &&
std::is_constructible<NakedArgType<index>, Head&&>::value, void>
::type CollectMatchers(Head &&value) {

Expand All @@ -8088,7 +8097,7 @@ namespace fakeit {

template<typename Head>
typename std::enable_if<
naked_type<Head>::type::template IsTypeCompatible<NakedArgType<index>>::value, void>
IsMatcherCreatorTypeCompatible<typename naked_type<Head>::type>::value, void>
::type CollectMatchers(Head &&creator) {
TypedMatcher<NakedArgType<index>> *d = creator.template createMatcher<NakedArgType<index>>();
_matchers.push_back(d);
Expand Down
Loading

0 comments on commit 78ca536

Please sign in to comment.