From d95f29b23ae542216bded3fc66ebfc1a26e57a4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sun, 18 Aug 2019 12:51:32 +0200 Subject: [PATCH] Fixed test/cli --- cli/cmdlineparser.cpp | 12 +++------ lib/cppcheck.cpp | 2 +- samples/AssignmentAddressToInteger/out.txt | 2 +- samples/arrayIndexOutOfBounds/out.txt | 2 +- samples/autoVariables/out.txt | 2 +- samples/bufferAccessOutOfBounds/out.txt | 2 +- samples/erase/out.txt | 2 +- samples/outOfBounds/out.txt | 2 +- samples/resourceLeak/out.txt | 2 +- samples/syntaxError/out.txt | 2 +- test/cli/test-helloworld.py | 30 +++++++++++----------- test/cli/test-proj2.py | 15 +++++++---- 12 files changed, 38 insertions(+), 37 deletions(-) diff --git a/cli/cmdlineparser.cpp b/cli/cmdlineparser.cpp index 6fb112cab..da3dcc54a 100644 --- a/cli/cmdlineparser.cpp +++ b/cli/cmdlineparser.cpp @@ -44,10 +44,6 @@ #include #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& 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); diff --git a/lib/cppcheck.cpp b/lib/cppcheck.cpp index b3a58dfb8..358673cfa 100644 --- a/lib/cppcheck.cpp +++ b/lib/cppcheck.cpp @@ -337,7 +337,7 @@ unsigned int CppCheck::checkFile(const std::string& filename, const std::string fdump << " location.fileIndex << "\" " << "linenr=\"" << tok->location.line << "\" " - << "col=\"" << tok->location.col << "\" " + << "column=\"" << tok->location.col << "\" " << "str=\"" << ErrorLogger::toxml(tok->str()) << "\"" << "/>" << std::endl; } diff --git a/samples/AssignmentAddressToInteger/out.txt b/samples/AssignmentAddressToInteger/out.txt index a34dcb96f..7fc3c9d27 100644 --- a/samples/AssignmentAddressToInteger/out.txt +++ b/samples/AssignmentAddressToInteger/out.txt @@ -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; ^ diff --git a/samples/arrayIndexOutOfBounds/out.txt b/samples/arrayIndexOutOfBounds/out.txt index a011c019a..bb8c14037 100644 --- a/samples/arrayIndexOutOfBounds/out.txt +++ b/samples/arrayIndexOutOfBounds/out.txt @@ -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; ^ diff --git a/samples/autoVariables/out.txt b/samples/autoVariables/out.txt index 678bcaf50..ba302b8a7 100644 --- a/samples/autoVariables/out.txt +++ b/samples/autoVariables/out.txt @@ -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; ^ diff --git a/samples/bufferAccessOutOfBounds/out.txt b/samples/bufferAccessOutOfBounds/out.txt index c09494c1f..f166c371f 100644 --- a/samples/bufferAccessOutOfBounds/out.txt +++ b/samples/bufferAccessOutOfBounds/out.txt @@ -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; ^ diff --git a/samples/erase/out.txt b/samples/erase/out.txt index b36e7a0e3..d6f3852b6 100644 --- a/samples/erase/out.txt +++ b/samples/erase/out.txt @@ -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. diff --git a/samples/outOfBounds/out.txt b/samples/outOfBounds/out.txt index 4432d9207..9ce3af4a5 100644 --- a/samples/outOfBounds/out.txt +++ b/samples/outOfBounds/out.txt @@ -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"); ^ diff --git a/samples/resourceLeak/out.txt b/samples/resourceLeak/out.txt index 84c63008c..b7c9ad9b8 100644 --- a/samples/resourceLeak/out.txt +++ b/samples/resourceLeak/out.txt @@ -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; ^ diff --git a/samples/syntaxError/out.txt b/samples/syntaxError/out.txt index d07934d38..7026830ee 100644 --- a/samples/syntaxError/out.txt +++ b/samples/syntaxError/out.txt @@ -1,3 +1,3 @@ -samples\syntaxError\bad.c:2:1: warning: Unmatched '{'. Configuration: ''. [syntaxError] +samples\syntaxError\bad.c:2:1: error: Unmatched '{'. Configuration: ''. [syntaxError] ^ diff --git a/test/cli/test-helloworld.py b/test/cli/test-helloworld.py index c6d84ffa6..798502589 100644 --- a/test/cli/test-helloworld.py +++ b/test/cli/test-helloworld.py @@ -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' diff --git a/test/cli/test-proj2.py b/test/cli/test-proj2.py index 60e1d60e5..6235ddd05 100644 --- a/test/cli/test-proj2.py +++ b/test/cli/test-proj2.py @@ -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