Skip to content

Commit 9a563a7

Browse files
committed
test/cli: Add test for cppcheck gui project with addons
1 parent 2156dd7 commit 9a563a7

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

test/cli/test-helloworld.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,16 @@ def test_addon_relative_path():
8181
assert stderr == ('[%s:5]: (error) Division by zero.\n'
8282
'[%s:1]: (style) misra violation (use --rule-texts=<file> to get proper output)\n' % (filename, filename))
8383

84+
def test_addon_relative_path():
85+
project_file = '1-helloworld/test.cppcheck'
86+
create_gui_project_file(project_file, paths=['.'], addon='misra')
87+
ret, stdout, stderr = cppcheck('--project=%s' % (project_file))
88+
filename = os.path.join('1-helloworld', 'main.c')
89+
assert ret == 0
90+
assert stdout == 'Checking %s ...\n' % (filename)
91+
assert stderr == ('[%s:5]: (error) Division by zero.\n'
92+
'[%s:1]: (style) misra violation (use --rule-texts=<file> to get proper output)\n' % (filename, filename))
93+
8494
def test_basepath_relative_path():
8595
prjpath = getRelativeProjectPath()
8696
ret, stdout, stderr = cppcheck('%s -rp=%s' % (prjpath, prjpath))

test/cli/testutils.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import subprocess
55

66
# Create Cppcheck project file
7-
def create_gui_project_file(project_file, root_path=None, import_project=None, paths=None, exclude_paths=None, suppressions=None):
7+
def create_gui_project_file(project_file, root_path=None, import_project=None, paths=None, exclude_paths=None, suppressions=None, addon=None):
88
cppcheck_xml = ('<?xml version="1.0" encoding="UTF-8"?>\n'
99
'<project version="1">\n')
1010
if root_path:
@@ -29,6 +29,10 @@ def create_gui_project_file(project_file, root_path=None, import_project=None, p
2929
cppcheck_xml += ' fileName="' + suppression['fileName'] + '"'
3030
cppcheck_xml += '>' + suppression['id'] + '</suppression>\n'
3131
cppcheck_xml += ' </suppressions>\n'
32+
if addon:
33+
cppcheck_xml += ' <addons>\n'
34+
cppcheck_xml += ' <addon>%s</addon>\n' % (addon)
35+
cppcheck_xml += ' </addons>\n'
3236
cppcheck_xml += '</project>\n'
3337

3438
f = open(project_file, 'wt')

0 commit comments

Comments
 (0)