15 #ifndef SIMPLE_JUNIT__JUNIT5_HPP_
16 #define SIMPLE_JUNIT__JUNIT5_HPP_
19 #include <pugixml.hpp>
22 #include <unordered_map>
37 return os <<
"\x1b[32mPassed\x1b[0m";
61 return os <<
"\x1b[1;31m" << failure.type <<
": " << failure.message <<
"\x1b[0m";
66 if (not failure.type.empty()) {
67 node.append_attribute(
"type") = failure.type.c_str();
70 if (not failure.message.empty()) {
71 node.append_attribute(
"message") = failure.message.c_str();
97 return os <<
"\x1b[1;31m" << error.type <<
": " << error.message <<
"\x1b[0m";
102 if (not error.type.empty()) {
103 node.append_attribute(
"type") = error.type.c_str();
106 if (not error.message.empty()) {
107 node.append_attribute(
"message") = error.message.c_str();
208 auto current_node = node.append_child(
"testcase");
210 current_node.append_attribute(
"name") = testcase.name.c_str();
212 if (not testcase.assertions.empty()) {
213 current_node.append_attribute(
"assertions") = testcase.assertions.c_str();
216 if (not testcase.time.empty()) {
217 current_node.append_attribute(
"time") = testcase.time.c_str();
220 if (not testcase.classname.empty()) {
221 current_node.append_attribute(
"classname") = testcase.classname.c_str();
224 if (not testcase.status.empty()) {
225 current_node.append_attribute(
"status") = testcase.status.c_str();
230 for (
const auto & each : testcase.error) {
231 current_node.append_child(
"error") << each;
234 for (
const auto & each : testcase.failure) {
235 current_node.append_child(
"failure") << each;
278 std::vector<std::string> names;
279 for (
auto itr = begin(); itr != end(); ++itr) {
280 names.emplace_back(itr->first);
289 }
catch (
const std::out_of_range &) {
297 auto current_node = node.append_child(
"testsuite");
299 current_node.append_attribute(
"name") = testsuite.name.c_str();
301 std::size_t tests = 0;
302 std::size_t failures = 0;
303 std::size_t pass = 0;
304 std::size_t errors = 0;
305 for (
const auto &
testcase : testsuite) {
307 pass = pass +
testcase.second.pass.size();
308 failures = failures +
testcase.second.failure.size();
309 errors = errors +
testcase.second.error.size();
311 tests = pass + failures + errors;
312 current_node.append_attribute(
"failures") = failures;
313 current_node.append_attribute(
"errors") = errors;
314 current_node.append_attribute(
"tests") = tests;
345 }
catch (
const std::out_of_range &) {
353 auto current_node = node.append_child(
"testsuites");
355 if (not testsuites.name.empty()) {
356 current_node.append_attribute(
"name") = testsuites.name.c_str();
358 std::size_t tests = 0;
359 std::size_t failures = 0;
360 std::size_t pass = 0;
361 std::size_t errors = 0;
362 for (
const auto &
testsuite : testsuites) {
364 current_node << suite;
366 for (
const auto & testcase_name : testcase_names) {
367 failures = failures + suite.
testcase(testcase_name).failure.size();
368 errors = errors + suite.
testcase(testcase_name).error.size();
369 pass = pass + suite.
testcase(testcase_name).pass.size();
371 tests = failures + errors + pass;
373 current_node.append_attribute(
"failures") = failures;
374 current_node.append_attribute(
"errors") = errors;
375 current_node.append_attribute(
"tests") = tests;
380 template <
typename... Ts>
383 pugi::xml_document document;
387 document.save_file(std::forward<decltype(
xs)>(
xs)...);
xs::string SystemErr
Definition: junit5.hpp:159
xs::string SystemOut
Definition: junit5.hpp:153
xs::string Skipped
Definition: junit5.hpp:147
Definition: concatenate.hpp:24
Definition: test_case.hpp:23
Definition: junit5.hpp:25
std::string string
Definition: junit5.hpp:26
Definition: junit5.hpp:88
friend auto operator<<(pugi::xml_node node, const Error &error) -> pugi::xml_node
Definition: junit5.hpp:100
friend auto operator<<(std::ostream &os, const Error &error) -> std::ostream &
Definition: junit5.hpp:95
Error(const xs::string &type, const xs::string &message)
Definition: junit5.hpp:91
xs::string message
Definition: junit5.hpp:89
xs::string type
Definition: junit5.hpp:89
Definition: junit5.hpp:51
xs::string type
Definition: junit5.hpp:52
xs::string message
Definition: junit5.hpp:52
Failure(const xs::string &type, const xs::string &message)
Definition: junit5.hpp:54
friend auto operator<<(std::ostream &os, const Failure &failure) -> std::ostream &
Definition: junit5.hpp:59
friend auto operator<<(pugi::xml_node node, const Failure &failure) -> pugi::xml_node
Definition: junit5.hpp:64
Definition: junit5.hpp:34
friend auto operator<<(std::ostream &os, const Pass &) -> std::ostream &
Definition: junit5.hpp:35
Definition: junit5.hpp:125
Definition: junit5.hpp:139
Definition: junit5.hpp:181
std::vector< Pass > pass
Definition: junit5.hpp:184
xs::string time
Definition: junit5.hpp:198
std::vector< SystemErr > system_err
Definition: junit5.hpp:192
const xs::string name
Definition: junit5.hpp:194
std::vector< SystemOut > system_out
Definition: junit5.hpp:190
std::vector< Error > error
Definition: junit5.hpp:186
std::vector< Failure > failure
Definition: junit5.hpp:188
friend auto operator<<(pugi::xml_node node, const SimpleTestCase &testcase) -> pugi::xml_node
Definition: junit5.hpp:206
SimpleTestCase(const xs::string &name)
Definition: junit5.hpp:204
xs::string status
Definition: junit5.hpp:202
xs::string assertions
Definition: junit5.hpp:196
xs::string classname
Definition: junit5.hpp:200
Skipped skipped
Definition: junit5.hpp:182
Definition: junit5.hpp:271
auto testcase(const xs::string &name) -> auto &
Definition: junit5.hpp:285
SimpleTestSuite(const xs::string &name)
Definition: junit5.hpp:274
const xs::string name
Definition: junit5.hpp:272
friend auto operator<<(pugi::xml_node node, const SimpleTestSuite &testsuite) -> pugi::xml_node
Definition: junit5.hpp:295
auto getTestcaseNames() const -> std::vector< std::string >
Definition: junit5.hpp:276
Definition: junit5.hpp:336
xs::string name
Definition: junit5.hpp:337
auto write_to(Ts &&... xs) const
Definition: junit5.hpp:381
SimpleTestSuites(const xs::string &name="")
Definition: junit5.hpp:339
auto testsuite(const xs::string &name) -> auto &
Definition: junit5.hpp:341
friend auto operator<<(pugi::xml_node node, const SimpleTestSuites &testsuites) -> pugi::xml_node
Definition: junit5.hpp:351