mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-01-06 19:19:44 +03: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
Notes:
sideshowbarker
2024-07-17 04:49:48 +09:00
Author: https://github.com/timschumi Commit: https://github.com/SerenityOS/serenity/commit/5f806ec53a Pull-request: https://github.com/SerenityOS/serenity/pull/18196 Reviewed-by: https://github.com/fdellwing ✅ Reviewed-by: https://github.com/gmta ✅
@ -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…
Reference in New Issue
Block a user