Googletest export
Fix DoAll to work with move-only sink arguments. This changes types of the first n - 1 actions so that they only get a readonly view of the arguments. The last action will accept move only objects. PiperOrigin-RevId: 327031893
This commit is contained in:
@@ -422,6 +422,33 @@ TEST(DoAllTest, TenActions) {
|
||||
EXPECT_EQ('g', g);
|
||||
}
|
||||
|
||||
TEST(DoAllTest, NoArgs) {
|
||||
bool ran_first = false;
|
||||
Action<bool()> a =
|
||||
DoAll([&] { ran_first = true; }, [&] { return ran_first; });
|
||||
EXPECT_TRUE(a.Perform({}));
|
||||
}
|
||||
|
||||
TEST(DoAllTest, MoveOnlyArgs) {
|
||||
bool ran_first = false;
|
||||
Action<int(std::unique_ptr<int>)> a =
|
||||
DoAll(InvokeWithoutArgs([&] { ran_first = true; }),
|
||||
[](std::unique_ptr<int> p) { return *p; });
|
||||
EXPECT_EQ(7, a.Perform(std::make_tuple(std::unique_ptr<int>(new int(7)))));
|
||||
EXPECT_TRUE(ran_first);
|
||||
}
|
||||
|
||||
TEST(DoAllTest, ImplicitlyConvertsActionArguments) {
|
||||
bool ran_first = false;
|
||||
// Action<void(std::vector<int>)> isn't an
|
||||
// Action<void(const std::vector<int>&) but can be converted.
|
||||
Action<void(std::vector<int>)> first = [&] { ran_first = true; };
|
||||
Action<int(std::vector<int>)> a =
|
||||
DoAll(first, [](std::vector<int> arg) { return arg.front(); });
|
||||
EXPECT_EQ(7, a.Perform(std::make_tuple(std::vector<int>{7})));
|
||||
EXPECT_TRUE(ran_first);
|
||||
}
|
||||
|
||||
// The ACTION*() macros trigger warning C4100 (unreferenced formal
|
||||
// parameter) in MSVC with -W4. Unfortunately they cannot be fixed in
|
||||
// the macro definition, as the warnings are generated when the macro
|
||||
|
||||
Reference in New Issue
Block a user