Refactor test/cli/test-proj2.py
This commit is contained in:
parent
7700cff0e9
commit
9e9bb9f804
|
@ -91,6 +91,7 @@ test_script:
|
|||
- cd test\cli
|
||||
- python -m pytest test-helloworld.py
|
||||
- python -m pytest test-inline-suppress.py
|
||||
- python -m pytest test-proj2.py
|
||||
- python -m pytest test-suppress-syntaxError.py
|
||||
- 'IF defined cygwin_build C:\cygwin64\bin\bash -e -l -c "cd /cygdrive/c/projects/cppcheck && make clean && make -j 2 && make test && make checkcfg"'
|
||||
|
||||
|
|
|
@ -5,20 +5,22 @@ import json
|
|||
import os
|
||||
from testutils import create_gui_project_file, cppcheck
|
||||
|
||||
COMPILE_COMMANDS_JSON = os.path.join('proj2', 'compile_commands.json')
|
||||
COMPILE_COMMANDS_JSON = 'compile_commands.json'
|
||||
|
||||
ERR_A = ('a/a.c:1:7: error: Division by zero. [zerodiv]\n' +
|
||||
ERR_A = ('%s:1:7: error: Division by zero. [zerodiv]\n' +
|
||||
'x = 3 / 0;\n' +
|
||||
' ^\n')
|
||||
ERR_B = ('b/b.c:1:7: error: Division by zero. [zerodiv]\n' +
|
||||
' ^\n') % os.path.join('a', 'a.c')
|
||||
ERR_B = ('%s:1:7: error: Division by zero. [zerodiv]\n' +
|
||||
'x = 3 / 0;\n' +
|
||||
' ^\n')
|
||||
' ^\n') % os.path.join('b', 'b.c')
|
||||
|
||||
def realpath(s):
|
||||
return os.path.realpath(s).replace('\\', '/')
|
||||
|
||||
def create_compile_commands():
|
||||
prjpath = os.path.join(os.getcwd(), 'proj2')
|
||||
j = [{'directory': os.path.join(prjpath,'a'), 'command': 'gcc -c a.c', 'file': 'a.c'},
|
||||
{'directory': os.path.join(prjpath,'b'), 'command': 'gcc -c b.c', 'file': 'b.c'}]
|
||||
f = open(COMPILE_COMMANDS_JSON, 'wt')
|
||||
j = [{'directory': realpath('proj2/a'), 'command': 'gcc -c a.c', 'file': 'a.c'},
|
||||
{'directory': realpath('proj2/b'), 'command': 'gcc -c b.c', 'file': 'b.c'}]
|
||||
f = open('proj2/' + COMPILE_COMMANDS_JSON, 'wt')
|
||||
f.write(json.dumps(j))
|
||||
|
||||
# Run Cppcheck from project path
|
||||
|
@ -34,82 +36,75 @@ def test_file_filter():
|
|||
file1 = os.path.join('proj2', 'a', 'a.c')
|
||||
file2 = os.path.join('proj2', 'b', 'b.c')
|
||||
assert ret == 0
|
||||
assert stdout.find('Checking %s ...' % (file1)) >= 0
|
||||
assert stdout.find('Checking %s ...' % file1) >= 0
|
||||
ret, stdout, stderr = cppcheck(['proj2/','--file-filter=proj2/b*'])
|
||||
assert ret == 0
|
||||
assert stdout.find('Checking %s ...' % (file2)) >= 0
|
||||
assert stdout.find('Checking %s ...' % file2) >= 0
|
||||
|
||||
def test_local_path():
|
||||
create_compile_commands()
|
||||
ret, stdout, stderr = cppcheck_local(['--project=compile_commands.json'])
|
||||
cwd = os.getcwd()
|
||||
file1 = os.path.join(cwd, 'proj2', 'a', 'a.c')
|
||||
file2 = os.path.join(cwd, 'proj2', 'b', 'b.c')
|
||||
file1 = os.path.realpath('proj2/a/a.c')
|
||||
file2 = os.path.realpath('proj2/b/b.c')
|
||||
assert ret == 0
|
||||
assert stdout.find('Checking %s ...' % (file1)) >= 0
|
||||
assert stdout.find('Checking %s ...' % (file2)) >= 0
|
||||
assert stdout.find('Checking %s ...' % file1) >= 0
|
||||
assert stdout.find('Checking %s ...' % file2) >= 0
|
||||
|
||||
def test_local_path_force():
|
||||
create_compile_commands()
|
||||
ret, stdout, stderr = cppcheck_local(['--project=compile_commands.json', '--force'])
|
||||
cwd = os.getcwd()
|
||||
file1 = os.path.join(cwd, 'proj2', 'a', 'a.c')
|
||||
file2 = os.path.join(cwd, 'proj2', 'b', 'b.c')
|
||||
file1 = os.path.realpath('proj2/a/a.c')
|
||||
file2 = os.path.realpath('proj2/b/b.c')
|
||||
assert ret == 0
|
||||
assert stdout.find('AAA') >= 0
|
||||
|
||||
def test_local_path_maxconfigs():
|
||||
create_compile_commands()
|
||||
ret, stdout, stderr = cppcheck_local(['--project=compile_commands.json', '--max-configs=2'])
|
||||
cwd = os.getcwd()
|
||||
file1 = os.path.join(cwd, 'proj2', 'a', 'a.c')
|
||||
file2 = os.path.join(cwd, 'proj2', 'b', 'b.c')
|
||||
file1 = os.path.realpath('proj2/a/a.c')
|
||||
file2 = os.path.realpath('proj2/b/b.c')
|
||||
assert ret == 0
|
||||
assert stdout.find('AAA') >= 0
|
||||
|
||||
def test_relative_path():
|
||||
create_compile_commands()
|
||||
ret, stdout, stderr = cppcheck(['--project=' + COMPILE_COMMANDS_JSON])
|
||||
cwd = os.getcwd()
|
||||
file1 = os.path.join(cwd, 'proj2', 'a', 'a.c')
|
||||
file2 = os.path.join(cwd, 'proj2', 'b', 'b.c')
|
||||
ret, stdout, stderr = cppcheck(['--project=proj2/' + COMPILE_COMMANDS_JSON])
|
||||
file1 = os.path.realpath('proj2/a/a.c')
|
||||
file2 = os.path.realpath('proj2/b/b.c')
|
||||
assert ret == 0
|
||||
assert stdout.find('Checking %s ...' % (file1)) >= 0
|
||||
assert stdout.find('Checking %s ...' % (file2)) >= 0
|
||||
assert stdout.find('Checking %s ...' % file1) >= 0
|
||||
assert stdout.find('Checking %s ...' % file2) >= 0
|
||||
|
||||
def test_absolute_path():
|
||||
create_compile_commands()
|
||||
cwd = os.getcwd()
|
||||
ret, stdout, stderr = cppcheck(['--project=' + os.path.join(cwd,COMPILE_COMMANDS_JSON)])
|
||||
file1 = os.path.join(cwd, 'proj2', 'a', 'a.c')
|
||||
file2 = os.path.join(cwd, 'proj2', 'b', 'b.c')
|
||||
ret, stdout, stderr = cppcheck(['--project=' + os.path.realpath('proj2/' + COMPILE_COMMANDS_JSON)])
|
||||
file1 = os.path.realpath('proj2/a/a.c')
|
||||
file2 = os.path.realpath('proj2/b/b.c')
|
||||
assert ret == 0
|
||||
assert stdout.find('Checking %s ...' % (file1)) >= 0
|
||||
assert stdout.find('Checking %s ...' % (file2)) >= 0
|
||||
assert stdout.find('Checking %s ...' % file1) >= 0
|
||||
assert stdout.find('Checking %s ...' % file2) >= 0
|
||||
|
||||
def test_gui_project_loads_compile_commands_1():
|
||||
create_compile_commands()
|
||||
ret, stdout, stderr = cppcheck(['--project=proj2/proj2.cppcheck'])
|
||||
cwd = os.getcwd()
|
||||
file1 = os.path.join(cwd, 'proj2', 'a', 'a.c')
|
||||
file2 = os.path.join(cwd, 'proj2', 'b', 'b.c')
|
||||
file1 = os.path.realpath('proj2/a/a.c')
|
||||
file2 = os.path.realpath('proj2/b/b.c')
|
||||
assert ret == 0
|
||||
assert stdout.find('Checking %s ...' % (file1)) >= 0
|
||||
assert stdout.find('Checking %s ...' % (file2)) >= 0
|
||||
assert stdout.find('Checking %s ...' % file1) >= 0
|
||||
assert stdout.find('Checking %s ...' % file2) >= 0
|
||||
|
||||
def test_gui_project_loads_compile_commands_2():
|
||||
create_compile_commands()
|
||||
exclude_path_1 = os.path.join(os.getcwd(), 'proj2', 'b').replace('\\', '/')
|
||||
exclude_path_1 = realpath('proj2/b')
|
||||
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'])
|
||||
cwd = os.getcwd()
|
||||
file1 = os.path.join(cwd, 'proj2', 'a', 'a.c')
|
||||
file2 = os.path.join(cwd, 'proj2', 'b', 'b.c') # Excluded by test.cppcheck
|
||||
file1 = os.path.realpath('proj2/a/a.c')
|
||||
file2 = os.path.realpath('proj2/b/b.c') # Excluded by test.cppcheck
|
||||
assert ret == 0
|
||||
assert stdout.find('Checking %s ...' % (file1)) >= 0
|
||||
assert stdout.find('Checking %s ...' % (file2)) < 0
|
||||
assert stdout.find('Checking %s ...' % file1) >= 0
|
||||
assert stdout.find('Checking %s ...' % file2) < 0
|
||||
|
||||
|
||||
def test_gui_project_loads_relative_vs_solution():
|
||||
|
@ -118,30 +113,30 @@ def test_gui_project_loads_relative_vs_solution():
|
|||
file1 = os.path.join('proj2', 'a', 'a.c')
|
||||
file2 = os.path.join('proj2', 'b', 'b.c')
|
||||
assert ret == 0
|
||||
assert stdout.find('Checking %s Debug|Win32...' % (file1)) >= 0
|
||||
assert stdout.find('Checking %s Debug|x64...' % (file1)) >= 0
|
||||
assert stdout.find('Checking %s Release|Win32...' % (file1)) >= 0
|
||||
assert stdout.find('Checking %s Release|x64...' % (file1)) >= 0
|
||||
assert stdout.find('Checking %s Debug|Win32...' % (file2)) >= 0
|
||||
assert stdout.find('Checking %s Debug|x64...' % (file2)) >= 0
|
||||
assert stdout.find('Checking %s Release|Win32...' % (file2)) >= 0
|
||||
assert stdout.find('Checking %s Release|x64...' % (file2)) >= 0
|
||||
assert stdout.find('Checking %s Debug|Win32...' % file1) >= 0
|
||||
assert stdout.find('Checking %s Debug|x64...' % file1) >= 0
|
||||
assert stdout.find('Checking %s Release|Win32...' % file1) >= 0
|
||||
assert stdout.find('Checking %s Release|x64...' % file1) >= 0
|
||||
assert stdout.find('Checking %s Debug|Win32...' % file2) >= 0
|
||||
assert stdout.find('Checking %s Debug|x64...' % file2) >= 0
|
||||
assert stdout.find('Checking %s Release|Win32...' % file2) >= 0
|
||||
assert stdout.find('Checking %s Release|x64...' % file2) >= 0
|
||||
|
||||
def test_gui_project_loads_absolute_vs_solution():
|
||||
create_gui_project_file('test.cppcheck', import_project=os.path.join(os.getcwd(),'proj2', 'proj2.sln').replace('\\', '/'))
|
||||
create_gui_project_file('test.cppcheck', import_project=realpath('proj2/proj2.sln'))
|
||||
ret, stdout, stderr = cppcheck(['--project=test.cppcheck'])
|
||||
file1 = os.path.join(os.getcwd(), 'proj2', 'a', 'a.c')
|
||||
file2 = os.path.join(os.getcwd(), 'proj2', 'b', 'b.c')
|
||||
file1 = os.path.realpath('proj2/a/a.c')
|
||||
file2 = os.path.realpath('proj2/b/b.c')
|
||||
print(stdout)
|
||||
assert ret == 0
|
||||
assert stdout.find('Checking %s Debug|Win32...' % (file1)) >= 0
|
||||
assert stdout.find('Checking %s Debug|x64...' % (file1)) >= 0
|
||||
assert stdout.find('Checking %s Release|Win32...' % (file1)) >= 0
|
||||
assert stdout.find('Checking %s Release|x64...' % (file1)) >= 0
|
||||
assert stdout.find('Checking %s Debug|Win32...' % (file2)) >= 0
|
||||
assert stdout.find('Checking %s Debug|x64...' % (file2)) >= 0
|
||||
assert stdout.find('Checking %s Release|Win32...' % (file2)) >= 0
|
||||
assert stdout.find('Checking %s Release|x64...' % (file2)) >= 0
|
||||
assert stdout.find('Checking %s Debug|Win32...' % file1) >= 0
|
||||
assert stdout.find('Checking %s Debug|x64...' % file1) >= 0
|
||||
assert stdout.find('Checking %s Release|Win32...' % file1) >= 0
|
||||
assert stdout.find('Checking %s Release|x64...' % file1) >= 0
|
||||
assert stdout.find('Checking %s Debug|Win32...' % file2) >= 0
|
||||
assert stdout.find('Checking %s Debug|x64...' % file2) >= 0
|
||||
assert stdout.find('Checking %s Release|Win32...' % file2) >= 0
|
||||
assert stdout.find('Checking %s Release|x64...' % file2) >= 0
|
||||
|
||||
def test_gui_project_loads_relative_vs_solution():
|
||||
create_gui_project_file('test.cppcheck', root_path='proj2', import_project='proj2/proj2.sln')
|
||||
|
@ -155,7 +150,7 @@ def test_gui_project_loads_relative_vs_solution():
|
|||
|
||||
def test_gui_project_loads_absolute_vs_solution():
|
||||
create_gui_project_file('test.cppcheck',
|
||||
root_path=os.path.join(os.getcwd(), 'proj2').replace('\\', '/'),
|
||||
import_project=os.path.join(os.getcwd(), 'proj2', 'proj2.sln').replace('\\', '/'))
|
||||
root_path=realpath('proj2'),
|
||||
import_project=realpath('proj2/proj2.sln'))
|
||||
ret, stdout, stderr = cppcheck(['--project=test.cppcheck'])
|
||||
assert stderr == ERR_A + ERR_B
|
||||
|
|
Loading…
Reference in New Issue