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:
parent
7e28ecc305
commit
7f51754780
3 changed files with 22 additions and 6 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue