[libc] Add [EXPECT|ASSERT]_[TRUE|FALSE] unittest macros.
authorSiva Chandra Reddy <sivachandra@google.com>
Wed, 29 Jan 2020 23:07:29 +0000 (15:07 -0800)
committerSiva Chandra Reddy <sivachandra@google.com>
Thu, 30 Jan 2020 19:59:31 +0000 (11:59 -0800)
Also, other EXPECT_* and ASSERT_* macros have been extended to accept
bool values.

Reviewers: abrachet, gchatelet

Subscribers: MaskRay, tschuett, libc-commits

Tags: #libc-project

Differential Revision: https://reviews.llvm.org/D73668

libc/utils/CPP/TypeTraits.h
libc/utils/UnitTest/Test.cpp
libc/utils/UnitTest/Test.h

index 9f55762..3804d1d 100644 (file)
@@ -37,9 +37,6 @@ template <> struct IsIntegral<long long> : public TrueValue {};
 template <> struct IsIntegral<unsigned long long> : public TrueValue {};
 template <> struct IsIntegral<bool> : public TrueValue {};
 
-template <typename Type> struct IsIntegralNotBool : public IsIntegral<Type> {};
-template <> struct IsIntegralNotBool<bool> : public FalseValue {};
-
 template <typename T> struct IsPointerType : public FalseValue {};
 template <typename T> struct IsPointerType<T *> : public TrueValue {};
 
index 1532922..032bf2c 100644 (file)
@@ -204,6 +204,11 @@ template bool Test::test<unsigned long, 0>(RunContext &Ctx, TestCondition Cond,
                                            const char *RHSStr, const char *File,
                                            unsigned long Line);
 
+template bool Test::test<bool, 0>(RunContext &Ctx, TestCondition Cond, bool LHS,
+                                  bool RHS, const char *LHSStr,
+                                  const char *RHSStr, const char *File,
+                                  unsigned long Line);
+
 template bool Test::test<unsigned long long, 0>(
     RunContext &Ctx, TestCondition Cond, unsigned long long LHS,
     unsigned long long RHS, const char *LHSStr, const char *RHSStr,
index fc1002a..cb7963e 100644 (file)
@@ -63,9 +63,8 @@ protected:
   // is the result of the |Cond| operation on |LHS| and |RHS|. Though not bad,
   // |Cond| on mismatched |LHS| and |RHS| types can potentially succeed because
   // of type promotion.
-  template <
-      typename ValType,
-      cpp::EnableIfType<cpp::IsIntegralNotBool<ValType>::Value, ValType> = 0>
+  template <typename ValType,
+            cpp::EnableIfType<cpp::IsIntegral<ValType>::Value, ValType> = 0>
   static bool test(RunContext &Ctx, TestCondition Cond, ValType LHS,
                    ValType RHS, const char *LHSStr, const char *RHSStr,
                    const char *File, unsigned long Line) {
@@ -176,3 +175,15 @@ private:
 #define ASSERT_STRNE(LHS, RHS)                                                 \
   if (!EXPECT_STRNE(LHS, RHS))                                                 \
   return
+
+#define EXPECT_TRUE(VAL) EXPECT_EQ((VAL), true)
+
+#define ASSERT_TRUE(VAL)                                                       \
+  if (!EXPECT_TRUE(VAL))                                                       \
+  return
+
+#define EXPECT_FALSE(VAL) EXPECT_EQ((VAL), false)
+
+#define ASSERT_FALSE(VAL)                                                      \
+  if (!EXPECT_FALSE(VAL))                                                      \
+  return