Skip to content

Commit d18736c

Browse files
committed
add errorlogger tests
1 parent 7c26e3f commit d18736c

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

test/testerrorlogger.cpp

+29
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ class TestErrorLogger : public TestFixture {
7070
TEST_CASE(substituteTemplateLocationStatic);
7171

7272
TEST_CASE(isCriticalErrorId);
73+
74+
TEST_CASE(ErrorMessageReportTypeMisraC);
75+
TEST_CASE(ErrorMessageReportTypeCertC);
7376
}
7477

7578
void TestPatternSearchReplace(const std::string& idPlaceholder, const std::string& id) const {
@@ -194,6 +197,32 @@ class TestErrorLogger : public TestFixture {
194197
}
195198
}
196199

200+
void ErrorMessageReportTypeMisraC() const {
201+
std::list<ErrorMessage::FileLocation> locs = { fooCpp5 };
202+
const auto reportType = checkers::ReportType::misraC;
203+
const auto mapping = checkers::createGuidelineMapping(reportType);
204+
const std::string format = "{severity} {id}";
205+
ErrorMessage msg(std::move(locs), emptyString, Severity::error, "", "unusedVariable", Certainty::normal);
206+
msg.guideline = checkers::getGuideline(msg.id, reportType, mapping, msg.severity);
207+
msg.classification = checkers::getClassification(msg.guideline, reportType);
208+
ASSERT_EQUALS("Advisory", msg.classification);
209+
ASSERT_EQUALS("2.8", msg.guideline);
210+
ASSERT_EQUALS("Advisory 2.8", msg.toString(true, format));
211+
}
212+
213+
void ErrorMessageReportTypeCertC() const {
214+
std::list<ErrorMessage::FileLocation> locs = { fooCpp5 };
215+
const auto reportType = checkers::ReportType::certC;
216+
const auto mapping = checkers::createGuidelineMapping(reportType);
217+
const std::string format = "{severity} {id}";
218+
ErrorMessage msg(std::move(locs), emptyString, Severity::error, "", "resourceLeak", Certainty::normal);
219+
msg.guideline = checkers::getGuideline(msg.id, reportType, mapping, msg.severity);
220+
msg.classification = checkers::getClassification(msg.guideline, reportType);
221+
ASSERT_EQUALS("L3", msg.classification);
222+
ASSERT_EQUALS("FIO42-C", msg.guideline);
223+
ASSERT_EQUALS("L3 FIO42-C", msg.toString(true, format));
224+
}
225+
197226
void CustomFormat() const {
198227
std::list<ErrorMessage::FileLocation> locs(1, fooCpp5);
199228
ErrorMessage msg(std::move(locs), emptyString, Severity::error, "Programming error.\nVerbose error", "errorId", Certainty::normal);

0 commit comments

Comments
 (0)