Skip to content

Commit 153c01d

Browse files
authored
htmlreport: don't report "Source file not found" for Cppcheck Premium license messages (#8987)
1 parent a7b9e1c commit 153c01d

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎htmlreport/cppcheck-htmlreport‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,9 @@ class CppCheckHandler(XmlContentHandler):
709709
error = self.errors[-1]
710710
locations = error['locations']
711711
file = attributes['file']
712+
# Cppcheck Premium reports license messages with this pseudo file name
713+
if file == 'Cppcheck Premium':
714+
file = ''
712715
line = int(attributes['line'])
713716
if not locations:
714717
error['file'] = file

‎test/tools/htmlreport/test_htmlreport.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,25 @@ def testEscape(self):
140140

141141
output_directory.cleanup()
142142

143+
def testPremiumLicenseMessage(self):
144+
with tempfile.TemporaryDirectory() as tmpdir:
145+
xml_filename = os.path.join(tmpdir, 'premium.xml')
146+
with open(xml_filename, 'w') as f:
147+
f.write('<?xml version="1.0" encoding="UTF-8"?>\n'
148+
'<results version="2"><cppcheck version="2.18"/><errors>\n'
149+
'<error id="premium-licenseExpiresSoon" severity="information" msg="license will expire" verbose="license will expire">\n'
150+
'<location file="Cppcheck Premium" line="0" column="0"/>\n'
151+
'</error>\n'
152+
'</errors></results>\n')
153+
output_directory = os.path.join(tmpdir, 'out')
154+
p = subprocess.run([*HTML_REPORT_BIN, '--file=' + xml_filename, '--report-dir=' + output_directory],
155+
capture_output=True, text=True, check=True)
156+
self.assertNotIn('not found', p.stderr)
157+
with open(os.path.join(output_directory, 'index.html')) as index_file:
158+
report = index_file.read()
159+
self.assertIn('license will expire', report)
160+
self.assertNotIn('0.html#line-0', report)
161+
143162

144163
@contextlib.contextmanager
145164
def runCheck(source_filename=None, xml_version='1', xml_filename=None, checkers_filename=None):

0 commit comments

Comments
 (0)