test/cli: Add tests that loads vs project

This commit is contained in:
Daniel Marjamäki 2019-04-14 16:48:59 +02:00
parent a18025c95d
commit fd0309db9b
1 changed files with 36 additions and 0 deletions

View File

@ -3,6 +3,7 @@
import logging
import os
import re
import subprocess
# Run Cppcheck with args
@ -22,6 +23,22 @@ def cppcheck(args):
stderr = comm[1].decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n')
return p.returncode, stdout, stderr
# Get Visual Studio configurations checking a file
# Checking {file} {config}...
def getVsConfigs(stdout, filename):
ret = []
for line in stdout.split('\n'):
if not line.startswith('Checking %s ' % (filename)):
continue
if not line.endswith('...'):
continue
res = re.match(r'.* ([A-Za-z0-9|]+)...', line)
if res:
ret.append(res.group(1))
ret.sort()
return ' '.join(ret)
def test_relative_path():
ret, stdout, stderr = cppcheck('1-helloworld')
filename = os.path.join('1-helloworld', 'main.c')
@ -29,6 +46,7 @@ def test_relative_path():
assert stdout == 'Checking %s ...\n' % (filename)
assert stderr == '[%s:5]: (error) Division by zero.\n' % (filename)
def test_local_path():
cwd = os.getcwd()
os.chdir('1-helloworld')
@ -90,3 +108,21 @@ def test_basepath_absolute_path():
assert stdout == 'Checking %s ...\n' % (filename)
assert stderr == '[main.c:5]: (error) Division by zero.\n'
def test_project_local_path():
cwd = os.getcwd()
os.chdir('1-helloworld')
ret, stdout, stderr = cppcheck('--project=helloworld.vcxproj')
os.chdir(cwd)
assert ret == 0
assert getVsConfigs(stdout, 'main.c') == 'Debug|Win32 Debug|x64 Release|Win32 Release|x64'
assert stderr == '[main.c:5]: (error) Division by zero.\n'
def test_project_relative_path():
prjpath = '1-helloworld'
ret, stdout, stderr = cppcheck('--project=%s' % (os.path.join(prjpath, 'helloworld.vcxproj')))
filename = os.path.join(prjpath, 'main.c')
assert ret == 0
assert getVsConfigs(stdout, filename) == 'Debug|Win32 Debug|x64 Release|Win32 Release|x64'
assert stderr == '[%s:5]: (error) Division by zero.\n' % (filename)