Skip to content

Commit 61252d8

Browse files
authored
fix #13964: ErrorLogger: Invalid/missing guideline/classification with --report-type=misra-cpp-2023 (#7624)
1 parent 9863804 commit 61252d8

File tree

2 files changed

+22
-37
lines changed

2 files changed

+22
-37
lines changed

lib/errorlogger.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,12 +1045,12 @@ std::string getGuideline(const std::string &errId, ReportType reportType,
10451045
guideline = errId.substr(errId.rfind('-') + 1);
10461046
break;
10471047
case ReportType::misraCpp2008:
1048-
if (errId.rfind("misra-cpp-2008-", 0) == 0)
1049-
guideline = errId.substr(15);
1048+
if (errId.rfind("premium-misra-cpp-2008", 0) == 0)
1049+
guideline = errId.substr(23);
10501050
break;
10511051
case ReportType::misraCpp2023:
1052-
if (errId.rfind("misra-cpp-2023-", 0) == 0)
1053-
guideline = errId.substr(15);
1052+
if (errId.rfind("premium-misra-cpp-2023", 0) == 0)
1053+
guideline = errId.substr(errId.rfind('-') + 1);
10541054
break;
10551055
default:
10561056
break;

test/testerrorlogger.cpp

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,7 @@ class TestErrorLogger : public TestFixture {
7777

7878
TEST_CASE(isCriticalErrorId);
7979

80-
TEST_CASE(ErrorMessageReportTypeMisraC);
81-
TEST_CASE(ErrorMessageReportTypeMisraCDirective);
82-
TEST_CASE(ErrorMessageReportTypeCertC);
80+
TEST_CASE(TestReportType);
8381
}
8482

8583
void TestPatternSearchReplace(const std::string& idPlaceholder, const std::string& id) const {
@@ -316,43 +314,30 @@ class TestErrorLogger : public TestFixture {
316314
}
317315
}
318316

319-
void ErrorMessageReportTypeMisraC() const {
317+
#define testReportType(reportType, severity, errorId, expectedClassification, expectedGuideline) \
318+
testReportType_(__FILE__, __LINE__, reportType, severity, errorId, expectedClassification, expectedGuideline)
319+
void testReportType_(const char *file, int line, ReportType reportType, Severity severity, const std::string &errorId,
320+
const std::string &expectedClassification, const std::string &expectedGuideline) const
321+
{
320322
std::list<ErrorMessage::FileLocation> locs = { fooCpp5 };
321-
const auto reportType = ReportType::misraC2012;
322323
const auto mapping = createGuidelineMapping(reportType);
323-
const std::string format = "{severity} {id}";
324-
ErrorMessage msg(std::move(locs), emptyString, Severity::error, "", "unusedVariable", Certainty::normal);
325-
msg.guideline = getGuideline(msg.id, reportType, mapping, msg.severity);
326-
msg.classification = getClassification(msg.guideline, reportType);
327-
ASSERT_EQUALS("Advisory", msg.classification);
328-
ASSERT_EQUALS("2.8", msg.guideline);
329-
ASSERT_EQUALS("Advisory 2.8", msg.toString(true, format, ""));
330-
}
331324

332-
void ErrorMessageReportTypeMisraCDirective() const {
333-
std::list<ErrorMessage::FileLocation> locs = { fooCpp5 };
334-
const auto reportType = ReportType::misraC2012;
335-
const auto mapping = createGuidelineMapping(reportType);
336-
const std::string format = "{severity} {id}";
337-
ErrorMessage msg(std::move(locs), emptyString, Severity::style, "", "premium-misra-c-2012-dir-4.6", Certainty::normal);
325+
ErrorMessage msg(std::move(locs), emptyString, severity, "", errorId, Certainty::normal);
338326
msg.guideline = getGuideline(msg.id, reportType, mapping, msg.severity);
339327
msg.classification = getClassification(msg.guideline, reportType);
340-
ASSERT_EQUALS("Advisory", msg.classification);
341-
ASSERT_EQUALS("Dir 4.6", msg.guideline);
342-
ASSERT_EQUALS("Advisory Dir 4.6", msg.toString(true, format, ""));
328+
329+
ASSERT_EQUALS_LOC(expectedClassification, msg.classification, file, line);
330+
ASSERT_EQUALS_LOC(expectedGuideline, msg.guideline, file, line);
343331
}
344332

345-
void ErrorMessageReportTypeCertC() const {
346-
std::list<ErrorMessage::FileLocation> locs = { fooCpp5 };
347-
const auto reportType = ReportType::certC;
348-
const auto mapping = createGuidelineMapping(reportType);
349-
const std::string format = "{severity} {id}";
350-
ErrorMessage msg(std::move(locs), emptyString, Severity::error, "", "resourceLeak", Certainty::normal);
351-
msg.guideline = getGuideline(msg.id, reportType, mapping, msg.severity);
352-
msg.classification = getClassification(msg.guideline, reportType);
353-
ASSERT_EQUALS("L3", msg.classification);
354-
ASSERT_EQUALS("FIO42-C", msg.guideline);
355-
ASSERT_EQUALS("L3 FIO42-C", msg.toString(true, format, ""));
333+
void TestReportType() const {
334+
testReportType(ReportType::misraC2012, Severity::error, "unusedVariable", "Advisory", "2.8");
335+
testReportType(ReportType::misraCpp2023, Severity::warning, "premium-misra-cpp-2023-6.8.4", "Advisory", "6.8.4");
336+
testReportType(ReportType::misraCpp2023, Severity::style, "premium-misra-cpp-2023-19.6.1", "Advisory", "19.6.1");
337+
testReportType(ReportType::misraCpp2008, Severity::style, "premium-misra-cpp-2008-3-4-1", "Required", "3-4-1");
338+
testReportType(ReportType::misraC2012, Severity::style, "premium-misra-c-2012-dir-4.6", "Advisory", "Dir 4.6");
339+
testReportType(ReportType::misraC2012, Severity::style, "misra-c2012-dir-4.6", "Advisory", "Dir 4.6");
340+
testReportType(ReportType::certC, Severity::error, "resourceLeak", "L3", "FIO42-C");
356341
}
357342

358343
void CustomFormat() const {

0 commit comments

Comments
 (0)