mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-29 08:11:13 +00:00
LibTest: Add EXPECT_NO_CRASH
This commit is contained in:
parent
4c6e826c05
commit
7a44c11378
Notes:
sideshowbarker
2024-07-17 22:34:46 +09:00
Author: https://github.com/mhermier Commit: https://github.com/SerenityOS/serenity/commit/7a44c11378b Pull-request: https://github.com/SerenityOS/serenity/pull/11291
|
@ -14,6 +14,7 @@ add_subdirectory(LibMarkdown)
|
||||||
add_subdirectory(LibPthread)
|
add_subdirectory(LibPthread)
|
||||||
add_subdirectory(LibRegex)
|
add_subdirectory(LibRegex)
|
||||||
add_subdirectory(LibSQL)
|
add_subdirectory(LibSQL)
|
||||||
|
add_subdirectory(LibTest)
|
||||||
add_subdirectory(LibThreading)
|
add_subdirectory(LibThreading)
|
||||||
add_subdirectory(LibUnicode)
|
add_subdirectory(LibUnicode)
|
||||||
add_subdirectory(LibWasm)
|
add_subdirectory(LibWasm)
|
||||||
|
|
7
Tests/LibTest/CMakeLists.txt
Normal file
7
Tests/LibTest/CMakeLists.txt
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
set(TEST_SOURCES
|
||||||
|
TestNoCrash.cpp
|
||||||
|
)
|
||||||
|
|
||||||
|
foreach(source IN LISTS TEST_SOURCES)
|
||||||
|
serenity_test("${source}" LibSQL LIBS LibSQL LibIPC)
|
||||||
|
endforeach()
|
14
Tests/LibTest/TestNoCrash.cpp
Normal file
14
Tests/LibTest/TestNoCrash.cpp
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2021, the SerenityOS developers.
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <LibTest/TestCase.h>
|
||||||
|
|
||||||
|
TEST_CASE(raise)
|
||||||
|
{
|
||||||
|
EXPECT_NO_CRASH("This should never crash", [] {
|
||||||
|
return Test::Crash::Failure::DidNotCrash;
|
||||||
|
});
|
||||||
|
}
|
|
@ -64,6 +64,8 @@ bool Crash::do_report(Report report)
|
||||||
bool pass = false;
|
bool pass = false;
|
||||||
if (m_crash_signal == ANY_SIGNAL) {
|
if (m_crash_signal == ANY_SIGNAL) {
|
||||||
pass = report.has<int>();
|
pass = report.has<int>();
|
||||||
|
} else if (m_crash_signal == 0) {
|
||||||
|
pass = report.has<Failure>() && report.get<Failure>() == Failure::DidNotCrash;
|
||||||
} else if (m_crash_signal > 0) {
|
} else if (m_crash_signal > 0) {
|
||||||
pass = report.has<int>() && report.get<int>() == m_crash_signal;
|
pass = report.has<int>() && report.get<int>() == m_crash_signal;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -134,3 +134,10 @@ void current_test_case_did_fail();
|
||||||
if (!crash.run()) \
|
if (!crash.run()) \
|
||||||
::Test::current_test_case_did_fail(); \
|
::Test::current_test_case_did_fail(); \
|
||||||
} while (false)
|
} while (false)
|
||||||
|
|
||||||
|
#define EXPECT_NO_CRASH(test_message, test_func) \
|
||||||
|
do { \
|
||||||
|
Test::Crash crash(test_message, test_func, 0); \
|
||||||
|
if (!crash.run()) \
|
||||||
|
::Test::current_test_case_did_fail(); \
|
||||||
|
} while (false)
|
||||||
|
|
Loading…
Reference in a new issue