@@ -13,7 +13,6 @@ namespace CppSpec::Formatters {
1313// The TAP format makes things a little tricky
1414class Progress : public BaseFormatter {
1515 std::list<std::string> baked_failure_messages;
16- std::list<std::string> raw_failure_messages;
1716
1817 std::string prep_failure_helper (const ItBase& it);
1918
@@ -25,6 +24,20 @@ class Progress : public BaseFormatter {
2524
2625 void format_failure_messages ();
2726 void prep_failure (const ItBase& it);
27+
28+ static char status_char (Result::Status status) {
29+ switch (status) {
30+ case Result::Status::Success:
31+ return ' .' ;
32+ case Result::Status::Failure:
33+ return ' F' ;
34+ case Result::Status::Error:
35+ return ' E' ;
36+ case Result::Status::Skipped:
37+ return ' S' ;
38+ }
39+ return ' .' ; // Default to success if status is unknown
40+ }
2841};
2942
3043/* * @brief An assistant function for prep_failure to reduce complexity */
@@ -63,43 +76,33 @@ inline std::string Progress::prep_failure_helper(const ItBase& it) {
6376}
6477
6578inline void Progress::prep_failure (const ItBase& it) {
66- std::ostringstream string_builder; // oss is used as the local string builder
67- if (color_output) {
68- string_builder << RED; // if we're doing color, make it red
69- }
79+ std::list<std::string> raw_failure_messages; // raw failure messages
80+ std::ranges::transform (it.get_results (), std::back_inserter (raw_failure_messages),
81+ [](const Result& result) { return result.get_message (); });
82+
83+ std::ostringstream string_builder; // oss is used as the local string builder
84+ string_builder << set_color (RED); // if we're doing color, make it red
7085 string_builder << " Test number " << test_counter << " failed:" ; // Tell us what test # failed
71- if (color_output) {
72- string_builder << RESET; // if we're doing color, reset the terminal
73- }
86+ string_builder << reset_color (); // reset the color
7487 string_builder << prep_failure_helper (it);
75- if (color_output) {
76- string_builder << RED;
77- }
78- string_builder << Util::join (raw_failure_messages, " \n " );
79- if (color_output) {
80- string_builder << RESET;
81- }
88+ string_builder << set_color (RED);
89+ string_builder << Util::join_endl (raw_failure_messages);
90+ string_builder << reset_color (); // reset the color
91+ string_builder << std::endl;
92+
8293 raw_failure_messages.clear ();
8394 baked_failure_messages.push_back (string_builder.str ());
8495}
8596
8697inline void Progress::format (const ItBase& it) {
87- if (it.get_result ().status ()) {
88- if (color_output) {
89- out_stream << GREEN;
90- }
91- out_stream << " ." ;
92- } else {
93- if (color_output) {
94- out_stream << RED;
95- }
96- out_stream << " F" ;
98+ out_stream << status_color (it.get_result ().status ());
99+ out_stream << status_char (it.get_result ().status ());
100+ out_stream << reset_color ();
101+ out_stream << std::flush;
102+
103+ if (it.get_result ().status () == Result::Status::Failure) {
97104 prep_failure (it);
98105 }
99- if (color_output) {
100- out_stream << RESET;
101- }
102- out_stream << std::flush;
103106 get_and_increment_test_counter ();
104107}
105108
0 commit comments