@@ -67,6 +67,9 @@ class TestSingleExecutorBase : public TestFixture {
6767 SHOWTIME_MODES showtime = SHOWTIME_MODES::SHOWTIME_NONE;
6868 const char * plistOutput = nullptr ;
6969 std::vector<std::string> filesList;
70+ bool executeCommandCalled = false ;
71+ std::string exe;
72+ std::vector<std::string> args;
7073 };
7174
7275 void check (int files, int result, const std::string &data, const CheckOptions &opt = {}) {
@@ -101,9 +104,16 @@ class TestSingleExecutorBase : public TestFixture {
101104 settings.showtime = opt.showtime ;
102105 if (opt.plistOutput )
103106 settings.plistOutput = opt.plistOutput ;
107+
108+ bool executeCommandCalled = false ;
109+ std::string exe;
110+ std::vector<std::string> args;
104111 // NOLINTNEXTLINE(performance-unnecessary-value-param)
105- CppCheck cppcheck (*this , true , [](std::string,std::vector<std::string>,std::string,std::string&){
106- return false ;
112+ CppCheck cppcheck (*this , true , [&executeCommandCalled, &exe, &args](std::string e,std::vector<std::string> a,std::string,std::string&){
113+ executeCommandCalled = true ;
114+ exe = std::move (e);
115+ args = std::move (a);
116+ return true ;
107117 });
108118 cppcheck.settings () = settings;
109119
@@ -119,6 +129,13 @@ class TestSingleExecutorBase : public TestFixture {
119129 // TODO: test with settings.project.fileSettings;
120130 SingleExecutor executor (cppcheck, filemap, settings, settings.nomsg , *this );
121131 ASSERT_EQUALS (result, executor.check ());
132+ ASSERT_EQUALS (opt.executeCommandCalled , executeCommandCalled);
133+ ASSERT_EQUALS (opt.exe , exe);
134+ ASSERT_EQUALS (opt.args .size (), args.size ());
135+ for (int i = 0 ; i < args.size (); ++i)
136+ {
137+ ASSERT_EQUALS (opt.args [i], args[i]);
138+ }
122139 }
123140
124141 void run () override {
@@ -131,6 +148,7 @@ class TestSingleExecutorBase : public TestFixture {
131148 TEST_CASE (one_error_less_files);
132149 TEST_CASE (one_error_several_files);
133150 TEST_CASE (markup);
151+ TEST_CASE (clangTidy);
134152 }
135153
136154 void many_files () {
@@ -246,7 +264,34 @@ class TestSingleExecutorBase : public TestFixture {
246264 settings = settingsOld;
247265 }
248266
249- // TODO: test clang-tidy
267+ void clangTidy () {
268+ // TODO: we currently only invoke it with ImportProject::FileSettings
269+ if (!useFS)
270+ return ;
271+
272+ const Settings settingsOld = settings;
273+ settings.clangTidy = true ;
274+
275+ #ifdef _WIN32
276+ const char exe[] = " clang-tidy.exe" ;
277+ #else
278+ const char exe[] = " clang-tidy" ;
279+ #endif
280+
281+ const std::string file = fprefix () + " _001.cpp" ;
282+ check (1 , 0 ,
283+ " int main()\n "
284+ " {\n "
285+ " return 0;\n "
286+ " }" ,
287+ dinit (CheckOptions,
288+ $.executeCommandCalled = true ,
289+ $.exe = exe,
290+ $.args = {" -quiet" , " -checks=*,-clang-analyzer-*,-llvm*" , file, " --" }));
291+ ASSERT_EQUALS (" Checking " + file + " ...\n " , output.str ());
292+ settings = settingsOld;
293+ }
294+
250295 // TODO: test whole program analysis
251296};
252297
0 commit comments