11#pragma once
2- #include < functional>
32#include < string>
3+ #include < functional>
44#include < meta>
5- #include < tuple>
65#include < vector>
6+ #include < tuple>
77
88#include < rsl/assert>
9- #include < libassert/assert.hpp> // TODO use repr instead
9+ #include < libassert/assert.hpp>
1010
11+ #include < rsl/testing/fuzz.hpp>
12+
13+ #include " fixture.hpp"
1114#include " annotations.hpp"
12- #include " _impl/fixture.hpp"
1315
1416namespace rsl ::testing {
17+ // TODO move to testing/test.hpp
1518struct TestResult ;
16- struct Test ;
17-
1819struct TestRun {
19- Test const * test;
20+ class Test const * test;
2021 std::function<void ()> fnc;
2122 std::string name;
2223
2324 [[nodiscard]] TestResult run () const ;
25+ };
26+ } // namespace rsl::testing
27+
28+ namespace rsl ::testing::_testing_impl {
29+ template <std::meta::info R, std::meta::info Target>
30+ struct FuzzRunner {
31+ static int run (uint8_t const * Data, size_t Size) {
32+ // TODO
33+ return 0 ;
34+ }
2435
25- template <std::meta::info Def, std::meta::info Target>
26- struct Runner {
27- template <typename T>
28- static void run_one (T const & tuple) {
29- if constexpr (is_class_member (Def)) {
30- auto fixture = [:parent_of (Def):]();
31- std::apply (fixture.[:Target:], tuple);
32- } else if constexpr (is_variable (Def)) {
33- std::apply ([:Def:].[:Target:], tuple);
34- } else {
35- std::apply ([:Target:], tuple);
36- }
36+ // mutator must be able to consider domains
37+ static size_t mutate (uint8_t * Data, size_t Size, size_t MaxSize, unsigned int Seed) {
38+ // TODO
39+ return 0 ;
40+ }
41+ };
42+
43+ template <std::meta::info Def, std::meta::info Target>
44+ struct TestRunner {
45+ template <typename T>
46+ static void run_one (T const & tuple) {
47+ if constexpr (is_class_member (Def)) {
48+ auto fixture = [:parent_of (Def):]();
49+ std::apply (fixture.[:Target:], tuple);
50+ } else if constexpr (is_variable (Def)) {
51+ std::apply ([:Def:].[:Target:], tuple);
52+ } else {
53+ std::apply ([:Target:], tuple);
3754 }
55+ }
3856
39- template <typename ... Ts>
40- static std::string get_name (std::tuple<Ts...> args) {
41- std::string name;
42- if constexpr (is_variable (Def)) {
57+ template <typename ... Ts>
58+ static std::string get_name (std::tuple<Ts...> args) {
59+ std::string name;
60+ if constexpr (is_variable (Def)) {
61+ name += identifier_of (Def);
62+ } else {
63+ if constexpr (has_template_arguments (Target)) {
4364 name += identifier_of (Def);
4465 } else {
45- if constexpr (has_template_arguments (Target)) {
46- name += identifier_of (Def);
47- } else {
48- name += identifier_of (Target);
49- }
66+ name += identifier_of (Target);
5067 }
68+ }
5169
52- if constexpr (has_template_arguments (Target)) {
53- name += " <" ;
54- bool first = true ;
55- template for (constexpr auto T : define_static_array (template_arguments_of (Target))) {
56- if (first) {
57- first = false ;
58- } else {
59- name += " , " ;
60- }
61- // TODO stringify aliases properly
62- name += display_string_of (T);
70+ if constexpr (has_template_arguments (Target)) {
71+ name += " <" ;
72+ bool first = true ;
73+ template for (constexpr auto T : define_static_array (template_arguments_of (Target))) {
74+ if (first) {
75+ first = false ;
76+ } else {
77+ name += " , " ;
6378 }
64- name += " >" ;
79+ // TODO stringify aliases properly
80+ name += display_string_of (T);
6581 }
66- name += std::apply (
67- [](auto &&... args) {
68- std::string result = " (" ;
69- std::size_t i = 0 ;
70- ((result += (i++ ? " , " : " " ) + libassert::stringify (args)), ...);
71- result += " )" ;
72- return result;
73- },
74- args);
75- return name;
82+ name += " >" ;
7683 }
84+ name += std::apply (
85+ [](auto &&... args) {
86+ std::string result = " (" ;
87+ std::size_t i = 0 ;
88+ ((result += (i++ ? " , " : " " ) + libassert::stringify (args)), ...);
89+ result += " )" ;
90+ return result;
91+ },
92+ args);
93+ return name;
94+ }
7795
78- template <typename ... Ts>
79- static TestRun bind (Test const * group, std::tuple<Ts...> args) {
80- return {group, std::bind_front (run_one<std::tuple<Ts...>>, args), get_name (args)};
81- }
82- };
96+ template <typename ... Ts>
97+ static TestRun bind (Test const * group, std::tuple<Ts...> args) {
98+ return {group, std::bind_front (run_one<std::tuple<Ts...>>, args), get_name (args)};
99+ }
83100};
84101
85- namespace _impl {
86- template <std::meta::info R, Annotations A>
102+ template <std::meta::info R, _testing_impl::Annotations A>
87103struct Expand {
88104 std::vector<TestRun> runs;
89105 Test const * group;
@@ -109,30 +125,31 @@ struct Expand {
109125
110126 template <std::meta::info Target>
111127 void expand_params () {
112- using Runner = TestRun::Runner <R, Target>;
128+ using runner = TestRunner <R, Target>;
113129
114130 if constexpr (A.params .size () == 0 ) {
115131 // expand fixtures
116- runs.push_back (Runner ::bind (group, rsl::testing::_testing_impl::evaluate_fixtures<Target>()));
132+ runs.push_back (runner ::bind (group, rsl::testing::_testing_impl::evaluate_fixtures<Target>()));
117133 } else {
118134 // expand param annotations
119135 template for (constexpr auto generator : A.params ) {
120- expand_param_generator<Runner , generator>();
136+ expand_param_generator<runner , generator>();
121137 }
122138 }
123139 }
124140
125141 template <std::meta::info Target>
126142 void expand_tparams () {
127- constexpr_assert (A.targets .size () != 0 ,
143+ constexpr_assert (
144+ A.targets .size () != 0 ,
128145 std::string (" template argument parameterization required for " ) + display_string_of (R));
129146
130147 template for (constexpr auto set : A.targets ) {
131148 expand_params<substitute (Target, set.value )>();
132149 }
133150 }
134151
135- explicit Expand (Test const * group) : group(group){
152+ explicit Expand (Test const * group) : group(group) {
136153 constexpr auto target_count = A.targets .size ();
137154 constexpr auto param_count = A.params .size ();
138155 if constexpr (is_variable (R)) {
@@ -157,6 +174,4 @@ struct Expand {
157174 }
158175 }
159176};
160- } // namespace _impl
161-
162- } // namespace rsl::testing
177+ } // namespace rsl::testing::_testing_impl
0 commit comments