From 35c0a6c54d4e67f0d600044ed8eae0ae5e5adfba Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Sat, 24 Apr 2021 23:53:23 -0600 Subject: AK+Userland: Move AK/TestSuite.h into LibTest and rework Tests' CMake 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. --- Userland/Libraries/LibSQL/Tests/CMakeLists.txt | 5 +---- Userland/Libraries/LibSQL/Tests/TestSqlExpressionParser.cpp | 4 +--- Userland/Libraries/LibSQL/Tests/TestSqlStatementParser.cpp | 4 +--- 3 files changed, 3 insertions(+), 10 deletions(-) (limited to 'Userland/Libraries/LibSQL') diff --git a/Userland/Libraries/LibSQL/Tests/CMakeLists.txt b/Userland/Libraries/LibSQL/Tests/CMakeLists.txt index b028333c61..f002a1e864 100644 --- a/Userland/Libraries/LibSQL/Tests/CMakeLists.txt +++ b/Userland/Libraries/LibSQL/Tests/CMakeLists.txt @@ -1,8 +1,5 @@ file(GLOB TEST_SOURCES CONFIGURE_DEPENDS "*.cpp") foreach(source ${TEST_SOURCES}) - get_filename_component(name ${source} NAME_WE) - add_executable(${name} ${source}) - target_link_libraries(${name} LibSQL) - install(TARGETS ${name} RUNTIME DESTINATION usr/Tests/LibSQL) + serenity_test(${source} LibSQL LIBS LibSQL) endforeach() diff --git a/Userland/Libraries/LibSQL/Tests/TestSqlExpressionParser.cpp b/Userland/Libraries/LibSQL/Tests/TestSqlExpressionParser.cpp index a3d2e6d32f..c2a6b3bfd7 100644 --- a/Userland/Libraries/LibSQL/Tests/TestSqlExpressionParser.cpp +++ b/Userland/Libraries/LibSQL/Tests/TestSqlExpressionParser.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include #include @@ -602,5 +602,3 @@ TEST_CASE(in_selection_expression) validate("15 IN (SELECT * FROM table)", false); validate("15 NOT IN (SELECT * FROM table)", true); } - -TEST_MAIN(SqlExpressionParser) diff --git a/Userland/Libraries/LibSQL/Tests/TestSqlStatementParser.cpp b/Userland/Libraries/LibSQL/Tests/TestSqlStatementParser.cpp index 7438311bdc..0126a85e4e 100644 --- a/Userland/Libraries/LibSQL/Tests/TestSqlStatementParser.cpp +++ b/Userland/Libraries/LibSQL/Tests/TestSqlStatementParser.cpp @@ -4,7 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ -#include +#include #include #include @@ -735,5 +735,3 @@ TEST_CASE(common_table_expression) validate("WITH table (column1, column2) AS (SELECT * FROM table) DELETE FROM table;", { false, { { "table", { "column1", "column2" } } } }); validate("WITH RECURSIVE table AS (SELECT * FROM table) DELETE FROM table;", { true, { { "table", {} } } }); } - -TEST_MAIN(SqlStatementParser) -- cgit v1.2.3