[libc-commits] [libc] 7f65892 - [libc] Add [EXPECT|ASSERT]_[TRUE|FALSE] unittest macros.
Siva Chandra Reddy via libc-commits
libc-commits at lists.llvm.org
Thu Jan 30 12:05:10 PST 2020
Author: Siva Chandra Reddy
Date: 2020-01-30T11:59:31-08:00
New Revision: 7f658920863bb96adc973a586cac50d9f8ad940b
URL: https://github.com/llvm/llvm-project/commit/7f658920863bb96adc973a586cac50d9f8ad940b
DIFF: https://github.com/llvm/llvm-project/commit/7f658920863bb96adc973a586cac50d9f8ad940b.diff
LOG: [libc] Add [EXPECT|ASSERT]_[TRUE|FALSE] unittest macros.
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
Added:
Modified:
libc/utils/CPP/TypeTraits.h
libc/utils/UnitTest/Test.cpp
libc/utils/UnitTest/Test.h
Removed:
################################################################################
diff --git a/libc/utils/CPP/TypeTraits.h b/libc/utils/CPP/TypeTraits.h
index 9f5576259540..3804d1d53f7e 100644
--- a/libc/utils/CPP/TypeTraits.h
+++ b/libc/utils/CPP/TypeTraits.h
@@ -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 {};
diff --git a/libc/utils/UnitTest/Test.cpp b/libc/utils/UnitTest/Test.cpp
index 1532922e9d4c..032bf2cadca9 100644
--- a/libc/utils/UnitTest/Test.cpp
+++ b/libc/utils/UnitTest/Test.cpp
@@ -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,
diff --git a/libc/utils/UnitTest/Test.h b/libc/utils/UnitTest/Test.h
index fc1002a56453..cb7963e86729 100644
--- a/libc/utils/UnitTest/Test.h
+++ b/libc/utils/UnitTest/Test.h
@@ -63,9 +63,8 @@ class Test {
// 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 @@ class Test {
#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
More information about the libc-commits
mailing list