11#pragma once
2-
32#include < meta>
4- #include < tuple>
5- #include < vector>
6- #include < ranges>
7-
8- #include < rsl/testing/_impl/util.hpp>
9-
10- namespace rsl ::testing {
11- namespace _testing_impl {
12- template <typename T, std::meta::info Set>
13- T param_set_to_tuple () {
14- constexpr static auto args = [:Set:];
15- return []<std::size_t ... Idx>(std::index_sequence<Idx...>) {
16- return T{[:args[Idx]:]...};
17- }(std::make_index_sequence<std::tuple_size_v<T>>{});
18- }
19-
20- template <typename T, std::meta::info Sets>
21- std::vector<T> param_generator () {
22- std::vector<T> ret;
23- template for (constexpr auto set : [:Sets:]) {
24- ret.push_back (param_set_to_tuple<T, set>());
25- }
26- return ret;
27- }
28-
29- struct TestInstance {
30- char const * name;
31- std::meta::info fnc;
32- };
333
34- consteval std::string stringify_targs (std::span<std::meta::info const > args) {
35- std::string result = " <" ;
36- for (std::size_t i = 0 ; i < args.size (); ++i) {
37- if (i != 0 ) {
38- result += " , " ;
39- }
40- result += display_string_of (args[i]);
41- }
42- result += " >" ;
43- return result;
44- }
45-
46- template <std::meta::info Sets>
47- constexpr std::vector<TestInstance> tparam_generator (std::meta::info fnc) {
48- std::vector<TestInstance> ret;
49- auto base_name = identifier_of (fnc);
50- template for (constexpr auto set : [:Sets:]) {
51- auto name = base_name + stringify_targs ([:set:]);
52- auto instance = substitute (get_operator (fnc, std::meta::operators::op_parentheses), [:set:]);
53- ret.emplace_back (define_static_string (name), instance);
54- }
55- return ret;
56- }
57-
58- template <typename ... Ts>
59- consteval std::meta::info reflect_tuple (std::tuple<Ts...> const & tup,
60- bool reflect_reflections = true ) {
61- std::array<std::meta::info, sizeof ...(Ts)> reflected_element;
62- template for (constexpr auto Idx : std::views::iota (0zu, sizeof ...(Ts))) {
63- if constexpr (std::same_as<Ts...[Idx], std::meta::info>) {
64- // effectively disallows std::meta::info CTPs for tests, but allows passing
65- // types etc as reflections
66- if (!reflect_reflections) {
67- reflected_element[Idx] = get<Idx>(tup);
68- continue ;
69- }
70- }
71- if constexpr (std::convertible_to<Ts...[Idx], std::string_view>) {
72- reflected_element[Idx] = std::meta::reflect_constant_string (get<Idx>(tup));
73- } else {
74- reflected_element[Idx] = std::meta::reflect_constant (get<Idx>(tup));
75- }
76- }
77- return std::meta::reflect_constant_array (reflected_element);
78- }
79-
80- } // namespace _testing_impl
81-
82- namespace annotations {
4+ #include " _impl/params.hpp"
835
6+ namespace rsl ::testing::annotations {
847struct TestTag {};
858constexpr inline TestTag test;
869
@@ -90,73 +13,16 @@ constexpr inline ExpectFailureTag expect_failure;
9013struct FixtureTag {};
9114constexpr inline FixtureTag fixture;
9215
93- struct Params {
94- std::meta::info generator;
95-
96- template <typename ... Ts>
97- consteval explicit Params (std::vector<std::tuple<Ts...>> const & param_sets) {
98- std::vector<std::meta::info> params = {};
99- for (auto const & element : param_sets) {
100- params.push_back (_testing_impl::reflect_tuple (element));
101- }
102-
103- auto arg_tuple = substitute (^^std::tuple, {^^Ts...});
104- generator =
105- substitute (^^_testing_impl::param_generator,
106- {arg_tuple, reflect_constant (std::meta::reflect_constant_array (params))});
107- }
108-
109- template <typename ... Ts>
110- consteval explicit (false ) Params(std::initializer_list<std::tuple<Ts...>> param_sets)
111- : Params(std::vector<std::tuple<Ts...>>{param_sets}) {}
112-
113- template <typename ... Ts>
114- consteval Params (std::vector<std::tuple<Ts...>> (*generator)())
115- : generator(std::meta::reflect_constant(generator)) {}
116- };
117-
118- struct TParams {
119- std::meta::info generator;
120-
121- template <typename ... Ts>
122- consteval explicit TParams (std::vector<std::tuple<Ts...>> const & param_sets) {
123- std::vector<std::meta::info> params = {};
124- for (auto const & element : param_sets) {
125- params.push_back (_testing_impl::reflect_tuple (element, false ));
126- }
127-
128- generator = substitute (^^_testing_impl::tparam_generator,
129- {reflect_constant (std::meta::reflect_constant_array (params))});
130- }
131-
132- template <typename ... Ts>
133- consteval explicit (false ) TParams(std::initializer_list<std::tuple<Ts...>> param_sets)
134- : TParams(std::vector<std::tuple<Ts...>>{param_sets}) {}
135- };
136-
13716using params = Params;
13817using tparams = TParams;
13918
14019struct Rename {
141- char const * value = nullptr ;
20+ char const * value = nullptr ;
14221
143- static consteval Rename operator ()(std::string_view new_name){
22+ static consteval Rename operator ()(std::string_view new_name) {
14423 return Rename (define_static_string (new_name));
14524 }
14625};
14726constexpr inline Rename rename{};
14827
149- } // namespace annotations
150-
151- template <std::meta::info R>
152- void make_calls () {
153- template for (constexpr auto annotation :
154- std::define_static_array (annotations_of (R, ^^annotations::Params))) {
155- constexpr static annotations::Params params = extract<annotations::Params>(annotation);
156- for (auto set : [:params.generator :]()) {
157- std::apply ([:R:], set);
158- }
159- }
160- }
161-
162- } // namespace rsl
28+ } // namespace rsl::testing::annotations
0 commit comments