1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:07:45 +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

@ -53,6 +53,14 @@ public:
void set_randomness_source(Randomized::RandomnessSource source) { m_randomness_source = move(source); }
Randomized::RandomnessSource& randomness_source() { return m_randomness_source; }
// Dictates whether FAIL(), EXPECT() and similar macros in LibTest/Macros.h
// print messages or not. This is important for randomized tests because
// they run the test function many times in a row, and we only want to
// report the _minimal_ (shrunk) failure to the user, not all of them.
bool is_reporting_enabled() { return m_reporting_enabled; }
void enable_reporting() { m_reporting_enabled = true; }
void disable_reporting() { m_reporting_enabled = false; }
private:
static TestSuite* s_global;
Vector<NonnullRefPtr<TestCase>> m_cases;
@ -63,6 +71,7 @@ private:
Function<void()> m_setup;
TestResult m_current_test_result = TestResult::NotRun;
Randomized::RandomnessSource m_randomness_source = Randomized::RandomnessSource::live();
bool m_reporting_enabled = true;
};
}