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