Skip to content

Commit 19848d6

Browse files
committed
refactor
1 parent 7df1f8b commit 19848d6

File tree

8 files changed

+25
-26
lines changed

8 files changed

+25
-26
lines changed

include/rsl/testing/_testing_impl/expand.hpp

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,11 @@
88
#include <rsl/assert>
99
#include <libassert/assert.hpp>
1010

11-
#include <rsl/testing/fuzz.hpp>
11+
#include <rsl/testing/test_case.hpp>
1212

1313
#include "fixture.hpp"
1414
#include "annotations.hpp"
1515

16-
namespace rsl::testing {
17-
// TODO move to testing/test.hpp
18-
struct TestResult;
19-
struct TestRun {
20-
class Test const* test;
21-
std::function<void()> fnc;
22-
std::string name;
23-
24-
[[nodiscard]] TestResult run() const;
25-
};
26-
} // namespace rsl::testing
27-
2816
namespace rsl::testing::_testing_impl {
2917
template <std::meta::info R, std::meta::info Target>
3018
struct FuzzRunner {
@@ -94,14 +82,14 @@ struct TestRunner {
9482
}
9583

9684
template <typename... Ts>
97-
static TestRun bind(Test const* group, std::tuple<Ts...> args) {
85+
static TestCase bind(Test const* group, std::tuple<Ts...> args) {
9886
return {group, std::bind_front(run_one<std::tuple<Ts...>>, args), get_name(args)};
9987
}
10088
};
10189

10290
template <std::meta::info R, _testing_impl::Annotations A>
10391
struct Expand {
104-
std::vector<TestRun> runs;
92+
std::vector<TestCase> runs;
10593
Test const* group;
10694

10795
template <typename Runner, annotations::Params Generator>

include/rsl/testing/output.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct Reporter : _testing_impl::Factory<Reporter> {
2828
virtual void before_test_group(Test const& test) {}
2929
virtual void after_test_group(std::span<TestResult> results) {}
3030

31-
virtual void before_test(TestRun const& test) = 0;
31+
virtual void before_test(TestCase const& test) = 0;
3232
virtual void after_test(TestResult const& result) = 0;
3333

3434
virtual void list_tests(TestNamespace const& tests);

include/rsl/testing/test.hpp

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

11+
#include "test_case.hpp"
12+
1113
#include "_testing_impl/util.hpp"
1214
#include "_testing_impl/expand.hpp"
1315
#include "_testing_impl/fixture.hpp"
@@ -30,11 +32,11 @@ struct TestResult {
3032

3133

3234
class Test {
33-
using runner_type = std::vector<TestRun> (Test::*)() const;
35+
using runner_type = std::vector<TestCase> (Test::*)() const;
3436
runner_type get_tests_impl;
3537

3638
template <std::meta::info R, _testing_impl::Annotations Ann>
37-
std::vector<TestRun> expand_test() const {
39+
std::vector<TestCase> expand_test() const {
3840
return _testing_impl::Expand<R, Ann>{this}.runs;
3941
}
4042
public:
@@ -70,7 +72,7 @@ class Test {
7072
full_name = define_static_array(meta_name);
7173
}
7274

73-
std::vector<TestRun> get_tests() const { return (this->*get_tests_impl)(); }
75+
std::vector<TestCase> get_tests() const { return (this->*get_tests_impl)(); }
7476
};
7577

7678
using TestDef = Test (*)();
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
#pragma once
2+
#include <functional>
23

34
namespace rsl::testing {
5+
struct TestResult;
46
class Test;
7+
8+
struct TestCase {
9+
Test const* test;
10+
std::function<void()> fnc;
11+
std::string name;
12+
13+
[[nodiscard]] TestResult run() const;
14+
};
15+
516
struct FuzzTarget {
617
// stringifying name is pointless here, perhaps do it after failure
7-
18+
Test const* test;
819
int (*run)(uint8_t const*, size_t);
920
size_t (*mutate)(uint8_t*, size_t, size_t, unsigned int);
10-
11-
Test const* test;
1221
};
1322
} // namespace rsl::testing

src/reporters/catch2xml.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class[[= rename("xml")]] Catch2XmlReporter : public Reporter::Registrar<Catch2Xm
115115
Catch2TestRun report;
116116

117117
public:
118-
void before_test(TestRun const& run) override {}
118+
void before_test(rsl::testing::TestCase const& run) override {}
119119
void after_test(TestResult const& result) override {
120120
TestCase& tc = report.get_tc(result.test->full_name[0]);
121121
Section* section = nullptr;

src/reporters/terminal.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace rsl::testing::_impl {
88
class [[=rename("plain")]] ConsoleReporter : public Reporter::Registrar<ConsoleReporter> {
99
public:
1010
void before_run(TestNamespace const& tests) override { std::print("Running {} tests...\n", tests.count()); }
11-
void before_test(TestRun const& test) override { std::print("[ RUN ] {}\n", test.name); }
11+
void before_test(TestCase const& test) override { std::print("[ RUN ] {}\n", test.name); }
1212
void after_test(TestResult const& result) override {
1313
bool const must_colorize = true;
1414
auto const color = std::array{must_colorize ? "\033[32m" : "", must_colorize ? "\033[31m" : ""};

src/reporters/xml.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct testsuite {
1919
class [[=rename("junit")]] JUnitXmlReporter : public Reporter::Registrar<JUnitXmlReporter> {
2020
testsuite suite;
2121
public:
22-
void before_test(TestRun const& test) override {}
22+
void before_test(TestCase const& test) override {}
2323
void after_test(TestResult const& result) override {
2424
auto node = testcase{.name=std::string(result.name), .time=result.duration_ms / 1000.};
2525
if (!result.passed) {

src/test.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace rsl::testing {
2424
namespace _testing_impl {
2525
std::set<TestDef>& registry();
2626
}
27-
TestResult TestRun::run() const {
27+
TestResult TestCase::run() const {
2828
auto ret = TestResult{.test = test, .name = name};
2929
try {
3030
auto t0 = std::chrono::steady_clock::now();

0 commit comments

Comments
 (0)