@@ -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,35 @@ 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+ const std::string format = " {bold} {severity}: {message}" ;
253+ {
254+ ErrorMessage msg (std::move (locs), emptyString, Severity::error, " Programming error.\n Verbose error" , " errorId" ,
255+ Certainty::normal);
256+ ASSERT_EQUALS (" {bold} \x1b [31merror: Programming error." , msg.toString (false , format, " " ));
257+ }
258+ {
259+ ErrorMessage msg (std::move (locs), emptyString, Severity::warning, " Programming warning.\n Verbose warning" , " errorId" ,
260+ Certainty::normal);
261+ ASSERT_EQUALS (" {bold} \x1b [35mwarning: Programming warning." , msg.toString (false , format, " " ));
262+ }
263+ {
264+ ErrorMessage msg (std::move (locs), emptyString, Severity::style, " Style.\n Verbose style" , " errorId" , Certainty::normal);
265+ ASSERT_EQUALS (" {bold} \x1b [1mstyle: Style." , msg.toString (false , format, " " ));
266+ }
267+ {
268+ ErrorMessage msg (std::move (locs), emptyString, Severity::information, " Programming information.\n Programming information" ,
269+ " errorId" , Certainty::normal);
270+ ASSERT_EQUALS (" {bold} \x1b [32minformation: Programming information." , msg.toString (false , format, " " ));
271+ }
272+ setenv (" CLICOLOR_FORCE" , " " , 1 );
273+ gDisableColors = oDisableColors;
274+ }
275+
246276 void CustomFormat () const {
247277 std::list<ErrorMessage::FileLocation> locs (1 , fooCpp5);
248278 ErrorMessage msg (std::move (locs), " " , Severity::error, " Programming error.\n Verbose error" , " errorId" , Certainty::normal);
0 commit comments