Skip to content

Commit 307aa6c

Browse files
committed
fix catch reporter
1 parent 754b06f commit 307aa6c

File tree

5 files changed

+90
-33
lines changed

5 files changed

+90
-33
lines changed

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ set(CMAKE_CXX_EXTENSIONS OFF)
55
set(CMAKE_CXX_STANDARD 26)
66

77
project(rsltest CXX)
8-
add_library(rsltest SHARED)
8+
add_library(rsltest )
99

1010
set_target_properties(rsltest PROPERTIES OUTPUT_NAME rsltest)
1111
target_compile_options(rsltest PUBLIC
@@ -20,7 +20,7 @@ target_include_directories(rsltest PUBLIC
2020
find_package(libassert REQUIRED)
2121
target_link_libraries(rsltest PUBLIC libassert::assert)
2222

23-
add_library(rsltest_main SHARED)
23+
add_library(rsltest_main )
2424

2525
target_link_libraries(rsltest_main PUBLIC rsltest)
2626

example/tparams.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ consteval std::vector<rsl::testing::ParamSet> make_tparams() {
1111
[[=rsl::tparams(make_tparams)]]
1212
[[=rsl::tparams({{^^int, 10}, {^^float, 21}})]]
1313
[[=rsl::params({{42, 'c'}, {12, 'b'}})]]
14-
constexpr inline auto tparam_gt_5 = []<typename T, int I>(int a, char b) static {
14+
constexpr inline auto tparam_gt_5 = []<typename T, unsigned I>(int a, char b) static {
1515
ASSERT(I > 5);
1616
};
17+
18+
struct TestAggregate{ unsigned value; };
19+
20+
[[=rsl::test]]
21+
[[=rsl::tparams({{TestAggregate{42}}, {TestAggregate{12}}})]]
22+
constexpr inline auto tparam_aggregate = []<TestAggregate>() static {};
1723
} // namespace

include/rsl/testing/_testing_impl/expand.hpp

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <tuple>
77

88
#include <rsl/assert>
9+
#include <rsl/repr>
910
#include <libassert/assert.hpp>
1011

1112
#include <rsl/testing/test_case.hpp>
@@ -56,24 +57,13 @@ struct TestRunner {
5657
}
5758

5859
if constexpr (has_template_arguments(Target)) {
59-
name += "<";
60-
bool first = true;
61-
template for (constexpr auto T : define_static_array(template_arguments_of(Target))) {
62-
if (first) {
63-
first = false;
64-
} else {
65-
name += ", ";
66-
}
67-
// TODO stringify aliases properly
68-
name += display_string_of(T);
69-
}
70-
name += ">";
60+
name += rsl::serializer::stringify_template_args(Target);
7161
}
7262
name += std::apply(
7363
[](auto&&... args) {
7464
std::string result = "(";
7565
std::size_t i = 0;
76-
((result += (i++ ? ", " : "") + libassert::stringify(args)), ...);
66+
((result += (i++ ? ", " : "") + repr(args)), ...);
7767
result += ")";
7868
return result;
7969
},

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
target_sources(rsltest PUBLIC
1+
target_sources(rsltest PRIVATE
22
capture.cpp
33
test.cpp
44
)

src/main/reporters/catch2xml.cpp

Lines changed: 77 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,56 @@ struct OverallResultsCases {
2828
[[= xml::attribute]] unsigned skips = 0;
2929
};
3030

31+
struct StdOut {
32+
[[= xml::attribute]] std::optional<std::string> filename;
33+
[[= xml::attribute]] std::optional<unsigned> line;
34+
[[= xml::raw]] std::string value;
35+
};
36+
struct StdErr {
37+
[[= xml::attribute]] std::optional<std::string> filename;
38+
[[= xml::attribute]] std::optional<unsigned> line;
39+
[[= xml::raw]] std::string value;
40+
};
41+
struct Exception {
42+
[[= xml::attribute]] std::optional<std::string> filename;
43+
[[= xml::attribute]] std::optional<unsigned> line;
44+
[[= xml::raw]] std::string value;
45+
};
46+
struct FatalErrorCondition {
47+
[[= xml::attribute]] std::optional<std::string> filename;
48+
[[= xml::attribute]] std::optional<unsigned> line;
49+
[[= xml::raw]] std::string value;
50+
};
51+
struct Failure {
52+
[[= xml::attribute]] std::optional<std::string> filename;
53+
[[= xml::attribute]] std::optional<unsigned> line;
54+
[[= xml::raw]] std::string value;
55+
};
56+
struct Warning {
57+
[[= xml::attribute]] std::optional<std::string> filename;
58+
[[= xml::attribute]] std::optional<unsigned> line;
59+
[[= xml::raw]] std::string value;
60+
};
61+
struct Info {
62+
[[= xml::attribute]] std::optional<std::string> filename;
63+
[[= xml::attribute]] std::optional<unsigned> line;
64+
[[= xml::raw]] std::string value;
65+
};
66+
3167
struct Section {
3268
[[= xml::attribute]] std::string name;
3369
[[= xml::attribute]] std::optional<std::string> filename;
3470
[[= xml::attribute]] std::optional<unsigned> line;
35-
[[=xml::node]] std::vector<Section> sections;
36-
[[=xml::node]] OverallResults results;
71+
[[= xml::node]] std::vector<Section> sections;
72+
[[= xml::node]] OverallResults results;
73+
74+
[[= xml::node]] std::optional<StdOut> stdout;
75+
[[= xml::node]] std::optional<StdErr> stderr;
76+
[[= xml::node]] std::optional<Exception> exception;
77+
[[= xml::node]] std::optional<FatalErrorCondition> fatal_ec;
78+
[[= xml::node]] std::optional<Failure> failure;
79+
[[= xml::node]] std::optional<Warning> warning;
80+
[[= xml::node]] std::optional<Info> info;
3781

3882
void update_results() {
3983
for (auto& section : sections) {
@@ -51,8 +95,8 @@ struct TestCase {
5195
[[= xml::attribute]] std::optional<std::string> filename;
5296
[[= xml::attribute]] std::optional<unsigned> line;
5397

54-
[[=xml::node]] std::vector<Section> sections;
55-
[[=xml::node]] OverallResult result;
98+
[[= xml::node]] std::vector<Section> sections;
99+
[[= xml::node]] OverallResult result;
56100

57101
void update_results() {
58102
for (auto& section : sections) {
@@ -67,9 +111,9 @@ struct Catch2TestRun {
67111
[[= xml::attribute]] std::size_t xml_format_version = 3;
68112
[[= xml::attribute]] std::string catch2_version = "3.8.1";
69113

70-
[[=xml::node]] std::vector<TestCase> tests;
71-
[[=xml::node]] OverallResults test_results;
72-
[[=xml::node]] OverallResultsCases case_results;
114+
[[= xml::node]] std::vector<TestCase> tests;
115+
[[= xml::node]] OverallResults test_results;
116+
[[= xml::node]] OverallResultsCases case_results;
73117

74118
TestCase& get_tc(std::string_view name) {
75119
for (auto& test : tests) {
@@ -103,37 +147,54 @@ struct Catch2TestRun {
103147
}
104148
};
105149

150+
struct Name {
151+
[[= xml::raw]] std::string value;
152+
};
153+
106154
struct MatchingTests {
107155
struct TestCase {
108-
[[= xml::raw]] std::string Name;
156+
Name name;
109157
};
110-
[[=xml::node]] std::vector<MatchingTests::TestCase> tests;
158+
[[= xml::node]] std::vector<MatchingTests::TestCase> tests;
111159
};
112160

113161
class[[= rename("xml")]] Catch2XmlReporter : public Reporter::Registrar<Catch2XmlReporter> {
114162
Catch2TestRun report;
115-
163+
116164
public:
117165
void before_test(rsl::testing::TestCase const& run) override {}
118166
void after_test(TestResult const& result) override {
119-
TestCase& tc = report.get_tc(result.test->full_name[0]);
167+
TestCase& tc = report.get_tc(result.test->full_name[0]);
120168
Section* section = nullptr;
121169

122170
if (result.test->full_name.size() >= 2) {
123-
section = &tc.sections.emplace_back(result.test->full_name[1]);
171+
section = &tc.sections.emplace_back(result.test->full_name[1]);
124172
for (auto const& part : result.test->full_name | std::views::drop(2)) {
125173
section = &section->sections.emplace_back(part);
126174
}
127-
section->sections.emplace_back(result.name, result.test->sloc.file_name(), result.test->sloc.line());
175+
section->sections.emplace_back(result.name,
176+
result.test->sloc.file_name(),
177+
result.test->sloc.line());
128178
section = &section->sections.back();
129179
} else {
130-
tc.sections.emplace_back(result.name, result.test->sloc.file_name(), result.test->sloc.line());
180+
tc.sections.emplace_back(result.name,
181+
result.test->sloc.file_name(),
182+
result.test->sloc.line());
131183
section = &tc.sections.back();
132184
}
133185

186+
if (!result.stdout.empty()) {
187+
section->stdout = {.value=result.stdout};
188+
}
189+
190+
if (!result.stderr.empty()) {
191+
section->stderr = {.value=result.stderr};
192+
}
193+
134194
if (result.passed) {
135195
++section->results.successes;
136196
} else {
197+
section->failure = {.value=result.error};
137198
++section->results.failures;
138199
}
139200
section->results.durationInSeconds += result.duration_ms / 1000.;
@@ -154,11 +215,11 @@ class[[= rename("xml")]] Catch2XmlReporter : public Reporter::Registrar<Catch2Xm
154215
void list_tests(TestNamespace const& tests) override {
155216
MatchingTests matching{};
156217
for (auto const& ns : tests.children) {
157-
matching.tests.emplace_back(std::string(ns.name));
218+
matching.tests.push_back(MatchingTests::TestCase{std::string(ns.name)});
158219
}
159220

160221
for (auto const& test : tests.tests) {
161-
matching.tests.emplace_back(std::string(test.name));
222+
matching.tests.push_back(MatchingTests::TestCase{std::string(test.name)});
162223
}
163224
// todo use Output instead
164225
std::println("{}", rsl::to_xml(matching));

0 commit comments

Comments
 (0)