1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 17:07:34 +00:00

LibTest: Expose new EXPECT_CRASH(..) macro for unit test assertions

Utilize the Crash type we imported into LibTest to support testing
of crash scenarios when testing all other components.
This commit is contained in:
Brian Gianforcaro 2021-05-07 04:38:56 -07:00 committed by Linus Groh
parent 7e28ecc305
commit 7f51754780
3 changed files with 22 additions and 6 deletions

View file

@ -9,6 +9,7 @@
#include <AK/Assertions.h>
#include <AK/CheckedFormatString.h>
#include <LibTest/CrashTest.h>
namespace AK {
template<typename... Parameters>
@ -101,3 +102,14 @@ void current_test_case_did_fail();
::AK::warnln("\033[31;1mFAIL\033[0m: {}:{}: {}", __FILE__, __LINE__, message); \
::Test::current_test_case_did_fail(); \
} while (false)
// To use, specify the lambda to execute in a sub process and verify it exits:
// EXPECT_CRASH("This should fail", []{
// return Test::Crash::Failure::DidNotCrash;
// });
#define EXPECT_CRASH(test_message, test_func) \
do { \
Test::Crash crash(test_message, test_func); \
if (!crash.run()) \
::Test::current_test_case_did_fail(); \
} while (false)