test/cli: tweaks for running it in windows

This commit is contained in:
Daniel Marjamäki 2019-04-14 15:53:32 +02:00
parent 2cd5a8fde0
commit a18025c95d
2 changed files with 33 additions and 20 deletions

View File

@ -66,7 +66,7 @@ namespace {
std::string getAddonInfo(const std::string &fileName, const std::string &exename) {
if (!endsWith(fileName, ".json", 5)) {
name = fileName;
scriptFile = Path::getPathFromFilename(exename) + "/addons/" + fileName + ".py";
scriptFile = Path::getPathFromFilename(exename) + "addons/" + fileName + ".py";
return "";
}
std::ifstream fin(fileName);
@ -84,7 +84,7 @@ namespace {
args += " " + v.get<std::string>();
}
name = obj["script"].get<std::string>();
scriptFile = Path::getPathFromFilename(exename) + "/addons/" + fileName + ".py";
scriptFile = Path::getPathFromFilename(exename) + "addons/" + fileName + ".py";
return "";
}
};

View File

@ -7,19 +7,27 @@ import subprocess
# Run Cppcheck with args
def cppcheck(args):
cmd = '%s %s' % (os.path.expanduser('~/cppcheck/cppcheck'), args)
if os.path.isfile('../../bin/debug/cppcheck.exe'):
cmd = '../../bin/debug/cppcheck.exe ' + args
elif os.path.isfile('../../../bin/debug/cppcheck.exe'):
cmd = '../../../bin/debug/cppcheck.exe ' + args
elif os.path.isfile('../../cppcheck'):
cmd = '../../cppcheck ' + args
else:
cmd = '../../../cppcheck ' + args
logging.info(cmd)
p = subprocess.Popen(cmd.split(), stdout=subprocess.PIPE, stderr=subprocess.PIPE)
comm = p.communicate()
stdout = comm[0].decode(encoding='utf-8', errors='ignore')
stderr = comm[1].decode(encoding='utf-8', errors='ignore')
stdout = comm[0].decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n')
stderr = comm[1].decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n')
return p.returncode, stdout, stderr
def test_relative_path():
ret, stdout, stderr = cppcheck('1-helloworld')
filename = os.path.join('1-helloworld', 'main.c')
assert ret == 0
assert stdout == 'Checking 1-helloworld/main.c ...\n'
assert stderr == '[1-helloworld/main.c:5]: (error) Division by zero.\n'
assert stdout == 'Checking %s ...\n' % (filename)
assert stderr == '[%s:5]: (error) Division by zero.\n' % (filename)
def test_local_path():
cwd = os.getcwd()
@ -31,11 +39,12 @@ def test_local_path():
assert stderr == '[main.c:5]: (error) Division by zero.\n'
def test_absolute_path():
prjpath = '%s/1-helloworld' % (os.getcwd())
prjpath = os.path.join(os.getcwd(), '1-helloworld')
ret, stdout, stderr = cppcheck(prjpath)
filename = os.path.join(prjpath, 'main.c')
assert ret == 0
assert stdout == 'Checking %s/main.c ...\n' % (prjpath)
assert stderr == '[%s/main.c:5]: (error) Division by zero.\n' % (prjpath)
assert stdout == 'Checking %s ...\n' % (filename)
assert stderr == '[%s:5]: (error) Division by zero.\n' % (filename)
def test_addon_local_path():
cwd = os.getcwd()
@ -48,32 +57,36 @@ def test_addon_local_path():
'[main.c:1]: (style) misra violation (use --rule-texts=<file> to get proper output)\n')
def test_addon_absolute_path():
prjpath = '%s/1-helloworld' % (os.getcwd())
prjpath = os.path.join(os.getcwd(), '1-helloworld')
ret, stdout, stderr = cppcheck('--addon=misra %s' % (prjpath))
filename = os.path.join(prjpath, 'main.c')
assert ret == 0
assert stdout == 'Checking %s/main.c ...\n' % (prjpath)
assert stderr == ('[%s/main.c:5]: (error) Division by zero.\n'
'[%s/main.c:1]: (style) misra violation (use --rule-texts=<file> to get proper output)\n' % (prjpath, prjpath))
assert stdout == 'Checking %s ...\n' % (filename)
assert stderr == ('[%s:5]: (error) Division by zero.\n'
'[%s:1]: (style) misra violation (use --rule-texts=<file> to get proper output)\n' % (filename, filename))
def test_addon_relative_path():
prjpath = '1-helloworld'
ret, stdout, stderr = cppcheck('--addon=misra %s' % (prjpath))
filename = os.path.join(prjpath, 'main.c')
assert ret == 0
assert stdout == 'Checking %s/main.c ...\n' % (prjpath)
assert stderr == ('[%s/main.c:5]: (error) Division by zero.\n'
'[%s/main.c:1]: (style) misra violation (use --rule-texts=<file> to get proper output)\n' % (prjpath, prjpath))
assert stdout == 'Checking %s ...\n' % (filename)
assert stderr == ('[%s:5]: (error) Division by zero.\n'
'[%s:1]: (style) misra violation (use --rule-texts=<file> to get proper output)\n' % (filename, filename))
def test_basepath_relative_path():
prjpath = '1-helloworld'
ret, stdout, stderr = cppcheck('%s -rp=%s' % (prjpath, prjpath))
filename = os.path.join(prjpath, 'main.c')
assert ret == 0
assert stdout == 'Checking %s/main.c ...\n' % (prjpath)
assert stdout == 'Checking %s ...\n' % (filename)
assert stderr == '[main.c:5]: (error) Division by zero.\n'
def test_basepath_absolute_path():
prjpath = '%s/1-helloworld' % (os.getcwd())
prjpath = os.path.join(os.getcwd(), '1-helloworld')
ret, stdout, stderr = cppcheck('%s -rp=%s' % (prjpath, prjpath))
filename = os.path.join(prjpath, 'main.c')
assert ret == 0
assert stdout == 'Checking %s/main.c ...\n' % (prjpath)
assert stdout == 'Checking %s ...\n' % (filename)
assert stderr == '[main.c:5]: (error) Division by zero.\n'