diff --git a/libc/utils/CPP/TypeTraits.h b/libc/utils/CPP/TypeTraits.h --- a/libc/utils/CPP/TypeTraits.h +++ b/libc/utils/CPP/TypeTraits.h @@ -40,6 +40,9 @@ template struct IsIntegralNotBool : public IsIntegral {}; template <> struct IsIntegralNotBool : public FalseValue {}; +template struct IsBool : public FalseValue {}; +template <> struct IsBool : public TrueValue {}; + template struct IsPointerType : public FalseValue {}; template struct IsPointerType : public TrueValue {}; diff --git a/libc/utils/UnitTest/Test.h b/libc/utils/UnitTest/Test.h --- a/libc/utils/UnitTest/Test.h +++ b/libc/utils/UnitTest/Test.h @@ -82,6 +82,15 @@ (unsigned long long)RHS, LHSStr, RHSStr, File, Line); } + // Restricting the ValType to bool ensures that only values of type bool + // are used with [EXPECT|ASSERT]_[TRUE|FALSE]. + template ::Value, ValType> = true> + static bool testTrue(RunContext &Ctx, ValType Val, const char *ValStr, + const char *File, unsigned long Line) { + return Val; + } + static bool testStrEq(RunContext &Ctx, const char *LHS, const char *RHS, const char *LHSStr, const char *RHSStr, const char *File, unsigned long Line); @@ -176,3 +185,17 @@ #define ASSERT_STRNE(LHS, RHS) \ if (!EXPECT_STRNE(LHS, RHS)) \ return + +#define EXPECT_TRUE(VAL) \ + __llvm_libc::testing::Test::testTrue(Ctx, (VAL), #VAL, __FILE__, __LINE__) + +#define ASSERT_TRUE(VAL) \ + if (!EXPECT_TRUE(VAL)) \ + return + +#define EXPECT_FALSE(VAL) \ + __llvm_libc::testing::Test::testTrue(Ctx, !(VAL), #VAL, __FILE__, __LINE__) + +#define ASSERT_FALSE(VAL) \ + if (!EXPECT_FALSE(VAL)) \ + return