mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-29 02:50:26 +00:00
35c0a6c54d
As many macros as possible are moved to Macros.h, while the macros to create a test case are moved to TestCase.h. TestCase is now the only user-facing header for creating a test case. TestSuite and its helpers have moved into a .cpp file. Instead of requiring a TEST_MAIN macro to be instantiated into the test file, a TestMain.cpp file is provided instead that will be linked against each test. This has the side effect that, if we wanted to have test cases split across multiple files, it's as simple as adding them all to the same executable. The test main should be portable to kernel mode as well, so if there's a set of tests that should be run in self-test mode in kernel space, we can accomodate that. A new serenity_test CMake function streamlines adding a new test with arguments for the test source file, subdirectory under /usr/Tests to install the test application and an optional list of libraries to link against the test application. To accomodate future test where the provided TestMain.cpp is not suitable (e.g. test-js), a CUSTOM_MAIN parameter can be passed to the function to not link against the boilerplate main function.
28 lines
647 B
C++
28 lines
647 B
C++
/*
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
* Copyright (c) 2021, Andrew Kaster <akaster@serenityos.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <LibTest/TestCase.h>
|
|
|
|
#include <AK/Format.h>
|
|
#include <LibTest/TestSuite.h>
|
|
|
|
#ifdef KERNEL
|
|
# define TEST_MAIN test_main
|
|
#else
|
|
# define TEST_MAIN main
|
|
#endif
|
|
|
|
int TEST_MAIN(int argc, char** argv)
|
|
{
|
|
if (argc < 1 || !argv[0] || '\0' == *argv[0]) {
|
|
warnln("Test main does not have a valid test name!");
|
|
return 1;
|
|
}
|
|
int ret = ::Test::TestSuite::the().main(argv[0], argc, argv);
|
|
::Test::TestSuite::release();
|
|
return ret;
|
|
}
|