Skip to content

Commit 372415c

Browse files
authored
SuppressionList::ErrorMessage::fromErrorMessage() did not set file when no call stack was provided (#7386)
1 parent 0b390be commit 372415c

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

lib/suppressions.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ SuppressionList::ErrorMessage SuppressionList::ErrorMessage::fromErrorMessage(co
4848
ret.setFileName(msg.callStack.back().getfile(false));
4949
ret.lineNumber = msg.callStack.back().line;
5050
} else {
51+
ret.setFileName(msg.file0);
5152
ret.lineNumber = SuppressionList::Suppression::NO_LINE;
5253
}
5354
ret.certainty = msg.certainty;

test/testsuppressions.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ class TestSuppressions : public TestFixture {
103103
TEST_CASE(suppressionsParseXmlFile);
104104

105105
TEST_CASE(toString);
106+
107+
TEST_CASE(suppressionFromErrorMessage);
106108
}
107109

108110
void suppressionsBadId1() const {
@@ -1661,6 +1663,41 @@ class TestSuppressions : public TestFixture {
16611663
ASSERT_EQUALS("unitvar:sym", s.toString());
16621664
}
16631665
}
1666+
1667+
void suppressionFromErrorMessage() const {
1668+
{
1669+
const ErrorMessage msg({}, "test1.cpp", Severity::information, "msg", "id", Certainty::inconclusive);
1670+
const auto msg_s = SuppressionList::ErrorMessage::fromErrorMessage(msg, {"m1", "m2"});
1671+
ASSERT_EQUALS("test1.cpp", msg_s.getFileName());
1672+
ASSERT_EQUALS(SuppressionList::Suppression::NO_LINE, msg_s.lineNumber);
1673+
ASSERT_EQUALS("id", msg_s.errorId);
1674+
ASSERT_EQUALS_ENUM(Certainty::inconclusive, msg_s.certainty);
1675+
ASSERT_EQUALS("", msg_s.symbolNames);
1676+
ASSERT_EQUALS(2, msg_s.macroNames.size());
1677+
auto it = msg_s.macroNames.cbegin();
1678+
ASSERT_EQUALS("m1", *it);
1679+
++it;
1680+
ASSERT_EQUALS("m2", *it);
1681+
}
1682+
{
1683+
std::list<ErrorMessage::FileLocation> loc;
1684+
loc.emplace_back("test1.cpp", 1, 1);
1685+
const ErrorMessage msg(std::move(loc), "test1.cpp", Severity::information, "msg", "id", Certainty::normal);
1686+
const auto msg_s = SuppressionList::ErrorMessage::fromErrorMessage(msg, {});
1687+
ASSERT_EQUALS("test1.cpp", msg_s.getFileName());
1688+
ASSERT_EQUALS(1, msg_s.lineNumber);
1689+
}
1690+
{
1691+
std::list<ErrorMessage::FileLocation> loc;
1692+
loc.emplace_back("test1.cpp", 1, 1);
1693+
loc.emplace_back("test2.cpp", 2, 2);
1694+
loc.emplace_back("test3.cpp", 3, 3);
1695+
const ErrorMessage msg(std::move(loc), "test1.cpp", Severity::information, "msg", "id", Certainty::normal);
1696+
const auto msg_s = SuppressionList::ErrorMessage::fromErrorMessage(msg, {});
1697+
ASSERT_EQUALS("test3.cpp", msg_s.getFileName());
1698+
ASSERT_EQUALS(3, msg_s.lineNumber);
1699+
}
1700+
}
16641701
};
16651702

16661703
REGISTER_TEST(TestSuppressions)

0 commit comments

Comments
 (0)