Commit 1cab639b authored by Nicholas Ormrod's avatar Nicholas Ormrod Committed by Sara Golemon

Fix Optional test for -fb platform

Summary:
The Optional test relied on std::string clearing its data when
it is the source of a move. This does not happen for in-situ fbstrings,
so the test breaks in the -fb platform. The solution: wrap the string in
a class that explicitly invalidates its data upon a move.

Test Plan:
fbconfig --platform-all=gcc-4.8.1-glibc-2.17-fb -r folly
fbmake runtests
fbconfig -r folly
fbmake runtests

Reviewed By: tudorb@fb.com

Subscribers: sdwilsh

FB internal diff: D1506840

Tasks: 4943996
parent 33f1f3d1
...@@ -108,9 +108,28 @@ TEST(Optional, Simple) { ...@@ -108,9 +108,28 @@ TEST(Optional, Simple) {
EXPECT_FALSE(bool(opt)); EXPECT_FALSE(bool(opt));
} }
class MoveTester {
public:
/* implicit */ MoveTester(const char* s) : s_(s) {}
MoveTester(const MoveTester&) = default;
MoveTester(MoveTester&& other) noexcept {
s_ = std::move(other.s_);
other.s_ = "";
}
MoveTester& operator=(const MoveTester&) = default;
MoveTester& operator=(MoveTester&&) = default;
private:
friend bool operator==(const MoveTester& o1, const MoveTester& o2);
std::string s_;
};
bool operator==(const MoveTester& o1, const MoveTester& o2) {
return o1.s_ == o2.s_;
}
TEST(Optional, value_or_rvalue_arg) { TEST(Optional, value_or_rvalue_arg) {
Optional<std::string> opt; Optional<MoveTester> opt;
std::string dflt = "hello"; MoveTester dflt = "hello";
EXPECT_EQ("hello", opt.value_or(dflt)); EXPECT_EQ("hello", opt.value_or(dflt));
EXPECT_EQ("hello", dflt); EXPECT_EQ("hello", dflt);
EXPECT_EQ("hello", opt.value_or(std::move(dflt))); EXPECT_EQ("hello", opt.value_or(std::move(dflt)));
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment