mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 02:37:35 +00:00
LibTest: Handle Crash printing in a private method
This commit is contained in:
parent
c22c1900c0
commit
c8cabd433a
2 changed files with 21 additions and 20 deletions
|
@ -27,26 +27,8 @@ bool Crash::run(RunType run_type)
|
||||||
{
|
{
|
||||||
outln("\x1B[33mTesting\x1B[0m: \"{}\"", m_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) {
|
if (run_type == RunType::UsingCurrentProcess) {
|
||||||
return run_crash_and_print_if_error();
|
return do_report(m_crash_function());
|
||||||
} else {
|
} else {
|
||||||
// Run the test in a child process so that we do not crash the crash program :^)
|
// Run the test in a child process so that we do not crash the crash program :^)
|
||||||
pid_t pid = fork();
|
pid_t pid = fork();
|
||||||
|
@ -58,7 +40,7 @@ bool Crash::run(RunType run_type)
|
||||||
if (prctl(PR_SET_DUMPABLE, 0, 0) < 0)
|
if (prctl(PR_SET_DUMPABLE, 0, 0) < 0)
|
||||||
perror("prctl(PR_SET_DUMPABLE)");
|
perror("prctl(PR_SET_DUMPABLE)");
|
||||||
#endif
|
#endif
|
||||||
run_crash_and_print_if_error();
|
return do_report(m_crash_function());
|
||||||
exit(0);
|
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);
|
bool run(RunType run_type = RunType::UsingChildProcess);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool do_report(Failure failure);
|
||||||
|
|
||||||
String m_type;
|
String m_type;
|
||||||
Function<Crash::Failure()> m_crash_function;
|
Function<Crash::Failure()> m_crash_function;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue