mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 10:38:13 +00:00
LibTest: Add the GEN macro
Generators are callable as-is: u32 my_int = Gen::unsigned_int(); // -> 1, 5, 8, 3, 2 But there is little visibility in the test fail message into what went wrong. Showing what values were generated helps a lot, and that's what this macro does: GEN(my_int, Gen::unsigned_int()); expands into the above declaration and (crucially) a conditional warnln() call looking like "my_int = {}". It will only run if error reporting is enabled (see Test::can_report()), so it will only give the final shrunk value instead of spamming the output with each generated value.
This commit is contained in:
parent
00934bc344
commit
ba20ddb834
1 changed files with 8 additions and 0 deletions
|
@ -82,3 +82,11 @@ void set_suite_setup_function(Function<void()> setup);
|
|||
}; \
|
||||
static struct __BENCHMARK_TYPE(x) __BENCHMARK_TYPE(x); \
|
||||
static void __BENCHMARK_FUNC(x)()
|
||||
|
||||
// This allows us to print the generated locals in the test after a failure is fully shrunk.
|
||||
#define GEN(identifier, value) \
|
||||
auto identifier = (value); \
|
||||
if (::Test::current_test_result() == ::Test::TestResult::Overrun) \
|
||||
return; \
|
||||
if (::Test::is_reporting_enabled()) \
|
||||
::AK::warnln("{} = {}", #identifier, (identifier))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue