@@ -55,6 +55,7 @@ class TestErrorLogger : public TestFixture {
5555 TEST_CASE (ErrorMessageVerboseNewline);
5656 TEST_CASE (ErrorMessageFromInternalError);
5757 TEST_CASE (ErrorMessageCode);
58+ TEST_CASE (ErrorMessageNoCode);
5859 TEST_CASE (CustomFormat);
5960 TEST_CASE (CustomFormat2);
6061 TEST_CASE (CustomFormatLocations);
@@ -386,6 +387,22 @@ class TestErrorLogger : public TestFixture {
386387 msg.toString (false , " {file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]\n {code}" , " " ));
387388 }
388389
390+ void ErrorMessageNoCode () const {
391+ ScopedFile file (" code.cpp" ,
392+ " int i;\n "
393+ " int i2;\n "
394+ " int i3;\n "
395+ );
396+
397+ ErrorMessage::FileLocation code{" code.cpp" , 3 , 5 };
398+ std::list<ErrorMessage::FileLocation> locs = { code };
399+ ErrorMessage msg (std::move (locs), " " , Severity::error, " Programming error.\n Verbose error" , " errorId" , Certainty::normal);
400+ ASSERT_EQUALS (1 , msg.callStack .size ());
401+ const bool noCode = true ;
402+ ASSERT_EQUALS (" code.cpp:3:5: error: Programming error. [errorId]\n " ,
403+ msg.toString (false , " {file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]\n {code}" , " " , noCode));
404+ }
405+
389406 void CustomFormat () const {
390407 std::list<ErrorMessage::FileLocation> locs (1 , fooCpp5);
391408 ErrorMessage msg (std::move (locs), " " , Severity::error, " Programming error.\n Verbose error" , " errorId" , Certainty::normal);
0 commit comments