Skip to content
Open
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
1 change: 1 addition & 0 deletions lib/errorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,7 @@ ErrorMessage::ErrorMessage(const tinyxml2::XMLElement * const errmsg)
callStack.front().setfile(file);
} else if (std::strcmp(name,"symbol")==0) {
mSymbolNames += e->GetText();
mSymbolNames += '\n';
}
}
}
Expand Down
63 changes: 63 additions & 0 deletions test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3794,6 +3794,69 @@ def test_suppress_unmatched_wildcard_cached(tmp_path): # #14585
assert stderr.splitlines() == stderr_exp


def __test_suppress_xml_symbolname(tmp_path, extra_args):
test_file = tmp_path / 'test.cpp'
with open(test_file, 'wt') as f:
f.write(
"""struct Base {
void init() {}
};
struct Derived : Base {
void init() {}
};
""")

suppr_file = tmp_path / 'suppr.xml'
with open(suppr_file, 'wt') as f:
f.write(
"""<?xml version="1.0"?>
<suppressions>
<suppress>
<id>duplInheritedMember</id>
<symbolName>init</symbolName>
</suppress>
</suppressions>
""")

args = [
'-q',
'--template=simple',
'--enable=warning',
'--suppress-xml={}'.format(suppr_file),
str(test_file)
]

args += extra_args

exitcode, stdout, stderr = cppcheck(args)
assert exitcode == 0, stdout
assert stdout.splitlines() == []
assert stderr.splitlines() == []


def test_suppress_xml_symbolname(tmp_path):
__test_suppress_xml_symbolname(tmp_path, ['-j1'])


def test_suppress_xml_symbolname_j(tmp_path):
__test_suppress_xml_symbolname(tmp_path, ['-j2'])


def test_suppress_xml_symbolname_builddir_cached(tmp_path):
build_dir = tmp_path / 'b1'
os.mkdir(build_dir)
__test_suppress_xml_symbolname(tmp_path, ['--cppcheck-build-dir={}'.format(build_dir), '-j1'])
__test_suppress_xml_symbolname(tmp_path, ['--cppcheck-build-dir={}'.format(build_dir), '-j1'])


def test_suppress_xml_symbolname_builddir_j_cached(tmp_path):
# the symbol names of results loaded from the build dir must still match the suppression
build_dir = tmp_path / 'b1'
os.mkdir(build_dir)
__test_suppress_xml_symbolname(tmp_path, ['--cppcheck-build-dir={}'.format(build_dir), '-j2'])
__test_suppress_xml_symbolname(tmp_path, ['--cppcheck-build-dir={}'.format(build_dir), '-j2'])


def test_suppress_unmatched_wildcard_unchecked(tmp_path):
# make sure that unmatched wildcards suppressions are reported if files matching the expressions were processesd
# but isSuppressed() has never been called (i.e. no findings in file at all)
Expand Down
15 changes: 15 additions & 0 deletions test/testerrorlogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class TestErrorLogger : public TestFixture {
TEST_CASE(ToXmlLocations);
TEST_CASE(ToXmlV2Encoding);
TEST_CASE(FromXmlV2);
TEST_CASE(FromXmlSymbolNames);
TEST_CASE(ToXmlV3);

// Inconclusive results in xml reports..
Expand Down Expand Up @@ -601,6 +602,20 @@ class TestErrorLogger : public TestFixture {
ASSERT_EQUALS(1u, msg.callStack.back().column);
}

void FromXmlSymbolNames() const {
// symbol names must survive a toXML() / XML constructor round trip (as done for results cached in the build dir)
const ErrorMessage msg({}, "", Severity::warning, "$symbol:sym1\n$symbol:sym2\nmessage $symbol", "id", Certainty::normal);
ASSERT_EQUALS("sym1\nsym2\n", msg.symbolNames());

const std::string xmldata = msg.toXML();
tinyxml2::XMLDocument doc;
ASSERT(doc.Parse(xmldata.c_str(), xmldata.size()) == tinyxml2::XML_SUCCESS);
const auto * const rootnode = doc.FirstChildElement();
ASSERT(rootnode);
const ErrorMessage msg2(rootnode);
ASSERT_EQUALS(msg.symbolNames(), msg2.symbolNames());
}

void ToXmlV3() const {
std::string header("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<results version=\"3\">\n");
header += " <cppcheck version=\"";
Expand Down