Skip to content

Commit c0f4c94

Browse files
committed
refactor
1 parent d8f5011 commit c0f4c94

File tree

4 files changed

+57
-22
lines changed

4 files changed

+57
-22
lines changed

include/rsl/testing/_testing_impl/expand.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <rsl/repr>
1010
#include <rsl/testing/assert.hpp>
1111

12-
#include <rsl/testing/test_case.hpp>
12+
#include <rsl/testing/result.hpp>
1313

1414
#include "fixture.hpp"
1515
#include "annotations.hpp"
@@ -29,7 +29,7 @@ struct FuzzRunner {
2929
}
3030
};
3131

32-
template <std::meta::info Def, std::meta::info Target>
32+
template <typename TC, std::meta::info Def, std::meta::info Target>
3333
struct TestRunner {
3434
template <typename T>
3535
static void run_one(T const& tuple) {
@@ -72,14 +72,14 @@ struct TestRunner {
7272
}
7373

7474
template <typename... Ts>
75-
static TestCase bind(Test const* group, std::tuple<Ts...> args) {
75+
static TC bind(Test const* group, std::tuple<Ts...> args) {
7676
return {group, std::bind_front(run_one<std::tuple<Ts...>>, args), get_name(args)};
7777
}
7878
};
7979

80-
template <std::meta::info R, _testing_impl::Annotations A>
80+
template <typename TC, std::meta::info R, _testing_impl::Annotations A>
8181
struct Expand {
82-
std::vector<TestCase> runs;
82+
std::vector<TC> runs;
8383
Test const* group;
8484

8585
template <typename Runner, annotations::Params Generator>
@@ -103,7 +103,7 @@ struct Expand {
103103

104104
template <std::meta::info Target>
105105
void expand_params() {
106-
using runner = TestRunner<R, Target>;
106+
using runner = TestRunner<TC, R, Target>;
107107

108108
if constexpr (A.params.size() == 0) {
109109
// expand fixtures
Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,18 +26,12 @@ struct TestResult {
2626
std::vector<AssertionInfo> assertions;
2727
};
2828

29-
struct TestCase {
30-
class Test const* test;
31-
std::function<void()> fnc;
32-
std::string name;
29+
struct ResultNamespace {
30+
std::string_view name;
31+
std::vector<TestResult> tests;
32+
std::vector<ResultNamespace> children;
3333

34-
[[nodiscard]] TestResult run() const;
35-
};
36-
37-
struct FuzzTarget {
38-
// stringifying name is pointless here, perhaps do it after failure
39-
class Test const* test;
40-
int (*run)(uint8_t const*, size_t);
41-
size_t (*mutate)(uint8_t*, size_t, size_t, unsigned int);
34+
void insert(TestResult const& test, size_t i = 0);
35+
[[nodiscard]] std::size_t count() const;
4236
};
4337
} // namespace rsl::testing

include/rsl/testing/test.hpp

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#include <set>
99
#include <algorithm>
1010

11-
#include "test_case.hpp"
11+
#include "result.hpp"
1212

1313
#include "_testing_impl/util.hpp"
1414
#include "_testing_impl/expand.hpp"
@@ -19,14 +19,28 @@
1919

2020

2121
namespace rsl::testing {
22-
22+
struct TestCase {
23+
class Test const* test;
24+
std::function<void()> fnc;
25+
std::string name;
26+
27+
[[nodiscard]] TestResult run() const;
28+
};
29+
30+
struct FuzzTarget {
31+
// stringifying name is pointless here, perhaps do it after failure
32+
class Test const* test;
33+
int (*run)(uint8_t const*, size_t);
34+
size_t (*mutate)(uint8_t*, size_t, size_t, unsigned int);
35+
};
36+
2337
class Test {
2438
using runner_type = std::vector<TestCase> (Test::*)() const;
2539
runner_type get_tests_impl;
2640

2741
template <std::meta::info R, _testing_impl::Annotations Ann>
2842
std::vector<TestCase> expand_test() const {
29-
return _testing_impl::Expand<R, Ann>{this}.runs;
43+
return _testing_impl::Expand<TestCase, R, Ann>{this}.runs;
3044
}
3145

3246
public:

src/test.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
#include <rsl/source_location>
77
#include <rsl/testing/assert.hpp>
88
#include <rsl/testing/test.hpp>
9+
#include <rsl/testing/result.hpp>
910
#include <rsl/testing/output.hpp>
1011
#include <rsl/testing/util.hpp>
1112
#include <rsl/testing/_testing_impl/discovery.hpp>
1213

1314
#include "capture.hpp"
14-
#include "rsl/testing/test_case.hpp"
1515

1616
#include <cpptrace/basic.hpp>
1717
#include <cpptrace/utils.hpp>
@@ -184,6 +184,33 @@ bool TestNamespace::iterator::operator==(iterator const& other) const {
184184
return elements == other.elements;
185185
}
186186

187+
// TODO get rid of duplicated code
188+
void ResultNamespace::insert(TestResult const& test, std::size_t i) {
189+
if (i == test.test->full_name.size() - 1) {
190+
tests.push_back(test);
191+
return;
192+
}
193+
194+
auto it = std::ranges::find_if(children, [&](const ResultNamespace& ns) {
195+
return ns.name == test.test->full_name[i];
196+
});
197+
198+
if (it == children.end()) {
199+
children.emplace_back(test.test->full_name[i]);
200+
it = std::prev(children.end());
201+
}
202+
203+
it->insert(test, i + 1);
204+
}
205+
206+
std::size_t ResultNamespace::count() const {
207+
std::size_t total = tests.size();
208+
for (auto const& ns : children) {
209+
total += ns.count();
210+
}
211+
return total;
212+
}
213+
187214
void TestNamespace::insert(Test const& test, std::size_t i) {
188215
if (i == test.full_name.size() - 1) {
189216
tests.push_back(test);

0 commit comments

Comments
 (0)