diff --git a/Userland/Libraries/LibTest/CrashTest.cpp b/Userland/Libraries/LibTest/CrashTest.cpp index 2610c10c98..c002bec148 100644 --- a/Userland/Libraries/LibTest/CrashTest.cpp +++ b/Userland/Libraries/LibTest/CrashTest.cpp @@ -49,28 +49,39 @@ bool Crash::run(RunType run_type) return do_report(Failure(WEXITSTATUS(status))); } if (WIFSIGNALED(status)) { - outln("\x1B[32mPASS\x1B[0m: Terminated with signal {}", WTERMSIG(status)); - return true; + return do_report(WTERMSIG(status)); } VERIFY_NOT_REACHED(); } } -bool Crash::do_report(Failure failure) +bool Crash::do_report(Report report) { - // If we got here something went wrong - out("\x1B[31mFAIL\x1B[0m: "); - switch (failure) { - case Failure::DidNotCrash: - outln("Did not crash!"); - break; - case Failure::UnexpectedError: - outln("Unexpected error!"); - break; - default: - VERIFY_NOT_REACHED(); - } - return false; + const bool pass = report.has(); + + if (pass) + out("\x1B[32mPASS\x1B[0m: "); + else + out("\x1B[31mFAIL\x1B[0m: "); + + report.visit( + [&](const Failure& failure) { + switch (failure) { + case Failure::DidNotCrash: + outln("Did not crash!"); + break; + case Failure::UnexpectedError: + outln("Unexpected error!"); + break; + default: + VERIFY_NOT_REACHED(); + } + }, + [&](const int& signal) { + outln("Terminated with signal {}", signal); + }); + + return pass; } } diff --git a/Userland/Libraries/LibTest/CrashTest.h b/Userland/Libraries/LibTest/CrashTest.h index 46e5e858e0..994b4060e4 100644 --- a/Userland/Libraries/LibTest/CrashTest.h +++ b/Userland/Libraries/LibTest/CrashTest.h @@ -10,6 +10,7 @@ #include #include +#include namespace Test { @@ -30,7 +31,8 @@ public: bool run(RunType run_type = RunType::UsingChildProcess); private: - bool do_report(Failure failure); + using Report = Variant; + bool do_report(Report report); String m_type; Function m_crash_function;