add missing include to ThreadId.h
[folly.git] / folly / test / ExpectedTest.cpp
index 771d81ed9cc43b2fc347ffc957aa01b6bbe60256..da2ede70ccc73cbbcde583aa35ab9c0313a5b39b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2016 Facebook, Inc.
+ * Copyright 2017 Facebook, Inc.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -15,7 +15,7 @@
  */
 
 #include <folly/Expected.h>
-#include <folly/Portability.h>
+#include <folly/portability/GTest.h>
 
 #include <algorithm>
 #include <iomanip>
@@ -25,7 +25,6 @@
 #include <vector>
 
 #include <glog/logging.h>
-#include <gtest/gtest.h>
 
 using std::unique_ptr;
 using std::shared_ptr;
@@ -64,17 +63,17 @@ TEST(Expected, NoDefault) {
   static_assert(
       std::is_default_constructible<Expected<NoDefault, int>>::value, "");
   Expected<NoDefault, int> x{in_place, 42, 42};
-  EXPECT_TRUE(x);
+  EXPECT_TRUE(bool(x));
   x.emplace(4, 5);
   EXPECT_TRUE(bool(x));
   x = makeUnexpected(42);
-  EXPECT_FALSE(x);
+  EXPECT_FALSE(bool(x));
   EXPECT_EQ(42, x.error());
 }
 
 TEST(Expected, String) {
   Expected<std::string, int> maybeString;
-  EXPECT_FALSE(maybeString);
+  EXPECT_FALSE(bool(maybeString));
   EXPECT_EQ(0, maybeString.error());
   maybeString = "hello";
   EXPECT_TRUE(bool(maybeString));
@@ -453,7 +452,7 @@ TEST(Expected, MakeOptional) {
   EXPECT_EQ(**exIntPtr, 3);
 }
 
-#if __CLANG_PREREQ(3, 6)
+#if __clang__
 #pragma clang diagnostic push
 #pragma clang diagnostic ignored "-Wself-move"
 #endif
@@ -468,7 +467,7 @@ TEST(Expected, SelfAssignment) {
   ASSERT_TRUE(b.hasValue() && b.value() == "23333333");
 }
 
-#if __CLANG_PREREQ(3, 6)
+#if __clang__
 #pragma clang diagnostic pop
 #endif
 
@@ -560,6 +559,36 @@ TEST(Expected, NoThrowMoveAssignable) {
       (std::is_nothrow_move_assignable<Expected<ThrowingBadness, E>>::value));
 }
 
+struct NoSelfAssign {
+  NoSelfAssign() = default;
+  NoSelfAssign(NoSelfAssign&&) = default;
+  NoSelfAssign(const NoSelfAssign&) = default;
+  NoSelfAssign& operator=(NoSelfAssign&& that) {
+    EXPECT_NE(this, &that);
+    return *this;
+  }
+  NoSelfAssign& operator=(const NoSelfAssign& that) {
+    EXPECT_NE(this, &that);
+    return *this;
+  }
+};
+
+#ifdef __GNUC__
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpragmas"
+#pragma GCC diagnostic ignored "-Wself-move"
+#endif
+
+TEST(Expected, NoSelfAssign) {
+  folly::Expected<NoSelfAssign, int> e {NoSelfAssign{}};
+  e = e; // @nolint
+  e = std::move(e); // @nolint
+}
+
+#ifdef __GNUC__
+#pragma GCC diagnostic pop
+#endif
+
 struct NoDestructor {};
 
 struct WithDestructor {