Skip to content

Commit

Permalink
Merge branch 'dev-2.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
FranckRJ committed Mar 13, 2022
2 parents 80a446b + c523986 commit 98979d2
Show file tree
Hide file tree
Showing 20 changed files with 5,681 additions and 111 deletions.
15 changes: 15 additions & 0 deletions config/catch/CatchFakeit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
#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>
#else
# include <catch.hpp>
#endif
Expand Down Expand Up @@ -91,6 +96,7 @@ namespace fakeit {
std::string fomattedMessage,
Catch::ResultWas::OfType resultWas = Catch::ResultWas::OfType::ExpressionFailed ){
Catch::AssertionHandler catchAssertionHandler( vetificationType, sourceLineInfo, failingExpression, Catch::ResultDisposition::Normal );
#if defined(CATCH_INTERNAL_START_WARNINGS_SUPPRESSION) && defined(CATCH_INTERNAL_STOP_WARNINGS_SUPPRESSION)
INTERNAL_CATCH_TRY { \
CATCH_INTERNAL_START_WARNINGS_SUPPRESSION \
CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
Expand All @@ -99,6 +105,15 @@ namespace fakeit {
} INTERNAL_CATCH_CATCH(catchAssertionHandler) { \
INTERNAL_CATCH_REACT(catchAssertionHandler) \
}
#else
INTERNAL_CATCH_TRY { \
CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
catchAssertionHandler.handleMessage(resultWas, fomattedMessage); \
CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
} INTERNAL_CATCH_CATCH(catchAssertionHandler) { \
INTERNAL_CATCH_REACT(catchAssertionHandler) \
}
#endif
}

virtual void handle(const UnexpectedMethodCallEvent &evt) override {
Expand Down
3 changes: 1 addition & 2 deletions include/fakeit/MockImpl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -226,8 +226,7 @@ namespace fakeit {
}

virtual std::function<void()> getOriginalMethod() override {
C &instance = MethodMockingContextBase<void>::_mock.get();
return [=, &instance]() -> void {
return [=]() -> void {
};
}

Expand Down
22 changes: 17 additions & 5 deletions include/fakeit/SequenceVerificationExpectation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ namespace fakeit {
_expectedCount = count;
}

void expectAnything() {
_expectAnything = true;
}

void setFileInfo(const char * file, int line, const char * callingMethod) {
_file = file;
_line = line;
Expand All @@ -39,6 +43,7 @@ namespace fakeit {
InvocationsSourceProxy _involvedInvocationSources;
std::vector<Sequence *> _expectedPattern;
int _expectedCount;
bool _expectAnything;

const char * _file;
int _line;
Expand All @@ -53,6 +58,7 @@ namespace fakeit {
_involvedInvocationSources(mocks),
_expectedPattern(expectedPattern), //
_expectedCount(-1), // AT_LEAST_ONCE
_expectAnything(false),
_line(0),
_isVerified(false) {
}
Expand All @@ -66,12 +72,14 @@ namespace fakeit {
MatchAnalysis ma;
ma.run(_involvedInvocationSources, _expectedPattern);

if (isAtLeastVerification() && atLeastLimitNotReached(ma.count)) {
return handleAtLeastVerificationEvent(verificationErrorHandler, ma.actualSequence, ma.count);
}
if (isNotAnythingVerification()) {
if (isAtLeastVerification() && atLeastLimitNotReached(ma.count)) {
return handleAtLeastVerificationEvent(verificationErrorHandler, ma.actualSequence, ma.count);
}

if (isExactVerification() && exactLimitNotMatched(ma.count)) {
return handleExactVerificationEvent(verificationErrorHandler, ma.actualSequence, ma.count);
if (isExactVerification() && exactLimitNotMatched(ma.count)) {
return handleExactVerificationEvent(verificationErrorHandler, ma.actualSequence, ma.count);
}
}

markAsVerified(ma.matchedInvocations);
Expand All @@ -95,6 +103,10 @@ namespace fakeit {
}
}

bool isNotAnythingVerification() {
return !_expectAnything;
}

bool isAtLeastVerification() {
// negative number represents an "AtLeast" search;
return _expectedCount < 0;
Expand Down
5 changes: 5 additions & 0 deletions include/fakeit/SequenceVerificationProgress.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ namespace fakeit {

bool operator!() const { return !Terminator(_expectationPtr); }

Terminator Any() {
_expectationPtr->expectAnything();
return Terminator(_expectationPtr);
}

Terminator Never() {
Exactly(0);
return Terminator(_expectationPtr);
Expand Down
Loading

0 comments on commit 98979d2

Please sign in to comment.