diff options
author | Tim Schumacher <timschumi@gmx.de> | 2021-10-23 02:49:13 +0200 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-10-24 22:40:11 -0700 |
commit | 338f80cbf6588354f23756ceb63aab55846c4541 (patch) | |
tree | 17a26a86aff87770e4dcf40dc49ae102ef4ec5f7 /Userland/Libraries/LibTest/Macros.h | |
parent | 9e3e4a692dc94f7dc9f925038156b59816aa03c1 (diff) | |
download | serenity-338f80cbf6588354f23756ceb63aab55846c4541.zip |
LibTest: Introduce a macro to only compare truthiness
Diffstat (limited to 'Userland/Libraries/LibTest/Macros.h')
-rw-r--r-- | Userland/Libraries/LibTest/Macros.h | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Userland/Libraries/LibTest/Macros.h b/Userland/Libraries/LibTest/Macros.h index 9c084e46a3..d883da655f 100644 --- a/Userland/Libraries/LibTest/Macros.h +++ b/Userland/Libraries/LibTest/Macros.h @@ -55,6 +55,19 @@ void current_test_case_did_fail(); } \ } while (false) +#define EXPECT_EQ_TRUTH(a, b) \ + do { \ + auto lhs = (a); \ + auto rhs = (b); \ + bool ltruth = static_cast<bool>(lhs); \ + bool rtruth = static_cast<bool>(rhs); \ + if (ltruth != rtruth) { \ + ::AK::warnln("\033[31;1mFAIL\033[0m: {}:{}: EXPECT_EQ_TRUTH({}, {}) failed with lhs={} ({}) and rhs={} ({})", \ + __FILE__, __LINE__, #a, #b, FormatIfSupported { lhs }, ltruth, FormatIfSupported { rhs }, rtruth); \ + ::Test::current_test_case_did_fail(); \ + } \ + } while (false) + // If you're stuck and `EXPECT_EQ` seems to refuse to print anything useful, // try this: It'll spit out a nice compiler error telling you why it doesn't print. #define EXPECT_EQ_FORCE(a, b) \ |