Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/errorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1045,12 +1045,12 @@ std::string getGuideline(const std::string &errId, ReportType reportType,
guideline = errId.substr(errId.rfind('-') + 1);
break;
case ReportType::misraCpp2008:
if (errId.rfind("misra-cpp-2008-", 0) == 0)
guideline = errId.substr(15);
if (errId.rfind("premium-misra-cpp-2008", 0) == 0)
guideline = errId.substr(23);
break;
case ReportType::misraCpp2023:
if (errId.rfind("misra-cpp-2023-", 0) == 0)
guideline = errId.substr(15);
if (errId.rfind("premium-misra-cpp-2023", 0) == 0)
guideline = errId.substr(errId.rfind('-') + 1);
Comment thread
ludviggunne marked this conversation as resolved.
break;
default:
break;
Expand Down
51 changes: 18 additions & 33 deletions test/testerrorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ class TestErrorLogger : public TestFixture {

TEST_CASE(isCriticalErrorId);

TEST_CASE(ErrorMessageReportTypeMisraC);
TEST_CASE(ErrorMessageReportTypeMisraCDirective);
TEST_CASE(ErrorMessageReportTypeCertC);
TEST_CASE(TestReportType);
}

void TestPatternSearchReplace(const std::string& idPlaceholder, const std::string& id) const {
Expand Down Expand Up @@ -316,43 +314,30 @@ class TestErrorLogger : public TestFixture {
}
}

void ErrorMessageReportTypeMisraC() const {
#define testReportType(reportType, severity, errorId, expectedClassification, expectedGuideline) \
testReportType_(__FILE__, __LINE__, reportType, severity, errorId, expectedClassification, expectedGuideline)
void testReportType_(const char *file, int line, ReportType reportType, Severity severity, const std::string &errorId,
const std::string &expectedClassification, const std::string &expectedGuideline) const
{
std::list<ErrorMessage::FileLocation> locs = { fooCpp5 };
const auto reportType = ReportType::misraC2012;
const auto mapping = createGuidelineMapping(reportType);
const std::string format = "{severity} {id}";
ErrorMessage msg(std::move(locs), emptyString, Severity::error, "", "unusedVariable", Certainty::normal);
msg.guideline = getGuideline(msg.id, reportType, mapping, msg.severity);
msg.classification = getClassification(msg.guideline, reportType);
ASSERT_EQUALS("Advisory", msg.classification);
ASSERT_EQUALS("2.8", msg.guideline);
ASSERT_EQUALS("Advisory 2.8", msg.toString(true, format, ""));
}

void ErrorMessageReportTypeMisraCDirective() const {
std::list<ErrorMessage::FileLocation> locs = { fooCpp5 };
const auto reportType = ReportType::misraC2012;
const auto mapping = createGuidelineMapping(reportType);
const std::string format = "{severity} {id}";
ErrorMessage msg(std::move(locs), emptyString, Severity::style, "", "premium-misra-c-2012-dir-4.6", Certainty::normal);
ErrorMessage msg(std::move(locs), emptyString, severity, "", errorId, Certainty::normal);
msg.guideline = getGuideline(msg.id, reportType, mapping, msg.severity);
msg.classification = getClassification(msg.guideline, reportType);
ASSERT_EQUALS("Advisory", msg.classification);
ASSERT_EQUALS("Dir 4.6", msg.guideline);
ASSERT_EQUALS("Advisory Dir 4.6", msg.toString(true, format, ""));

ASSERT_EQUALS_LOC(expectedClassification, msg.classification, file, line);
ASSERT_EQUALS_LOC(expectedGuideline, msg.guideline, file, line);
}

void ErrorMessageReportTypeCertC() const {
std::list<ErrorMessage::FileLocation> locs = { fooCpp5 };
const auto reportType = ReportType::certC;
const auto mapping = createGuidelineMapping(reportType);
const std::string format = "{severity} {id}";
ErrorMessage msg(std::move(locs), emptyString, Severity::error, "", "resourceLeak", Certainty::normal);
msg.guideline = getGuideline(msg.id, reportType, mapping, msg.severity);
msg.classification = getClassification(msg.guideline, reportType);
ASSERT_EQUALS("L3", msg.classification);
ASSERT_EQUALS("FIO42-C", msg.guideline);
ASSERT_EQUALS("L3 FIO42-C", msg.toString(true, format, ""));
void TestReportType() const {
testReportType(ReportType::misraC2012, Severity::error, "unusedVariable", "Advisory", "2.8");
testReportType(ReportType::misraCpp2023, Severity::warning, "premium-misra-cpp-2023-6.8.4", "Advisory", "6.8.4");
testReportType(ReportType::misraCpp2023, Severity::style, "premium-misra-cpp-2023-19.6.1", "Advisory", "19.6.1");
testReportType(ReportType::misraCpp2008, Severity::style, "premium-misra-cpp-2008-3-4-1", "Required", "3-4-1");
testReportType(ReportType::misraC2012, Severity::style, "premium-misra-c-2012-dir-4.6", "Advisory", "Dir 4.6");
testReportType(ReportType::misraC2012, Severity::style, "misra-c2012-dir-4.6", "Advisory", "Dir 4.6");
testReportType(ReportType::certC, Severity::error, "resourceLeak", "L3", "FIO42-C");
}

void CustomFormat() const {
Expand Down
Loading