From 7f658920863bb96adc973a586cac50d9f8ad940b Mon Sep 17 00:00:00 2001 From: Siva Chandra Reddy Date: Wed, 29 Jan 2020 15:07:29 -0800 Subject: [PATCH] [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 --- libc/utils/CPP/TypeTraits.h | 3 --- libc/utils/UnitTest/Test.cpp | 5 +++++ libc/utils/UnitTest/Test.h | 17 ++++++++++++++--- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/libc/utils/CPP/TypeTraits.h b/libc/utils/CPP/TypeTraits.h index 9f55762..3804d1d 100644 --- a/libc/utils/CPP/TypeTraits.h +++ b/libc/utils/CPP/TypeTraits.h @@ -37,9 +37,6 @@ template <> struct IsIntegral : public TrueValue {}; template <> struct IsIntegral : public TrueValue {}; template <> struct IsIntegral : public TrueValue {}; -template struct IsIntegralNotBool : public IsIntegral {}; -template <> struct IsIntegralNotBool : public FalseValue {}; - template struct IsPointerType : public FalseValue {}; template struct IsPointerType : public TrueValue {}; diff --git a/libc/utils/UnitTest/Test.cpp b/libc/utils/UnitTest/Test.cpp index 1532922..032bf2c 100644 --- a/libc/utils/UnitTest/Test.cpp +++ b/libc/utils/UnitTest/Test.cpp @@ -204,6 +204,11 @@ template bool Test::test(RunContext &Ctx, TestCondition Cond, const char *RHSStr, const char *File, unsigned long Line); +template bool Test::test(RunContext &Ctx, TestCondition Cond, bool LHS, + bool RHS, const char *LHSStr, + const char *RHSStr, const char *File, + unsigned long Line); + template bool Test::test( 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 fc1002a..cb7963e 100644 --- a/libc/utils/UnitTest/Test.h +++ b/libc/utils/UnitTest/Test.h @@ -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::Value, ValType> = 0> + template ::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 -- 2.7.4