22#include < algorithm>
33#include < atomic>
44#include < chrono>
5+ #include < filesystem>
56#include < numeric>
67#include < string>
7- #include < string_view>
88
99#include " formatters_base.hpp"
1010#include " it_base.hpp"
1111
1212namespace CppSpec ::Formatters {
1313// JUnit XML header
14- constexpr static std::string_view junit_xml_header = R"( <?xml version="1.0" encoding="UTF-8"?>)" ;
14+ constexpr static auto junit_xml_header = R"( <?xml version="1.0" encoding="UTF-8"?>)" ;
1515
1616struct XMLSerializable {
1717 virtual ~XMLSerializable () = default ;
@@ -26,8 +26,8 @@ struct Result {
2626 std::string type;
2727 std::string text;
2828
29- Result (const std::string& message, const std::string& type, const std::string& text, Status status = Status::Failure)
30- : status(status), message(message), type(type), text(text) {}
29+ Result (std::string message, std::string type, std::string text, Status status = Status::Failure)
30+ : status(status), message(std::move( message)) , type(std::move( type)) , text(std::move( text) ) {}
3131
3232 [[nodiscard]] std::string status_string () const {
3333 switch (status) {
@@ -91,7 +91,7 @@ struct TestSuite {
9191 size_t tests,
9292 size_t failures,
9393 std::chrono::time_point<std::chrono::system_clock> timestamp)
94- : id(get_next_id()), name(name), time(time), timestamp(timestamp), tests(tests), failures(failures) {}
94+ : id(get_next_id()), name(std::move( name) ), time(time), timestamp(timestamp), tests(tests), failures(failures) {}
9595
9696 [[nodiscard]] std::string to_xml () const {
9797 auto timestamp_str =
@@ -119,7 +119,7 @@ struct TestSuites {
119119 std::string name;
120120 size_t tests = 0 ;
121121 size_t failures = 0 ;
122- std::chrono::duration<double > time;
122+ std::chrono::duration<double > time{} ;
123123 std::chrono::time_point<std::chrono::system_clock> timestamp;
124124
125125 std::list<TestSuite> suites;
@@ -165,6 +165,10 @@ class JUnitXML : public BaseFormatter {
165165 }
166166
167167 void format (Description& description) override {
168+ if (test_suites.name .empty ()) {
169+ std::filesystem::path file_path = description.get_location ().file_name ();
170+ test_suites.name = file_path.stem ().string ();
171+ }
168172 if (description.has_parent ()) {
169173 return ;
170174 }
@@ -177,7 +181,7 @@ class JUnitXML : public BaseFormatter {
177181 std::forward_list<std::string> descriptions;
178182
179183 descriptions.push_front (it.get_description ());
180- for (auto parent = it.get_parent_as <Description>(); parent->has_parent ();
184+ for (auto * parent = it.get_parent_as <Description>(); parent->has_parent ();
181185 parent = parent->get_parent_as <Description>()) {
182186 descriptions.push_front (parent->get_description ());
183187 }
@@ -198,8 +202,8 @@ class JUnitXML : public BaseFormatter {
198202 if (result.is_success ()) {
199203 continue ;
200204 }
201- std::string junit_message = result.get_location_string () + " : " + result.get_message ();
202- test_case. results . emplace_back ( " Match failure. " , result. get_type (), result.get_message ());
205+ test_case. results . emplace_back ( result.get_location_string () + " : Match failure. " , result.get_type (),
206+ result.get_message ());
203207 }
204208
205209 test_suites.suites .back ().cases .push_back (test_case);
0 commit comments