LibTest: Handle Crash printing in a private method
This commit is contained in:
parent
c22c1900c0
commit
c8cabd433a
Notes:
sideshowbarker
2024-07-17 22:35:03 +09:00
Author: https://github.com/mhermier Commit: https://github.com/SerenityOS/serenity/commit/c8cabd433a5 Pull-request: https://github.com/SerenityOS/serenity/pull/11291
2 changed files with 21 additions and 20 deletions
Userland/Libraries/LibTest
|
@ -27,26 +27,8 @@ bool Crash::run(RunType run_type)
|
|||
{
|
||||
outln("\x1B[33mTesting\x1B[0m: \"{}\"", m_type);
|
||||
|
||||
auto run_crash_and_print_if_error = [this]() -> bool {
|
||||
auto failure = m_crash_function();
|
||||
|
||||
// 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;
|
||||
};
|
||||
|
||||
if (run_type == RunType::UsingCurrentProcess) {
|
||||
return run_crash_and_print_if_error();
|
||||
return do_report(m_crash_function());
|
||||
} else {
|
||||
// Run the test in a child process so that we do not crash the crash program :^)
|
||||
pid_t pid = fork();
|
||||
|
@ -58,7 +40,7 @@ bool Crash::run(RunType run_type)
|
|||
if (prctl(PR_SET_DUMPABLE, 0, 0) < 0)
|
||||
perror("prctl(PR_SET_DUMPABLE)");
|
||||
#endif
|
||||
run_crash_and_print_if_error();
|
||||
return do_report(m_crash_function());
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
@ -72,4 +54,21 @@ bool Crash::run(RunType run_type)
|
|||
}
|
||||
}
|
||||
|
||||
bool Crash::do_report(Failure failure)
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -30,6 +30,8 @@ public:
|
|||
bool run(RunType run_type = RunType::UsingChildProcess);
|
||||
|
||||
private:
|
||||
bool do_report(Failure failure);
|
||||
|
||||
String m_type;
|
||||
Function<Crash::Failure()> m_crash_function;
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue