mirror of
https://github.com/google/googletest.git
synced 2025-11-10 15:05:24 -05:00
Add support for move-only and &&-qualified actions in WillOnce.
This provides a type-safe way for an action to express that it wants to be called only once, or to capture move-only objects. It is a generalization of the type system-evading hack in ByMove, with the improvement that it works for _any_ action (including user-defined ones), and correctly expresses that the action can only be used with WillOnce. I'll make existing actions benefit in a future commit. PiperOrigin-RevId: 440496139 Change-Id: I4145d191cca5655995ef41360bb126c123cb41d3
This commit is contained in:
committed by
Copybara-Service
parent
5f467ec04d
commit
a1cc8c5519
@@ -992,14 +992,16 @@ class TypedExpectation : public ExpectationBase {
|
||||
return After(s1, s2, s3, s4).After(s5);
|
||||
}
|
||||
|
||||
// Implements the .WillOnce() clause.
|
||||
TypedExpectation& WillOnce(const Action<F>& action) {
|
||||
// Implements the .WillOnce() clause for copyable actions.
|
||||
TypedExpectation& WillOnce(OnceAction<F> once_action) {
|
||||
ExpectSpecProperty(last_clause_ <= kWillOnce,
|
||||
".WillOnce() cannot appear after "
|
||||
".WillRepeatedly() or .RetiresOnSaturation().");
|
||||
last_clause_ = kWillOnce;
|
||||
|
||||
untyped_actions_.push_back(new Action<F>(action));
|
||||
untyped_actions_.push_back(
|
||||
new Action<F>(std::move(once_action).ReleaseAction()));
|
||||
|
||||
if (!cardinality_specified()) {
|
||||
set_cardinality(Exactly(static_cast<int>(untyped_actions_.size())));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user