define SKIP_IF
authorJim Meyering <meyering@fb.com>
Tue, 16 Jan 2018 17:32:45 +0000 (09:32 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Tue, 16 Jan 2018 17:37:12 +0000 (09:37 -0800)
Summary:
Finding ourselves writing too many identical "if (expr) SKIP << ..." statements,
this change factors out/encapsulates the functionality.

Reviewed By: yfeldblum

Differential Revision: D6727531

fbshipit-source-id: 703abcd5d8c30a6ebab94327a12da4f2d1f7ff74

folly/test/TestUtils.h

index 6eb7a0b9d048324aa02012ee76ab81e5495cf581..62085ff8c23d65852c438c352734dc85567e17e6 100644 (file)
@@ -19,7 +19,7 @@
 /*
  * This file contains additional gtest-style check macros to use in unit tests.
  *
- * - SKIP()
+ * - SKIP(), SKIP_IF(EXPR)
  * - EXPECT_THROW_RE(), ASSERT_THROW_RE()
  * - EXPECT_THROW_ERRNO(), ASSERT_THROW_ERRNO()
  * - AreWithinSecs()
 // interprets the message.
 #define SKIP() GTEST_FATAL_FAILURE_("Test skipped by client")
 
+// Encapsulate conditional-skip, since it's nontrivial to get right.
+#define SKIP_IF(expr)           \
+  GTEST_AMBIGUOUS_ELSE_BLOCKER_ \
+  if (!(expr)) {                \
+  } else                        \
+    SKIP()
+
 #define TEST_THROW_ERRNO_(statement, errnoValue, fail)       \
   GTEST_AMBIGUOUS_ELSE_BLOCKER_                              \
   if (::folly::test::detail::CheckResult gtest_result =      \