Elffuss BraidHub

kikocis/kleidiai public

main · 1.5 KiBRawPermalink
1//
2// SPDX-FileCopyrightText: Copyright 2025 Arm Limited and/or its affiliates <open-source-office@arm.com>
3//
4// SPDX-License-Identifier: Apache-2.0
5//
6
7#pragma once
8
9#include <functional>
10#include <utility>
11
12namespace kai::test {
13
14#define KAI_REGISTER_TEST(test_suite_type, test_type, test_suite_name, test_name, ...) \
15 testing::RegisterTest( \
16 test_suite_name, test_name, nullptr, nullptr, __FILE__, __LINE__, \
17 [=]() -> test_suite_type* { return new test_type(__VA_ARGS__); });
18
19/// A facility to register functions that are called before the main function
20/// to setup the list of tests.
21///
22/// Example:
23///
24/// ```
25/// static auto a_register_function = TestRegistry::register_setup([]() {
26/// // Setups the list of tests.
27/// });
28/// ```
29class TestRegistry {
30public:
31 using Fn = std::function<void()>;
32
33private:
34 class Handle {
35 friend class TestRegistry;
36
37 private:
38 explicit Handle(Fn&& fn);
39 };
40
41public:
42 /// Registers a function to be called in the main function to setup the list of tests.
43 ///
44 /// The return value of this function must be kept as a static variable.
45 ///
46 /// @param[in] fn The function to be called.
47 [[nodiscard]] static TestRegistry::Handle register_setup(Fn&& fn) {
48 return TestRegistry::Handle(std::move(fn));
49 }
50
51 /// Runs all functions registered to be called in the main function to setup the list of tests.
52 static void init();
53};
54
55} // namespace kai::test