Skip to content

Commit f9a7db2

Browse files
committed
TestErrorLogger: added test for {code}
1 parent dceadd2 commit f9a7db2

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

test/testerrorlogger.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class TestErrorLogger : public TestFixture {
5454
TEST_CASE(ErrorMessageVerboseSymbol);
5555
TEST_CASE(ErrorMessageVerboseNewline);
5656
TEST_CASE(ErrorMessageFromInternalError);
57+
TEST_CASE(ErrorMessageCode);
5758
TEST_CASE(CustomFormat);
5859
TEST_CASE(CustomFormat2);
5960
TEST_CASE(CustomFormatLocations);
@@ -364,6 +365,25 @@ class TestErrorLogger : public TestFixture {
364365
testReportType(ReportType::certC, Severity::error, "resourceLeak", "L3", "FIO42-C");
365366
}
366367

368+
void ErrorMessageCode() const {
369+
ScopedFile file("code.cpp",
370+
"int i;\n"
371+
"int i2;\n"
372+
"int i3;\n"
373+
);
374+
375+
ErrorMessage::FileLocation codeCpp3_5{"code.cpp", 3, 5};
376+
std::list<ErrorMessage::FileLocation> locs = { codeCpp3_5 };
377+
ErrorMessage msg(std::move(locs), "", Severity::error, "Programming error.\nVerbose error", "errorId", Certainty::normal);
378+
ASSERT_EQUALS(1, msg.callStack.size());
379+
ASSERT_EQUALS("Programming error.", msg.shortMessage());
380+
ASSERT_EQUALS("Verbose error", msg.verboseMessage());
381+
ASSERT_EQUALS("code.cpp:3:5: error: Programming error. [errorId]\n"
382+
"int i3;\n"
383+
" ^",
384+
msg.toString(false, "{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]\n{code}", ""));
385+
}
386+
367387
void CustomFormat() const {
368388
std::list<ErrorMessage::FileLocation> locs(1, fooCpp5);
369389
ErrorMessage msg(std::move(locs), "", Severity::error, "Programming error.\nVerbose error", "errorId", Certainty::normal);

0 commit comments

Comments
 (0)