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

LibTest: Add ability to turn test failure reporting on/off

This will be very useful as we add the randomized test cases and their
two loops ("generate+test many times" and "shrink once failure is
found"), because without this failure reporting we'd get many FAIL error
messages while still searching for the minimal one.

So, inside randomized test cases we want to only turn the error
reporting on for one last time after all the generating and shrinking.
This commit is contained in:
Martin Janiczek 2023-10-24 01:26:28 +02:00 committed by Andrew Kaster
parent 99e2d42a53
commit 1bcfead020
3 changed files with 90 additions and 48 deletions

View file

@ -76,6 +76,24 @@ void set_suite_setup_function(Function<void()> setup)
TestSuite::the().set_suite_setup(move(setup));
}
// Declared in Macros.h
bool is_reporting_enabled()
{
return TestSuite::the().is_reporting_enabled();
}
// Declared in Macros.h
void enable_reporting()
{
TestSuite::the().enable_reporting();
}
// Declared in Macros.h
void disable_reporting()
{
TestSuite::the().disable_reporting();
}
static DeprecatedString test_result_to_string(TestResult result)
{
switch (result) {
@ -164,6 +182,7 @@ int TestSuite::run(Vector<NonnullRefPtr<TestCase>> const& tests)
warnln("Running {} '{}'.", test_type, t->name());
m_current_test_result = TestResult::NotRun;
enable_reporting();
u64 total_time = 0;
u64 sum_of_squared_times = 0;