[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
This commit is contained in:
Siva Chandra Reddy 2020-01-29 15:07:29 -08:00
parent 389b126210
commit 7f65892086
3 changed files with 19 additions and 6 deletions

View 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 {};

View 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,

View 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