From cc92b09ec18482b87561da216331de35e55914b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Mon, 9 Oct 2023 12:26:58 +0200 Subject: [PATCH] fixed #12016 - ProcessExecutor: added missing invocation of clang-tidy (#5529) No changes in tests since the intercepted invocation function in called in a forked process. The clang-tidy integration is also broken. --- cli/processexecutor.cpp | 3 ++- test/cli/test-more-projects.py | 41 +++++++++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/cli/processexecutor.cpp b/cli/processexecutor.cpp index 09cec0f2d..04be345e9 100644 --- a/cli/processexecutor.cpp +++ b/cli/processexecutor.cpp @@ -277,7 +277,8 @@ unsigned int ProcessExecutor::check() if (iFileSettings != mSettings.project.fileSettings.end()) { resultOfCheck = fileChecker.check(*iFileSettings); - // TODO: call analyseClangTidy() + if (fileChecker.settings().clangTidy) + fileChecker.analyseClangTidy(*iFileSettings); } else { // Read file from a file resultOfCheck = fileChecker.check(iFile->first); diff --git a/test/cli/test-more-projects.py b/test/cli/test-more-projects.py index ed3660beb..0b1a4b1db 100644 --- a/test/cli/test-more-projects.py +++ b/test/cli/test-more-projects.py @@ -1,6 +1,7 @@ # python -m pytest test-more-projects.py import json import os +import pytest from testutils import cppcheck @@ -251,4 +252,42 @@ def test_project_std(tmpdir): ret, stdout, stderr = cppcheck(['--project=' + compile_commands, '--enable=all', '-rp=' + str(tmpdir), '--template=cppcheck1']) assert ret == 0, stdout - assert (stderr == '[bug1.cpp:3]: (error) Division by zero.\n') \ No newline at end of file + assert (stderr == '[bug1.cpp:3]: (error) Division by zero.\n') + + + +@pytest.mark.skip() # clang-tidy is not available in all cases +def test_clang_tidy(tmpdir): + test_file = os.path.join(tmpdir, 'test.cpp') + with open(test_file, 'wt') as f: + f.write(""" + int main(int argc) + { + (void)argc; + } + """) + + project_file = os.path.join(tmpdir, 'test.cppcheck') + with open(project_file, 'wt') as f: + f.write( + """ + + + + > + + clang-tidy + +""".format(test_file)) + + args = ['--project={}'.format(project_file)] + + exitcode, stdout, stderr = cppcheck(args) + assert exitcode == 0, stdout + lines = stdout.splitlines() + # TODO: should detect clang-tidy issue + assert len(lines) == 1 + assert lines == [ + 'Checking {} ...'.format(test_file) + ] + assert stderr == ''