Skip to content

Commit 0a672b7

Browse files
committed
start result cleanup
1 parent 5af1541 commit 0a672b7

File tree

8 files changed

+25
-46
lines changed

8 files changed

+25
-46
lines changed

example/CMakeLists.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ target_sources(example_test PRIVATE
55
fixtures.cpp
66
conditional.cpp
77
)
8-
9-
add_executable(params_debug params_debug.cpp)
10-
target_link_libraries(params_debug PUBLIC rsltest)
8+
# add_executable(params_debug params_debug.cpp)
9+
# target_compile_options(example_test PUBLIC -fprofile-instr-generate -fcoverage-mapping)
10+
# target_link_options(example_test PUBLIC -fprofile-instr-generate -fcoverage-mapping)
11+
# target_link_libraries(params_debug PUBLIC rsltest)

include/rsl/testing/output.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ struct Reporter : _testing_impl::Factory<Reporter> {
2323

2424
virtual ~Reporter() = default;
2525
virtual void before_run(TestNamespace const& tests) {}
26-
virtual void after_run(std::span<TestResult> results) {}
26+
virtual void after_run(std::span<Result> results) {}
2727

2828
virtual void before_test_group(Test const& test) {}
29-
virtual void after_test_group(std::span<TestResult> results) {}
29+
virtual void after_test_group(std::span<Result> results) {}
3030

3131
virtual void before_test(TestCase const& test) = 0;
32-
virtual void after_test(TestResult const& result) = 0;
32+
virtual void after_test(Result const& result) = 0;
3333

3434
virtual void list_tests(TestNamespace const& tests);
3535

include/rsl/testing/result.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ enum class TestOutcome: uint8_t {
1111
SKIP
1212
};
1313

14-
struct TestResult {
14+
struct Result {
1515
class Test const* test;
1616
std::string name;
1717

@@ -26,12 +26,17 @@ struct TestResult {
2626
std::vector<AssertionInfo> assertions;
2727
};
2828

29+
struct TestResult {
30+
class Test const* test;
31+
std::vector<Result> results;
32+
};
33+
2934
struct ResultNamespace {
3035
std::string_view name;
3136
std::vector<TestResult> tests;
3237
std::vector<ResultNamespace> children;
3338

34-
void insert(TestResult const& test, size_t i = 0);
39+
void insert(Result const& test, size_t i = 0);
3540
[[nodiscard]] std::size_t count() const;
3641
};
3742
} // namespace rsl::testing

include/rsl/testing/test.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct TestCase {
1919
std::function<void()> fnc;
2020
std::string name;
2121

22-
[[nodiscard]] TestResult run() const;
22+
[[nodiscard]] Result run() const;
2323
};
2424

2525
struct FuzzTarget {

src/main/reporters/catch2xml.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ class[[= rename("xml")]] Catch2XmlReporter : public Reporter::Registrar<Catch2Xm
170170

171171
public:
172172
void before_test(rsl::testing::TestCase const& run) override {}
173-
void after_test(TestResult const& result) override {
173+
void after_test(Result const& result) override {
174174
TestCase& tc = report.get_tc(result.test->full_name[0]);
175175
Section* section = nullptr;
176176

@@ -227,7 +227,7 @@ class[[= rename("xml")]] Catch2XmlReporter : public Reporter::Registrar<Catch2Xm
227227
// </Expression>
228228
}
229229

230-
void after_run(std::span<TestResult> results) override { report.update_results(); }
230+
void after_run(std::span<Result> results) override { report.update_results(); }
231231

232232
void list_tests(TestNamespace const& tests) override {
233233
MatchingTests matching{};

src/main/reporters/terminal.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class [[=rename("plain")]] ConsoleReporter : public Reporter::Registrar<ConsoleR
99
public:
1010
void before_run(TestNamespace const& tests) override { std::print("Running {} tests...\n", tests.count()); }
1111
void before_test(TestCase const& test) override { std::print("[ RUN ] {}\n", test.name); }
12-
void after_test(TestResult const& result) override {
12+
void after_test(Result const& result) override {
1313
bool const must_colorize = true;
1414
auto const color = std::array{must_colorize ? "\033[32m" : "", must_colorize ? "\033[31m" : ""};
1515
const char* const reset = must_colorize ? "\033[0m" : "";
@@ -31,7 +31,7 @@ class [[=rename("plain")]] ConsoleReporter : public Reporter::Registrar<ConsoleR
3131
std::print("==== {}stderr{} ====\n{}\n", color[1], reset, result.stderr);
3232
}
3333
}
34-
void after_run(std::span<TestResult> results) override {
34+
void after_run(std::span<Result> results) override {
3535
auto passed = std::ranges::count_if(results, [](auto& r) { return r.outcome == TestOutcome::PASS; });
3636
std::print("=== Summary ===\n{} / {} tests passed.\n", passed, results.size());
3737
}

src/main/reporters/xml.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class [[=rename("junit")]] JUnitXmlReporter : public Reporter::Registrar<JUnitXm
2020
testsuite suite;
2121
public:
2222
void before_test(TestCase const& test) override {}
23-
void after_test(TestResult const& result) override {
23+
void after_test(Result const& result) override {
2424
auto node = testcase{.name=std::string(result.name), .time=result.duration_ms / 1000.};
2525
if (result.outcome == TestOutcome::FAIL) {
2626
node.failure = result.failure->message + "\n";

src/test.cpp

Lines changed: 5 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,9 @@ bool TestNamespace::run(Reporter* reporter) {
8383
for (auto& test : tests) {
8484
auto runs = test.get_tests();
8585
reporter->before_test_group(test);
86-
std::vector<TestResult> results;
86+
std::vector<Result> results;
8787
if (!test.skip()) {
88-
std::vector<TestResult> results;
88+
std::vector<Result> results;
8989
for (auto const& test_run : test.get_tests()) {
9090
auto& tracker = _testing_impl::assertion_counter();
9191
tracker.assertions = {};
@@ -102,7 +102,7 @@ bool TestNamespace::run(Reporter* reporter) {
102102
reporter->before_test(TestCase{&test, +[]{}, std::string(test.name)});
103103

104104
// TODO stringify skipped tests properly
105-
auto result = TestResult{&test, std::string(test.name) + "(...)", TestOutcome::SKIP};
105+
auto result = Result{&test, std::string(test.name) + "(...)", TestOutcome::SKIP};
106106
reporter->after_test(result);
107107
results.push_back(result);
108108
}
@@ -115,8 +115,8 @@ bool TestNamespace::run(Reporter* reporter) {
115115
return status;
116116
}
117117

118-
TestResult TestCase::run() const {
119-
auto ret = TestResult{.test = test, .name = name};
118+
Result TestCase::run() const {
119+
auto ret = Result{.test = test, .name = name};
120120
try {
121121
Capture _out(stdout, ret.stdout);
122122
Capture _err(stderr, ret.stderr);
@@ -184,33 +184,6 @@ 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-
214187
void TestNamespace::insert(Test const& test, std::size_t i) {
215188
if (i == test.full_name.size() - 1) {
216189
tests.push_back(test);

0 commit comments

Comments
 (0)