Skip to content

Commit

Permalink
AK+Userland: Move AK/TestSuite.h into LibTest and rework Tests' CMake
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ADKaster authored and awesomekling committed Apr 25, 2021
1 parent 89ee38f commit 35c0a6c
Show file tree
Hide file tree
Showing 94 changed files with 522 additions and 579 deletions.
319 changes: 0 additions & 319 deletions AK/TestSuite.h

This file was deleted.

5 changes: 1 addition & 4 deletions AK/Tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,7 @@ set(AK_TEST_SOURCES
)

foreach(source ${AK_TEST_SOURCES})
get_filename_component(name ${source} NAME_WE)
add_executable(${name} ${source})
target_link_libraries(${name} LibCore)
install(TARGETS ${name} RUNTIME DESTINATION usr/Tests/AK)
serenity_test(${source} AK)
endforeach()

get_filename_component(TEST_FRM_RESOLVED ./test.frm REALPATH)
Expand Down
4 changes: 1 addition & 3 deletions AK/Tests/TestAllOf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <AK/TestSuite.h>
#include <LibTest/TestCase.h>

#include <AK/AllOf.h>
#include <AK/Array.h>
Expand All @@ -19,5 +19,3 @@ TEST_CASE(should_determine_if_predicate_applies_to_all_elements_in_container)
EXPECT(all_of(a.begin(), a.end(), [](auto elem) { return elem == 0; }));
EXPECT(!all_of(a.begin(), a.end(), [](auto elem) { return elem == 1; }));
}

TEST_MAIN(AllOf)
4 changes: 1 addition & 3 deletions AK/Tests/TestAnyOf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <AK/TestSuite.h>
#include <LibTest/TestCase.h>

#include <AK/AnyOf.h>
#include <AK/Array.h>
Expand All @@ -21,5 +21,3 @@ TEST_CASE(should_determine_if_predicate_applies_to_any_element_in_container)
EXPECT(any_of(a.begin(), a.end(), [](auto elem) { return elem == 1; }));
EXPECT(!any_of(a.begin(), a.end(), [](auto elem) { return elem == 2; }));
}

TEST_MAIN(AllOf)
4 changes: 1 addition & 3 deletions AK/Tests/TestArray.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <AK/TestSuite.h>
#include <LibTest/TestCase.h>

#include <AK/Array.h>

Expand All @@ -28,5 +28,3 @@ TEST_CASE(compile_time_iterable)
constexpr Array<int, 8> array = { 0, 1, 2, 3, 4, 5, 6, 7 };
static_assert(constexpr_sum(array) == 28);
}

TEST_MAIN(Array)
4 changes: 1 addition & 3 deletions AK/Tests/TestAtomic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/

#include <AK/TestSuite.h>
#include <LibTest/TestCase.h>

#include <AK/Atomic.h>

Expand Down Expand Up @@ -340,5 +340,3 @@ TEST_CASE(fetch_xor)
a_u8 = 0xe2;
EXPECT((a_u8 ^= 0xef) == 0x0d);
}

TEST_MAIN(Atomic)
Loading

0 comments on commit 35c0a6c

Please sign in to comment.