Fix Optional test for -fb platform
authorNicholas Ormrod <njormrod@fb.com>
Wed, 20 Aug 2014 01:23:44 +0000 (18:23 -0700)
committerSara Golemon <sgolemon@fb.com>
Tue, 9 Sep 2014 21:22:22 +0000 (14:22 -0700)
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

folly/test/OptionalTest.cpp

index efea777f2baef9a7d68d9ca58d530433f58a1b9e..58a20685dfdb9cac218ec3d1b7570d1eae44e828 100644 (file)
@@ -108,9 +108,28 @@ TEST(Optional, Simple) {
   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) {
-  Optional<std::string> opt;
-  std::string dflt = "hello";
+  Optional<MoveTester> opt;
+  MoveTester dflt = "hello";
   EXPECT_EQ("hello", opt.value_or(dflt));
   EXPECT_EQ("hello", dflt);
   EXPECT_EQ("hello", opt.value_or(std::move(dflt)));