@@ -50,6 +50,7 @@ class TestErrorLogger : public TestFixture {
5050 TEST_CASE (ErrorMessageVerbose);
5151 TEST_CASE (ErrorMessageVerboseLocations);
5252 TEST_CASE (ErrorMessageFromInternalError);
53+ TEST_CASE (ErrorMessageColorized);
5354 TEST_CASE (CustomFormat);
5455 TEST_CASE (CustomFormat2);
5556 TEST_CASE (CustomFormatLocations);
@@ -243,6 +244,34 @@ class TestErrorLogger : public TestFixture {
243244 ASSERT_EQUALS (" L3 FIO42-C" , msg.toString (true , format, " " ));
244245 }
245246
247+ void ErrorMessageColorized () const {
248+ const bool oDisableColors = gDisableColors ;
249+ gDisableColors = false ;
250+ setenv (" CLICOLOR_FORCE" , " 1" , 1 );
251+ std::list<ErrorMessage::FileLocation> locs = { };
252+ {
253+ ErrorMessage msg (std::move (locs), emptyString, Severity::error, " Programming error.\n Verbose error" , " errorId" ,
254+ Certainty::normal);
255+ ASSERT_EQUALS (" {bold} \x1b [31merror: Programming error." , msg.toString (false , " {bold} {severity}: {message}" ));
256+ }
257+ {
258+ ErrorMessage msg (std::move (locs), emptyString, Severity::warning, " Programming warning.\n Verbose warning" , " errorId" ,
259+ Certainty::normal);
260+ ASSERT_EQUALS (" {bold} \x1b [35mwarning: Programming warning." , msg.toString (false , " {bold} {severity}: {message}" ));
261+ }
262+ {
263+ ErrorMessage msg (std::move (locs), emptyString, Severity::style, " Style.\n Verbose style" , " errorId" , Certainty::normal);
264+ ASSERT_EQUALS (" {bold} \x1b [1mstyle: Style." , msg.toString (false , " {bold} {severity}: {message}" ));
265+ }
266+ {
267+ ErrorMessage msg (std::move (locs), emptyString, Severity::information, " Programming information.\n Programming information" ,
268+ " errorId" , Certainty::normal);
269+ ASSERT_EQUALS (" {bold} \x1b [32minformation: Programming information." , msg.toString (false , " {bold} {severity}: {message}" ));
270+ }
271+ setenv (" CLICOLOR_FORCE" , " " , 1 );
272+ gDisableColors = oDisableColors;
273+ }
274+
246275 void CustomFormat () const {
247276 std::list<ErrorMessage::FileLocation> locs (1 , fooCpp5);
248277 ErrorMessage msg (std::move (locs), " " , Severity::error, " Programming error.\n Verbose error" , " errorId" , Certainty::normal);
0 commit comments