Skip to content

Commit

Permalink
Merge 6cab5b1 into 26e86de
Browse files Browse the repository at this point in the history
  • Loading branch information
FranckRJ committed Dec 1, 2022
2 parents 26e86de + 6cab5b1 commit 1bc9a9a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 5 additions & 0 deletions include/fakeit/ActionSequence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ namespace fakeit {
Action<R, arglist...> &action = dynamic_cast<Action<R, arglist...> &>(destructable);
std::function<void()> finallyClause = [&]() -> void {
if (action.isDone())
{
_recordedActions.erase(_recordedActions.begin());
_usedActions.push_back(destructablePtr);
}
};
Finally onExit(finallyClause);
return action.invoke(args);
Expand Down Expand Up @@ -76,11 +79,13 @@ namespace fakeit {

void clear() {
_recordedActions.clear();
_usedActions.clear();
auto actionPtr = std::shared_ptr<Destructible> {new NoMoreRecordedAction()};
_recordedActions.push_back(actionPtr);
}

std::vector<std::shared_ptr<Destructible>> _recordedActions;
std::vector<std::shared_ptr<Destructible>> _usedActions;
};

}
19 changes: 18 additions & 1 deletion tests/stubbing_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ struct BasicStubbing : tpunit::TestFixture {
TEST(BasicStubbing::exception_while_stubbing_should_cancel_stubbing),
TEST(BasicStubbing::reset_mock_to_initial_state),
TEST(BasicStubbing::use_lambda_to_change_ptr_value),
TEST(BasicStubbing::assingOutParamsWithLambda)
TEST(BasicStubbing::assingOutParamsWithLambda),
TEST(BasicStubbing::throw_string_literal)
) {
}

Expand Down Expand Up @@ -868,5 +869,21 @@ struct BasicStubbing : tpunit::TestFixture {
ASSERT_EQUAL(3,result);
}

void throw_string_literal() {
Mock<SomeInterface> mock;

When(Method(mock, func)).Throw("an exception that is a string literal");

SomeInterface& i = mock.get();

try {
i.func(1);
} catch (const char* str) {
ASSERT_EQUAL(std::string("an exception that is a string literal"), str);
}

ASSERT_THROW(i.func(1), fakeit::UnexpectedMethodCallException);
}

} __BasicStubbing;

0 comments on commit 1bc9a9a

Please sign in to comment.