test/cli: test function that creates gui project file
This commit is contained in:
parent
58f886c725
commit
a03455c505
|
@ -52,6 +52,38 @@ def getVsConfigs(stdout, filename):
|
||||||
ret.sort()
|
ret.sort()
|
||||||
return ' '.join(ret)
|
return ' '.join(ret)
|
||||||
|
|
||||||
|
# Create Cppcheck project file
|
||||||
|
def create_gui_project_file(project_file, root_path=None, import_project=None, paths=None, exclude_paths=None, suppressions=None):
|
||||||
|
cppcheck_xml = ('<?xml version="1.0" encoding="UTF-8"?>\n'
|
||||||
|
'<project version="1">\n')
|
||||||
|
if root_path:
|
||||||
|
cppcheck_xml += ' <root name="' + root_path + '"/>\n'
|
||||||
|
if import_project:
|
||||||
|
cppcheck_xml += ' <importproject>' + import_project + '</importproject>\n'
|
||||||
|
if paths:
|
||||||
|
cppcheck_xml += ' <paths>\n'
|
||||||
|
for path in paths:
|
||||||
|
cppcheck_xml += ' <dir name="' + path + '"/>\n'
|
||||||
|
cppcheck_xml += ' </paths>\n'
|
||||||
|
if exclude_paths:
|
||||||
|
cppcheck_xml += ' <exclude>\n'
|
||||||
|
for path in exclude_paths:
|
||||||
|
cppcheck_xml += ' <path name="' + path + '"/>\n'
|
||||||
|
cppcheck_xml += ' </exclude>\n'
|
||||||
|
if suppressions:
|
||||||
|
cppcheck_xml += ' <suppressions>\n'
|
||||||
|
for suppression in suppressions:
|
||||||
|
cppcheck_xml += ' <suppression'
|
||||||
|
if 'fileName' in suppression:
|
||||||
|
cppcheck_xml += ' fileName="' + suppression['fileName'] + '"'
|
||||||
|
cppcheck_xml += '>' + suppression['id'] + '</suppression>\n'
|
||||||
|
cppcheck_xml += ' </suppressions>\n'
|
||||||
|
cppcheck_xml += '</project>\n'
|
||||||
|
|
||||||
|
f = open(project_file, 'wt')
|
||||||
|
f.write(cppcheck_xml)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
def test_relative_path():
|
def test_relative_path():
|
||||||
ret, stdout, stderr = cppcheck('1-helloworld')
|
ret, stdout, stderr = cppcheck('1-helloworld')
|
||||||
|
@ -172,19 +204,10 @@ def test_suppress_command_line():
|
||||||
assert stderr == ''
|
assert stderr == ''
|
||||||
|
|
||||||
def test_suppress_project():
|
def test_suppress_project():
|
||||||
cppcheck_xml = ('<?xml version="1.0" encoding="UTF-8"?>'
|
|
||||||
'<project version="1">'
|
|
||||||
' <paths>'
|
|
||||||
' <dir name="."/>'
|
|
||||||
' </paths>'
|
|
||||||
' <suppressions>'
|
|
||||||
' <suppression fileName="main.c">zerodiv</suppression>'
|
|
||||||
' </suppressions>'
|
|
||||||
'</project>')
|
|
||||||
project_file = os.path.join('1-helloworld', 'test.cppcheck')
|
project_file = os.path.join('1-helloworld', 'test.cppcheck')
|
||||||
f = open(project_file, 'wt')
|
create_gui_project_file(project_file,
|
||||||
f.write(cppcheck_xml)
|
paths=['.'],
|
||||||
f.close()
|
suppressions=[{'fileName':'main.c', 'id':'zerodiv'}])
|
||||||
|
|
||||||
# Relative path
|
# Relative path
|
||||||
ret, stdout, stderr = cppcheck('--project=%s' % (project_file))
|
ret, stdout, stderr = cppcheck('--project=%s' % (project_file))
|
||||||
|
|
|
@ -15,6 +15,40 @@ def create_compile_commands():
|
||||||
f = open(COMPILE_COMMANDS_JSON, 'wt')
|
f = open(COMPILE_COMMANDS_JSON, 'wt')
|
||||||
f.write(json.dumps(j))
|
f.write(json.dumps(j))
|
||||||
|
|
||||||
|
|
||||||
|
# Create Cppcheck project file
|
||||||
|
def create_gui_project_file(project_file, root_path=None, import_project=None, paths=None, exclude_paths=None, suppressions=None):
|
||||||
|
cppcheck_xml = ('<?xml version="1.0" encoding="UTF-8"?>\n'
|
||||||
|
'<project version="1">\n')
|
||||||
|
if root_path:
|
||||||
|
cppcheck_xml += ' <root name="' + root_path + '"/>\n'
|
||||||
|
if import_project:
|
||||||
|
cppcheck_xml += ' <importproject>' + import_project + '</importproject>\n'
|
||||||
|
if paths:
|
||||||
|
cppcheck_xml += ' <paths>\n'
|
||||||
|
for path in paths:
|
||||||
|
cppcheck_xml += ' <dir name="' + path + '"/>\n'
|
||||||
|
cppcheck_xml += ' </paths>\n'
|
||||||
|
if exclude_paths:
|
||||||
|
cppcheck_xml += ' <exclude>\n'
|
||||||
|
for path in exclude_paths:
|
||||||
|
cppcheck_xml += ' <path name="' + path + '"/>\n'
|
||||||
|
cppcheck_xml += ' </exclude>\n'
|
||||||
|
if suppressions:
|
||||||
|
cppcheck_xml += ' <suppressions>\n'
|
||||||
|
for suppression in suppressions:
|
||||||
|
cppcheck_xml += ' <suppression'
|
||||||
|
if 'fileName' in suppression:
|
||||||
|
cppcheck_xml += ' fileName="' + suppression['fileName'] + '"'
|
||||||
|
cppcheck_xml += '>' + suppression['id'] + '</suppression>\n'
|
||||||
|
cppcheck_xml += ' </suppressions>\n'
|
||||||
|
cppcheck_xml += '</project>\n'
|
||||||
|
|
||||||
|
f = open(project_file, 'wt')
|
||||||
|
f.write(cppcheck_xml)
|
||||||
|
f.close()
|
||||||
|
|
||||||
|
|
||||||
# Run Cppcheck with args
|
# Run Cppcheck with args
|
||||||
def cppcheck(args):
|
def cppcheck(args):
|
||||||
if os.path.isfile('../../bin/debug/cppcheck.exe'):
|
if os.path.isfile('../../bin/debug/cppcheck.exe'):
|
||||||
|
@ -83,20 +117,24 @@ def test_gui_project_loads_compile_commands_1():
|
||||||
|
|
||||||
def test_gui_project_loads_compile_commands_2():
|
def test_gui_project_loads_compile_commands_2():
|
||||||
create_compile_commands()
|
create_compile_commands()
|
||||||
|
exclude_path_1 = os.path.join(os.getcwd(), 'proj2', 'b').replace('\\', '/')
|
||||||
# create cppcheck gui project file
|
create_gui_project_file('proj2/test.cppcheck',
|
||||||
cppcheck_xml = ('<?xml version="1.0" encoding="UTF-8"?>'
|
import_project='compile_commands.json',
|
||||||
'<project version="1">'
|
exclude_paths=[exclude_path_1])
|
||||||
' <root name="."/>'
|
ret, stdout, stderr = cppcheck('--project=proj2/test.cppcheck')
|
||||||
' <importproject>compile_commands.json</importproject>'
|
cwd = os.getcwd()
|
||||||
' <exclude>'
|
file1 = os.path.join(cwd, 'proj2', 'a', 'a.c')
|
||||||
' <path name="' + os.path.join(os.getcwd(), 'proj2', 'b').replace('\\', '/') + '"/>'
|
file2 = os.path.join(cwd, 'proj2', 'b', 'b.c') # Excluded by test.cppcheck
|
||||||
' </exclude>'
|
assert ret == 0
|
||||||
'</project>')
|
assert stdout.find('Checking %s ...' % (file1)) >= 0
|
||||||
f = open('proj2/test.cppcheck', 'wt')
|
assert stdout.find('Checking %s ...' % (file2)) < 0
|
||||||
f.write(cppcheck_xml)
|
|
||||||
f.close()
|
def test_gui_project_loads_compile_commands_2():
|
||||||
|
create_compile_commands()
|
||||||
|
exclude_path_1 = os.path.join(os.getcwd(), 'proj2', 'b').replace('\\', '/')
|
||||||
|
create_gui_project_file('proj2/test.cppcheck',
|
||||||
|
import_project='compile_commands.json',
|
||||||
|
exclude_paths=[exclude_path_1])
|
||||||
ret, stdout, stderr = cppcheck('--project=proj2/test.cppcheck')
|
ret, stdout, stderr = cppcheck('--project=proj2/test.cppcheck')
|
||||||
cwd = os.getcwd()
|
cwd = os.getcwd()
|
||||||
file1 = os.path.join(cwd, 'proj2', 'a', 'a.c')
|
file1 = os.path.join(cwd, 'proj2', 'a', 'a.c')
|
||||||
|
|
Loading…
Reference in New Issue