@@ -52,6 +52,7 @@ class TestErrorLogger : public TestFixture {
5252 TEST_CASE (ErrorMessageVerbose);
5353 TEST_CASE (ErrorMessageVerboseLocations);
5454 TEST_CASE (ErrorMessageFromInternalError);
55+ TEST_CASE (ErrorMessageColorized);
5556 TEST_CASE (CustomFormat);
5657 TEST_CASE (CustomFormat2);
5758 TEST_CASE (CustomFormatLocations);
@@ -342,6 +343,34 @@ class TestErrorLogger : public TestFixture {
342343 testReportType (ReportType::certC, Severity::error, " resourceLeak" , " L3" , " FIO42-C" );
343344 }
344345
346+ void ErrorMessageColorized () const {
347+ const bool oDisableColors = gDisableColors ;
348+ gDisableColors = false ;
349+ setenv (" CLICOLOR_FORCE" , " 1" , 1 );
350+ std::list<ErrorMessage::FileLocation> locs = { };
351+ {
352+ ErrorMessage msg (std::move (locs), emptyString, Severity::error, " Programming error.\n Verbose error" , " errorId" ,
353+ Certainty::normal);
354+ ASSERT_EQUALS (" {bold} \x1b [31merror: Programming error." , msg.toString (false , " {bold} {severity}: {message}" , " " ));
355+ }
356+ {
357+ ErrorMessage msg (std::move (locs), emptyString, Severity::warning, " Programming warning.\n Verbose warning" , " errorId" ,
358+ Certainty::normal);
359+ ASSERT_EQUALS (" {bold} \x1b [35mwarning: Programming warning." , msg.toString (false , " {bold} {severity}: {message}" , " " ));
360+ }
361+ {
362+ ErrorMessage msg (std::move (locs), emptyString, Severity::style, " Style.\n Verbose style" , " errorId" , Certainty::normal);
363+ ASSERT_EQUALS (" {bold} \x1b [1mstyle: Style." , msg.toString (false , " {bold} {severity}: {message}" , " " ));
364+ }
365+ {
366+ ErrorMessage msg (std::move (locs), emptyString, Severity::information, " Programming information.\n Programming information" ,
367+ " errorId" , Certainty::normal);
368+ ASSERT_EQUALS (" {bold} \x1b [32minformation: Programming information." , msg.toString (false , " {bold} {severity}: {message}" , " " ));
369+ }
370+ setenv (" CLICOLOR_FORCE" , " " , 1 );
371+ gDisableColors = oDisableColors;
372+ }
373+
345374 void CustomFormat () const {
346375 std::list<ErrorMessage::FileLocation> locs (1 , fooCpp5);
347376 ErrorMessage msg (std::move (locs), " " , Severity::error, " Programming error.\n Verbose error" , " errorId" , Certainty::normal);
0 commit comments