diff --git a/Userland/Libraries/LibTest/Macros.h b/Userland/Libraries/LibTest/Macros.h index 004154ee3e7..5f2f3cdd243 100644 --- a/Userland/Libraries/LibTest/Macros.h +++ b/Userland/Libraries/LibTest/Macros.h @@ -109,6 +109,25 @@ void disable_reporting(); #define EXPECT_APPROXIMATE(a, b) EXPECT_APPROXIMATE_WITH_ERROR(a, b, 0.0000005) +#define REJECT(message) \ + do { \ + if (::Test::is_reporting_enabled()) \ + ::AK::warnln("\033[31;1mREJECTED\033[0m: {}:{}: {}", \ + __FILE__, __LINE__, #message); \ + ::Test::set_current_test_result(::Test::TestResult::Rejected); \ + } while (false) + +#define ASSUME(x) \ + do { \ + if (!(x)) { \ + if (::Test::is_reporting_enabled()) \ + ::AK::warnln("\033[31;1mREJECTED\033[0m: {}:{}: Couldn't generate random value satisfying ASSUME({})", \ + __FILE__, __LINE__, #x); \ + ::Test::set_current_test_result(::Test::TestResult::Rejected); \ + return; \ + } \ + } while (false) + #define FAIL(message) \ do { \ if (::Test::is_reporting_enabled()) \ diff --git a/Userland/Libraries/LibTest/TestResult.h b/Userland/Libraries/LibTest/TestResult.h index d63b763800f..513a60e5d57 100644 --- a/Userland/Libraries/LibTest/TestResult.h +++ b/Userland/Libraries/LibTest/TestResult.h @@ -18,6 +18,11 @@ enum class TestResult { // Didn't get through EXPECT(...). Failed, + // Didn't get through the ASSUME(...) filter 15 times in a row + // (in a randomized test). + // Alternatively, user used REJECT(...). + Rejected, + // Ran out of RandomRun data (in a randomized test, when shrinking). // This is fine, we'll just try some other shrink. Overrun, diff --git a/Userland/Libraries/LibTest/TestSuite.cpp b/Userland/Libraries/LibTest/TestSuite.cpp index 76076de110b..53cd499932c 100644 --- a/Userland/Libraries/LibTest/TestSuite.cpp +++ b/Userland/Libraries/LibTest/TestSuite.cpp @@ -103,6 +103,8 @@ static DeprecatedString test_result_to_string(TestResult result) return "Completed"; case TestResult::Failed: return "Failed"; + case TestResult::Rejected: + return "Rejected"; case TestResult::Overrun: return "Ran out of randomness"; default: