diff options
author | Michel Hermier <michel.hermier@gmail.com> | 2021-12-15 08:58:40 +0100 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2021-12-19 14:22:06 -0800 |
commit | c8cabd433a582a259368c60c59bfcaad6ff6e038 (patch) | |
tree | d02c8e7555aa15ca4f3ddc892f9a48030109a054 /Userland/Libraries | |
parent | c22c1900c0e4cb9d1e55b920854ad9e68b2422f4 (diff) | |
download | serenity-c8cabd433a582a259368c60c59bfcaad6ff6e038.zip |
LibTest: Handle Crash printing in a private method
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibTest/CrashTest.cpp | 39 | ||||
-rw-r--r-- | Userland/Libraries/LibTest/CrashTest.h | 2 |
2 files changed, 21 insertions, 20 deletions
diff --git a/Userland/Libraries/LibTest/CrashTest.cpp b/Userland/Libraries/LibTest/CrashTest.cpp index bcb7b83f1a..aff77990bf 100644 --- a/Userland/Libraries/LibTest/CrashTest.cpp +++ b/Userland/Libraries/LibTest/CrashTest.cpp @@ -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; +} + } diff --git a/Userland/Libraries/LibTest/CrashTest.h b/Userland/Libraries/LibTest/CrashTest.h index f7dbf1f217..46e5e858e0 100644 --- a/Userland/Libraries/LibTest/CrashTest.h +++ b/Userland/Libraries/LibTest/CrashTest.h @@ -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; }; |