[libc-commits] [PATCH] D73668: [libc] Add [EXPECT|ASSERT]_[TRUE|FALSE] unittest macros.

Siva Chandra via Phabricator via libc-commits libc-commits at lists.llvm.org
Thu Jan 30 11:35:22 PST 2020


sivachandra updated this revision to Diff 241530.
sivachandra added a comment.

Ready for a review.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73668/new/

https://reviews.llvm.org/D73668

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


Index: libc/utils/UnitTest/Test.h
===================================================================
--- libc/utils/UnitTest/Test.h
+++ libc/utils/UnitTest/Test.h
@@ -63,9 +63,8 @@
   // 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,19 @@
 #define ASSERT_STRNE(LHS, RHS)                                                 \
   if (!EXPECT_STRNE(LHS, RHS))                                                 \
   return
+
+#define EXPECT_TRUE(VAL)                                                       \
+  __llvm_libc::testing::Test::test(Ctx, __llvm_libc::testing::Cond_EQ, (VAL),  \
+                                   true, #VAL, "true", __FILE__, __LINE__)
+
+#define ASSERT_TRUE(VAL)                                                       \
+  if (!EXPECT_TRUE(VAL))                                                       \
+  return
+
+#define EXPECT_FALSE(VAL)                                                      \
+  __llvm_libc::testing::Test::test(Ctx, __llvm_libc::testing::Cond_EQ, (VAL),  \
+                                   false, #VAL, "false", __FILE__, __LINE__)
+
+#define ASSERT_FALSE(VAL)                                                      \
+  if (!EXPECT_FALSE(VAL))                                                      \
+  return
Index: libc/utils/UnitTest/Test.cpp
===================================================================
--- libc/utils/UnitTest/Test.cpp
+++ libc/utils/UnitTest/Test.cpp
@@ -204,6 +204,11 @@
                                            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: libc/utils/CPP/TypeTraits.h
===================================================================
--- libc/utils/CPP/TypeTraits.h
+++ libc/utils/CPP/TypeTraits.h
@@ -37,9 +37,6 @@
 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 {};
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D73668.241530.patch
Type: text/x-patch
Size: 3248 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20200130/c67801e3/attachment.bin>


More information about the libc-commits mailing list