Skip to content

Commit 78ca536

Browse files
committed
Merge branch 'dev-2.3.0'
2 parents ded6e47 + ea7dcc5 commit 78ca536

File tree

21 files changed

+10620
-609
lines changed

21 files changed

+10620
-609
lines changed

config/catch/CatchFakeit.hpp

Lines changed: 12 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -3,74 +3,23 @@
33
#include "fakeit/DefaultFakeit.hpp"
44
#include "fakeit/EventHandler.hpp"
55
#include "mockutils/to_string.hpp"
6-
#if __has_include("catch2/catch.hpp")
7-
# include <catch2/catch.hpp>
8-
#elif __has_include("catch2/catch_all.hpp")
9-
# include <catch2/catch_assertion_result.hpp>
10-
# include <catch2/catch_test_macros.hpp>
11-
#elif __has_include("catch_amalgamated.hpp")
12-
# include <catch_amalgamated.hpp>
6+
#if defined __has_include
7+
# if __has_include("catch2/catch.hpp")
8+
# include <catch2/catch.hpp>
9+
# elif __has_include("catch2/catch_all.hpp")
10+
# include <catch2/catch_assertion_result.hpp>
11+
# include <catch2/catch_test_macros.hpp>
12+
# elif __has_include("catch_amalgamated.hpp")
13+
# include <catch_amalgamated.hpp>
14+
# else
15+
# include <catch.hpp>
16+
# endif
1317
#else
14-
# include <catch.hpp>
18+
# include <catch2/catch.hpp>
1519
#endif
1620

1721
namespace fakeit {
1822

19-
struct VerificationException : public FakeitException {
20-
virtual ~VerificationException() = default;
21-
22-
void setFileInfo(const char *file, int line, const char *callingMethod) {
23-
_file = file;
24-
_callingMethod = callingMethod;
25-
_line = line;
26-
}
27-
28-
const char *file() const {
29-
return _file;
30-
}
31-
32-
int line() const {
33-
return _line;
34-
}
35-
36-
const char *callingMethod() const {
37-
return _callingMethod;
38-
}
39-
40-
private:
41-
const char *_file;
42-
int _line;
43-
const char *_callingMethod;
44-
};
45-
46-
struct NoMoreInvocationsVerificationException : public VerificationException {
47-
48-
NoMoreInvocationsVerificationException(std::string format) : //
49-
_format(format) { //
50-
}
51-
52-
virtual std::string what() const override {
53-
return _format;
54-
}
55-
56-
private:
57-
std::string _format;
58-
};
59-
60-
struct SequenceVerificationException : public VerificationException {
61-
SequenceVerificationException(const std::string &format) : //
62-
_format(format) //
63-
{
64-
}
65-
66-
virtual std::string what() const override {
67-
return _format;
68-
}
69-
70-
private:
71-
std::string _format;
72-
};
73-
7423
class CatchAdapter : public EventHandler {
7524
EventFormatter &_formatter;
7625

config/doctest/DoctestFakeit.hpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#pragma once
2+
3+
#include "fakeit/DefaultFakeit.hpp"
4+
#include "fakeit/EventHandler.hpp"
5+
#include "mockutils/to_string.hpp"
6+
#include <doctest.h>
7+
8+
namespace fakeit
9+
{
10+
class DoctestAdapter : public EventHandler
11+
{
12+
EventFormatter &_formatter;
13+
14+
public:
15+
virtual ~DoctestAdapter() = default;
16+
17+
DoctestAdapter(EventFormatter &formatter)
18+
: _formatter(formatter) {}
19+
20+
void fail(const char* fileName,
21+
int lineNumber,
22+
std::string fomattedMessage,
23+
bool fatalFailure)
24+
{
25+
if (fatalFailure)
26+
{
27+
DOCTEST_ADD_FAIL_AT(fileName, lineNumber, fomattedMessage);
28+
}
29+
else
30+
{
31+
DOCTEST_ADD_FAIL_CHECK_AT(fileName, lineNumber, fomattedMessage);
32+
}
33+
}
34+
35+
void handle(const UnexpectedMethodCallEvent &evt) override
36+
{
37+
fail("Unknown file", 0, _formatter.format(evt), true);
38+
}
39+
40+
void handle(const SequenceVerificationEvent &evt) override
41+
{
42+
fail(evt.file(), evt.line(), _formatter.format(evt), false);
43+
}
44+
45+
void handle(const NoMoreInvocationsVerificationEvent &evt) override
46+
{
47+
fail(evt.file(), evt.line(), _formatter.format(evt), false);
48+
}
49+
};
50+
51+
class DoctestFakeit : public DefaultFakeit
52+
{
53+
public:
54+
virtual ~DoctestFakeit() = default;
55+
56+
DoctestFakeit() : _doctestAdapter(*this) {}
57+
58+
static DoctestFakeit &getInstance()
59+
{
60+
static DoctestFakeit instance;
61+
return instance;
62+
}
63+
64+
protected:
65+
fakeit::EventHandler &accessTestingFrameworkAdapter() override
66+
{
67+
return _doctestAdapter;
68+
}
69+
70+
private:
71+
DoctestAdapter _doctestAdapter;
72+
};
73+
}

config/doctest/fakeit.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#ifndef fakeit_h__
2+
#define fakeit_h__
3+
4+
#include "fakeit_instance.hpp"
5+
#include "fakeit/fakeit_root.hpp"
6+
7+
#endif

config/doctest/fakeit_instance.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#include "DoctestFakeit.hpp"
4+
5+
static fakeit::DefaultFakeit& Fakeit = fakeit::DoctestFakeit::getInstance();

include/fakeit/MatchersCollector.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ namespace fakeit {
3434
template<std::size_t N>
3535
using NakedArgType = typename naked_type<ArgType<index>>::type;
3636

37+
template <typename MatcherCreatorT, typename = void>
38+
struct IsMatcherCreatorTypeCompatible : std::false_type {};
39+
40+
template <typename MatcherCreatorT>
41+
struct IsMatcherCreatorTypeCompatible<MatcherCreatorT, typename std::enable_if<MatcherCreatorT::template IsTypeCompatible<NakedArgType<index>>::value, void>::type> : std::true_type {};
42+
3743
MatchersCollector(std::vector<Destructible *> &matchers)
3844
: _matchers(matchers) {
3945
}
@@ -43,6 +49,8 @@ namespace fakeit {
4349

4450
template<typename Head>
4551
typename std::enable_if< //
52+
!std::is_same<AnyMatcher, typename naked_type<Head>::type>::value &&
53+
!IsMatcherCreatorTypeCompatible<typename naked_type<Head>::type>::value &&
4654
std::is_constructible<NakedArgType<index>, Head&&>::value, void> //
4755
::type CollectMatchers(Head &&value) {
4856

@@ -52,7 +60,7 @@ namespace fakeit {
5260

5361
template<typename Head>
5462
typename std::enable_if< //
55-
naked_type<Head>::type::template IsTypeCompatible<NakedArgType<index>>::value, void> //
63+
IsMatcherCreatorTypeCompatible<typename naked_type<Head>::type>::value, void> //
5664
::type CollectMatchers(Head &&creator) {
5765
TypedMatcher<NakedArgType<index>> *d = creator.template createMatcher<NakedArgType<index>>();
5866
_matchers.push_back(d);

include/fakeit/StubbingProgress.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ namespace fakeit {
362362
template <typename T, int N>
363363
struct ArgValue
364364
{
365-
ArgValue(T &&v): value { std::forward<T>(v) } {}
365+
ArgValue(T &&v): value ( std::forward<T>(v) ) {}
366366
constexpr static int pos = N;
367367
T value;
368368
};

include/fakeit/argument_matchers.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
*/
99
#pragma once
1010

11+
#include <cmath>
1112
#include <cstring>
1213

1314
#include "mockutils/type_utils.hpp"

single_header/boost/fakeit.hpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/*
33
* FakeIt - A Simplified C++ Mocking Framework
44
* Copyright (c) Eran Pe'er 2013
5-
* Generated: 2022-05-22 19:04:08.688985
5+
* Generated: 2022-06-12 10:26:04.711108
66
* Distributed under the MIT License. Please refer to the LICENSE file at:
77
* https://github.com/eranpeer/FakeIt
88
*/
@@ -6372,6 +6372,7 @@ namespace fakeit {
63726372
};
63736373

63746374
}
6375+
#include <cmath>
63756376
#include <cstring>
63766377

63776378

@@ -7777,7 +7778,7 @@ namespace fakeit {
77777778
template <typename T, int N>
77787779
struct ArgValue
77797780
{
7780-
ArgValue(T &&v): value { std::forward<T>(v) } {}
7781+
ArgValue(T &&v): value ( std::forward<T>(v) ) {}
77817782
constexpr static int pos = N;
77827783
T value;
77837784
};
@@ -8070,6 +8071,12 @@ namespace fakeit {
80708071
template<std::size_t N>
80718072
using NakedArgType = typename naked_type<ArgType<index>>::type;
80728073

8074+
template <typename MatcherCreatorT, typename = void>
8075+
struct IsMatcherCreatorTypeCompatible : std::false_type {};
8076+
8077+
template <typename MatcherCreatorT>
8078+
struct IsMatcherCreatorTypeCompatible<MatcherCreatorT, typename std::enable_if<MatcherCreatorT::template IsTypeCompatible<NakedArgType<index>>::value, void>::type> : std::true_type {};
8079+
80738080
MatchersCollector(std::vector<Destructible *> &matchers)
80748081
: _matchers(matchers) {
80758082
}
@@ -8079,6 +8086,8 @@ namespace fakeit {
80798086

80808087
template<typename Head>
80818088
typename std::enable_if<
8089+
!std::is_same<AnyMatcher, typename naked_type<Head>::type>::value &&
8090+
!IsMatcherCreatorTypeCompatible<typename naked_type<Head>::type>::value &&
80828091
std::is_constructible<NakedArgType<index>, Head&&>::value, void>
80838092
::type CollectMatchers(Head &&value) {
80848093

@@ -8088,7 +8097,7 @@ namespace fakeit {
80888097

80898098
template<typename Head>
80908099
typename std::enable_if<
8091-
naked_type<Head>::type::template IsTypeCompatible<NakedArgType<index>>::value, void>
8100+
IsMatcherCreatorTypeCompatible<typename naked_type<Head>::type>::value, void>
80928101
::type CollectMatchers(Head &&creator) {
80938102
TypedMatcher<NakedArgType<index>> *d = creator.template createMatcher<NakedArgType<index>>();
80948103
_matchers.push_back(d);

0 commit comments

Comments
 (0)