Fixed test/cli

This commit is contained in:
Daniel Marjamäki 2019-08-18 12:51:32 +02:00
parent 2d9a131817
commit d95f29b23a
12 changed files with 38 additions and 37 deletions

View File

@ -44,10 +44,6 @@
#include <tinyxml2.h>
#endif
// The default template format is "gcc"
static const char GCC_TEMPLATE_FORMAT[] = "{file}:{line}:{column}: warning: {message} [{id}]\\n{code}";
static const char GCC_TEMPLATE_LOCATION[] = "{file}:{line}:{column}: note: {info}\\n{code}";
static void addFilesToList(const std::string& FileList, std::vector<std::string>& PathNames)
{
// To keep things initially simple, if the file can't be opened, just be silent and move on.
@ -642,8 +638,8 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
}
if (mSettings->templateFormat == "gcc") {
mSettings->templateFormat = GCC_TEMPLATE_FORMAT;
mSettings->templateLocation = GCC_TEMPLATE_LOCATION;
mSettings->templateFormat = "{file}:{line}:{column}: warning: {message} [{id}]\\n{code}";
mSettings->templateLocation = "{file}:{line}:{column}: note: {info}\\n{code}";
} else if (mSettings->templateFormat == "daca2") {
mSettings->templateFormat = "{file}:{line}:{column}: {severity}: {message} [{id}]";
mSettings->templateLocation = "{file}:{line}:{column}: note: {info}";
@ -890,9 +886,9 @@ bool CmdLineParser::parseFromArgs(int argc, const char* const argv[])
// Default template format..
if (mSettings->templateFormat.empty()) {
mSettings->templateFormat = GCC_TEMPLATE_FORMAT;
mSettings->templateFormat = "{file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]\\n{code}";
if (mSettings->templateLocation.empty())
mSettings->templateLocation = GCC_TEMPLATE_LOCATION;
mSettings->templateLocation = "{file}:{line}:{column}: note: {info}\\n{code}";
}
mSettings->project.ignorePaths(mIgnoredPaths);

View File

@ -337,7 +337,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string
fdump << " <tok "
<< "fileIndex=\"" << tok->location.fileIndex << "\" "
<< "linenr=\"" << tok->location.line << "\" "
<< "col=\"" << tok->location.col << "\" "
<< "column=\"" << tok->location.col << "\" "
<< "str=\"" << ErrorLogger::toxml(tok->str()) << "\""
<< "/>" << std::endl;
}

View File

@ -1,3 +1,3 @@
samples\AssignmentAddressToInteger\bad.c:3:0: warning: Assigning a pointer to an integer is not portable. [AssignmentAddressToInteger]
samples\AssignmentAddressToInteger\bad.c:3:0: portability: Assigning a pointer to an integer is not portable. [AssignmentAddressToInteger]
int a = p;
^

View File

@ -1,3 +1,3 @@
samples\arrayIndexOutOfBounds\bad.c:7:6: warning: Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]
samples\arrayIndexOutOfBounds\bad.c:7:6: error: Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]
a[2] = 0;
^

View File

@ -1,3 +1,3 @@
samples\autoVariables\bad.c:4:5: warning: Address of local auto-variable assigned to a function parameter. [autoVariables]
samples\autoVariables\bad.c:4:5: error: Address of local auto-variable assigned to a function parameter. [autoVariables]
*a = &b;
^

View File

@ -1,3 +1,3 @@
samples\bufferAccessOutOfBounds\bad.c:6:10: warning: Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]
samples\bufferAccessOutOfBounds\bad.c:6:10: error: Array 'a[2]' accessed at index 2, which is out of bounds. [arrayIndexOutOfBounds]
a[i] = 0;
^

View File

@ -1,4 +1,4 @@
samples\erase\bad.cpp:9:32: warning: Using iterator to local container 'items' that may be invalid. [invalidContainer]
samples\erase\bad.cpp:9:32: error: Using iterator to local container 'items' that may be invalid. [invalidContainer]
for (iter = items.begin(); iter != items.end(); ++iter) {
^
samples\erase\bad.cpp:9:17: note: Iterator to container is created here.

View File

@ -1,3 +1,3 @@
samples\outOfBounds\bad.c:5:12: warning: Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]
samples\outOfBounds\bad.c:5:12: error: Buffer is accessed out of bounds: str [bufferAccessOutOfBounds]
strcpy(str, "0123456789abcdef");
^

View File

@ -1,3 +1,3 @@
samples\resourceLeak\bad.c:8:5: warning: Resource leak: a [resourceLeak]
samples\resourceLeak\bad.c:8:5: error: Resource leak: a [resourceLeak]
return 0;
^

View File

@ -1,3 +1,3 @@
samples\syntaxError\bad.c:2:1: warning: Unmatched '{'. Configuration: ''. [syntaxError]
samples\syntaxError\bad.c:2:1: error: Unmatched '{'. Configuration: ''. [syntaxError]
^

View File

@ -35,7 +35,7 @@ def getVsConfigs(stdout, filename):
return ' '.join(ret)
def test_relative_path():
ret, stdout, stderr = cppcheck(['helloworld'])
ret, stdout, stderr = cppcheck(['--template=cppcheck1', 'helloworld'])
filename = os.path.join('helloworld', 'main.c')
assert ret == 0
assert stdout == 'Checking %s ...\n' % (filename)
@ -43,21 +43,21 @@ def test_relative_path():
def test_local_path():
ret, stdout, stderr = cppcheck_local(['.'])
ret, stdout, stderr = cppcheck_local(['--template=cppcheck1', '.'])
assert ret == 0
assert stdout == 'Checking main.c ...\n'
assert stderr == '[main.c:5]: (error) Division by zero.\n'
def test_absolute_path():
prjpath = getAbsoluteProjectPath()
ret, stdout, stderr = cppcheck([prjpath])
ret, stdout, stderr = cppcheck(['--template=cppcheck1', prjpath])
filename = os.path.join(prjpath, 'main.c')
assert ret == 0
assert stdout == 'Checking %s ...\n' % (filename)
assert stderr == '[%s:5]: (error) Division by zero.\n' % (filename)
def test_addon_local_path():
ret, stdout, stderr = cppcheck_local(['--addon=misra', '.'])
ret, stdout, stderr = cppcheck_local(['--addon=misra', '--template=cppcheck1', '.'])
assert ret == 0
assert stdout == 'Checking main.c ...\n'
assert stderr == ('[main.c:5]: (error) Division by zero.\n'
@ -65,7 +65,7 @@ def test_addon_local_path():
def test_addon_absolute_path():
prjpath = getAbsoluteProjectPath()
ret, stdout, stderr = cppcheck(['--addon=misra', prjpath])
ret, stdout, stderr = cppcheck(['--addon=misra', '--template=cppcheck1', prjpath])
filename = os.path.join(prjpath, 'main.c')
assert ret == 0
assert stdout == 'Checking %s ...\n' % (filename)
@ -74,7 +74,7 @@ def test_addon_absolute_path():
def test_addon_relative_path():
prjpath = getRelativeProjectPath()
ret, stdout, stderr = cppcheck(['--addon=misra', prjpath])
ret, stdout, stderr = cppcheck(['--addon=misra', '--template=cppcheck1', prjpath])
filename = os.path.join(prjpath, 'main.c')
assert ret == 0
assert stdout == 'Checking %s ...\n' % (filename)
@ -84,7 +84,7 @@ def test_addon_relative_path():
def test_addon_relative_path():
project_file = 'helloworld/test.cppcheck'
create_gui_project_file(project_file, paths=['.'], addon='misra')
ret, stdout, stderr = cppcheck(['--project=' + project_file])
ret, stdout, stderr = cppcheck(['--template=cppcheck1', '--project=' + project_file])
filename = os.path.join('helloworld', 'main.c')
assert ret == 0
assert stdout == 'Checking %s ...\n' % (filename)
@ -93,7 +93,7 @@ def test_addon_relative_path():
def test_basepath_relative_path():
prjpath = getRelativeProjectPath()
ret, stdout, stderr = cppcheck([prjpath, '-rp=' + prjpath])
ret, stdout, stderr = cppcheck([prjpath, '--template=cppcheck1', '-rp=' + prjpath])
filename = os.path.join(prjpath, 'main.c')
assert ret == 0
assert stdout == 'Checking %s ...\n' % (filename)
@ -101,21 +101,21 @@ def test_basepath_relative_path():
def test_basepath_absolute_path():
prjpath = getAbsoluteProjectPath()
ret, stdout, stderr = cppcheck([prjpath, '-rp=' + prjpath])
ret, stdout, stderr = cppcheck(['--template=cppcheck1', prjpath, '-rp=' + prjpath])
filename = os.path.join(prjpath, 'main.c')
assert ret == 0
assert stdout == 'Checking %s ...\n' % (filename)
assert stderr == '[main.c:5]: (error) Division by zero.\n'
def test_vs_project_local_path():
ret, stdout, stderr = cppcheck_local(['--project=helloworld.vcxproj'])
ret, stdout, stderr = cppcheck_local(['--template=cppcheck1', '--project=helloworld.vcxproj'])
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_vs_project_relative_path():
prjpath = getRelativeProjectPath()
ret, stdout, stderr = cppcheck(['--project=' + os.path.join(prjpath, 'helloworld.vcxproj')])
ret, stdout, stderr = cppcheck(['--template=cppcheck1', '--project=' + 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'
@ -123,21 +123,21 @@ def test_vs_project_relative_path():
def test_vs_project_absolute_path():
prjpath = getAbsoluteProjectPath()
ret, stdout, stderr = cppcheck(['--project=' + os.path.join(prjpath, 'helloworld.vcxproj')])
ret, stdout, stderr = cppcheck(['--template=cppcheck1', '--project=' + 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)
def test_cppcheck_project_local_path():
ret, stdout, stderr = cppcheck_local(['--platform=win64', '--project=helloworld.cppcheck'])
ret, stdout, stderr = cppcheck_local(['--template=cppcheck1', '--platform=win64', '--project=helloworld.cppcheck'])
assert ret == 0
assert getVsConfigs(stdout, 'main.c') == 'Debug|x64'
assert stderr == '[main.c:5]: (error) Division by zero.\n'
def test_cppcheck_project_relative_path():
prjpath = getRelativeProjectPath()
ret, stdout, stderr = cppcheck(['--platform=win64', '--project=' + os.path.join(prjpath, 'helloworld.cppcheck')])
ret, stdout, stderr = cppcheck(['--template=cppcheck1', '--platform=win64', '--project=' + os.path.join(prjpath, 'helloworld.cppcheck')])
filename = os.path.join(prjpath, 'main.c')
assert ret == 0
assert getVsConfigs(stdout, filename) == 'Debug|x64'
@ -145,7 +145,7 @@ def test_cppcheck_project_relative_path():
def test_cppcheck_project_absolute_path():
prjpath = getAbsoluteProjectPath()
ret, stdout, stderr = cppcheck(['--platform=win64', '--project=' + os.path.join(prjpath, 'helloworld.cppcheck')])
ret, stdout, stderr = cppcheck(['--template=cppcheck1', '--platform=win64', '--project=' + os.path.join(prjpath, 'helloworld.cppcheck')])
filename = os.path.join(prjpath, 'main.c')
assert ret == 0
assert getVsConfigs(stdout, filename) == 'Debug|x64'

View File

@ -7,6 +7,13 @@ from testutils import create_gui_project_file, cppcheck
COMPILE_COMMANDS_JSON = os.path.join('proj2', 'compile_commands.json')
ERR_A = ('a/a.c: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' +
'x = 3 / 0;\n' +
' ^\n')
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'},
@ -112,19 +119,17 @@ def test_gui_project_loads_absolute_vs_solution():
def test_gui_project_loads_relative_vs_solution():
create_gui_project_file('test.cppcheck', root_path='proj2', import_project='proj2/proj2.sln')
ret, stdout, stderr = cppcheck(['--project=test.cppcheck'])
assert stderr == ('[a/a.c:1]: (error) Division by zero.\n'
'[b/b.c:1]: (error) Division by zero.\n')
assert stderr == ERR_A + ERR_B
def test_gui_project_loads_relative_vs_solution():
create_gui_project_file('test.cppcheck', root_path='proj2', import_project='proj2/proj2.sln', exclude_paths=['b'])
ret, stdout, stderr = cppcheck(['--project=test.cppcheck'])
assert stderr == '[a/a.c:1]: (error) Division by zero.\n'
assert stderr == ERR_A
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('\\', '/'))
ret, stdout, stderr = cppcheck(['--project=test.cppcheck'])
assert stderr == ('[a/a.c:1]: (error) Division by zero.\n'
'[b/b.c:1]: (error) Division by zero.\n')
assert stderr == ERR_A + ERR_B