diff --git a/cli/processexecutor.cpp b/cli/processexecutor.cpp index 445b545f8..be9c61d15 100644 --- a/cli/processexecutor.cpp +++ b/cli/processexecutor.cpp @@ -280,9 +280,11 @@ unsigned int ProcessExecutor::check() if (iFileSettings != mSettings.project.fileSettings.end()) { resultOfCheck = fileChecker.check(*iFileSettings); + // TODO: call analyseClangTidy() } else { // Read file from a file resultOfCheck = fileChecker.check(iFile->first); + // TODO: call analyseClangTidy()? } pipewriter.writeEnd(std::to_string(resultOfCheck)); diff --git a/cli/singleexecutor.cpp b/cli/singleexecutor.cpp index 4de711a2c..c3fea886b 100644 --- a/cli/singleexecutor.cpp +++ b/cli/singleexecutor.cpp @@ -61,7 +61,7 @@ unsigned int SingleExecutor::check() processedsize += i->second; if (!mSettings.quiet) reportStatus(c + 1, mFiles.size(), processedsize, totalfilesize); - // TODO: call analyseClangTidy() + // TODO: call analyseClangTidy()? c++; } } @@ -92,7 +92,7 @@ unsigned int SingleExecutor::check() processedsize += i->second; if (!mSettings.quiet) reportStatus(c + 1, mFiles.size(), processedsize, totalfilesize); - // TODO: call analyseClangTidy() + // TODO: call analyseClangTidy()? c++; } } diff --git a/cli/threadexecutor.cpp b/cli/threadexecutor.cpp index 26c3c03aa..8590651a2 100644 --- a/cli/threadexecutor.cpp +++ b/cli/threadexecutor.cpp @@ -129,6 +129,7 @@ public: } else { // Read file from a file result = fileChecker.check(*file); + // TODO: call analyseClangTidy()? } return result; } diff --git a/test/testprocessexecutor.cpp b/test/testprocessexecutor.cpp index f9cf2d0d9..ecf9a5f07 100644 --- a/test/testprocessexecutor.cpp +++ b/test/testprocessexecutor.cpp @@ -229,6 +229,9 @@ private: output.str());*/ settings = settingsOld; } + + // TODO: test clang-tidy + // TODO: test whole program analysis }; REGISTER_TEST(TestProcessExecutor) diff --git a/test/testsingleexecutor.cpp b/test/testsingleexecutor.cpp index 9208ca72e..56e5e8478 100644 --- a/test/testsingleexecutor.cpp +++ b/test/testsingleexecutor.cpp @@ -67,6 +67,9 @@ private: SHOWTIME_MODES showtime = SHOWTIME_MODES::SHOWTIME_NONE; const char* plistOutput = nullptr; std::vector filesList; + bool executeCommandCalled = false; + std::string exe; + std::vector args; }; void check(int files, int result, const std::string &data, const CheckOptions &opt = {}) { @@ -101,9 +104,16 @@ private: settings.showtime = opt.showtime; if (opt.plistOutput) settings.plistOutput = opt.plistOutput; + + bool executeCommandCalled = false; + std::string exe; + std::vector args; // NOLINTNEXTLINE(performance-unnecessary-value-param) - CppCheck cppcheck(*this, true, [](std::string,std::vector,std::string,std::string&){ - return false; + CppCheck cppcheck(*this, true, [&executeCommandCalled, &exe, &args](std::string e,std::vector a,std::string,std::string&){ + executeCommandCalled = true; + exe = std::move(e); + args = std::move(a); + return true; }); cppcheck.settings() = settings; @@ -119,6 +129,13 @@ private: // TODO: test with settings.project.fileSettings; SingleExecutor executor(cppcheck, filemap, settings, settings.nomsg, *this); ASSERT_EQUALS(result, executor.check()); + ASSERT_EQUALS(opt.executeCommandCalled, executeCommandCalled); + ASSERT_EQUALS(opt.exe, exe); + ASSERT_EQUALS(opt.args.size(), args.size()); + for (int i = 0; i < args.size(); ++i) + { + ASSERT_EQUALS(opt.args[i], args[i]); + } } void run() override { @@ -131,6 +148,7 @@ private: TEST_CASE(one_error_less_files); TEST_CASE(one_error_several_files); TEST_CASE(markup); + TEST_CASE(clangTidy); } void many_files() { @@ -246,7 +264,34 @@ private: settings = settingsOld; } - // TODO: test clang-tidy + void clangTidy() { + // TODO: we currently only invoke it with ImportProject::FileSettings + if (!useFS) + return; + + const Settings settingsOld = settings; + settings.clangTidy = true; + +#ifdef _WIN32 + const char exe[] = "clang-tidy.exe"; +#else + const char exe[] = "clang-tidy"; +#endif + + const std::string file = fprefix() + "_001.cpp"; + check(1, 0, + "int main()\n" + "{\n" + " return 0;\n" + "}", + dinit(CheckOptions, + $.executeCommandCalled = true, + $.exe = exe, + $.args = {"-quiet", "-checks=*,-clang-analyzer-*,-llvm*", file, "--"})); + ASSERT_EQUALS("Checking " + file + " ...\n", output.str()); + settings = settingsOld; + } + // TODO: test whole program analysis }; diff --git a/test/testthreadexecutor.cpp b/test/testthreadexecutor.cpp index 8d7f11bc5..08cfccfda 100644 --- a/test/testthreadexecutor.cpp +++ b/test/testthreadexecutor.cpp @@ -228,6 +228,9 @@ private: output.str());*/ settings = settingsOld; } + + // TODO: test clang-tidy + // TODO: test whole program analysis }; REGISTER_TEST(TestThreadExecutor)