mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 18:57:35 +00:00
LibTest: Add a TRY_OR_FAIL
macro
This macro has the usual `TRY` semantics, but instead of returning the error, it will let the test fail with the formatted error as the fail message.
This commit is contained in:
parent
bfffe88de5
commit
5f806ec53a
1 changed files with 14 additions and 0 deletions
|
@ -141,3 +141,17 @@ void current_test_case_did_fail();
|
|||
if (!crash.run()) \
|
||||
::Test::current_test_case_did_fail(); \
|
||||
} while (false)
|
||||
|
||||
#define TRY_OR_FAIL(expression) \
|
||||
({ \
|
||||
/* Ignore -Wshadow to allow nesting the macro. */ \
|
||||
AK_IGNORE_DIAGNOSTIC("-Wshadow", \
|
||||
auto&& _temporary_result = (expression)); \
|
||||
static_assert(!::AK::Detail::IsLvalueReference<decltype(_temporary_result.release_value())>, \
|
||||
"Do not return a reference from a fallible expression"); \
|
||||
if (_temporary_result.is_error()) [[unlikely]] { \
|
||||
FAIL(_temporary_result.release_error()); \
|
||||
return; \
|
||||
} \
|
||||
_temporary_result.release_value(); \
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue