3434#include < utility>
3535#include < vector>
3636
37- class TestProcessExecutor : public TestFixture {
37+ class TestProcessExecutorBase : public TestFixture {
3838public:
39- TestProcessExecutor ( ) : TestFixture(" TestProcessExecutor " ) {}
39+ TestProcessExecutorBase ( const char * const name, bool useFS ) : TestFixture(name), useFS(useFS ) {}
4040
4141private:
4242 Settings settings = settingsBuilder().library(" std.cfg" ).build();
43+ bool useFS;
4344
44- static std::string fprefix ()
45+ std::string fprefix () const
4546 {
47+ if (useFS)
48+ return " processfs" ;
4649 return " process" ;
4750 }
4851
@@ -53,6 +56,10 @@ class TestProcessExecutor : public TestFixture {
5356 SHOWTIME_MODES showtime = SHOWTIME_MODES::SHOWTIME_NONE;
5457 const char * plistOutput = nullptr ;
5558 std::vector<std::string> filesList;
59+ bool clangTidy = false ;
60+ bool executeCommandCalled = false ;
61+ std::string exe;
62+ std::vector<std::string> args;
5663 };
5764
5865 /* *
@@ -63,35 +70,67 @@ class TestProcessExecutor : public TestFixture {
6370 errout.str (" " );
6471 output.str (" " );
6572
73+ Settings s = settings;
74+
6675 std::map<std::string, std::size_t > filemap;
6776 if (opt.filesList .empty ()) {
6877 for (int i = 1 ; i <= files; ++i) {
69- std::ostringstream oss;
70- oss << fprefix () << " _" << i << " .cpp" ;
71- filemap[oss.str ()] = data.size ();
78+ std::string f_s = fprefix () + " _" + std::to_string (i) + " .cpp" ;
79+ filemap[f_s] = data.size ();
80+ if (useFS) {
81+ ImportProject::FileSettings fs;
82+ fs.filename = std::move (f_s);
83+ s.project .fileSettings .emplace_back (std::move (fs));
84+ }
7285 }
7386 }
7487 else {
7588 for (const auto & f : opt.filesList )
7689 {
7790 filemap[f] = data.size ();
91+ if (useFS) {
92+ ImportProject::FileSettings fs;
93+ fs.filename = f;
94+ s.project .fileSettings .emplace_back (std::move (fs));
95+ }
7896 }
7997 }
8098
81- Settings s = settings;
8299 s.jobs = jobs;
83100 s.showtime = opt.showtime ;
84- settings .quiet = opt.quiet ;
101+ s .quiet = opt.quiet ;
85102 if (opt.plistOutput )
86103 s.plistOutput = opt.plistOutput ;
87- // TODO: test with settings.project.fileSettings;
88- ProcessExecutor executor (filemap, s, s.nomsg , *this );
104+
105+ bool executeCommandCalled = false ;
106+ std::string exe;
107+ std::vector<std::string> args;
108+ // NOLINTNEXTLINE(performance-unnecessary-value-param)
109+ auto executeFn = [&executeCommandCalled, &exe, &args](std::string e,std::vector<std::string> a,std::string,std::string&){
110+ executeCommandCalled = true ;
111+ exe = std::move (e);
112+ args = std::move (a);
113+ return EXIT_SUCCESS;
114+ };
115+
89116 std::vector<std::unique_ptr<ScopedFile>> scopedfiles;
90117 scopedfiles.reserve (filemap.size ());
91118 for (std::map<std::string, std::size_t >::const_iterator i = filemap.cbegin (); i != filemap.cend (); ++i)
92119 scopedfiles.emplace_back (new ScopedFile (i->first , data));
93120
121+ // clear files list so only fileSettings are used
122+ if (useFS)
123+ filemap.clear ();
124+
125+ ProcessExecutor executor (filemap, s, s.nomsg , *this , executeFn);
94126 ASSERT_EQUALS (result, executor.check ());
127+ ASSERT_EQUALS (opt.executeCommandCalled , executeCommandCalled);
128+ ASSERT_EQUALS (opt.exe , exe);
129+ ASSERT_EQUALS (opt.args .size (), args.size ());
130+ for (int i = 0 ; i < args.size (); ++i)
131+ {
132+ ASSERT_EQUALS (opt.args [i], args[i]);
133+ }
95134 }
96135
97136 void run () override {
@@ -106,6 +145,7 @@ class TestProcessExecutor : public TestFixture {
106145 TEST_CASE (one_error_less_files);
107146 TEST_CASE (one_error_several_files);
108147 TEST_CASE (markup);
148+ TEST_CASE (clangTidy);
109149 TEST_CASE (showtime_top5_file);
110150 TEST_CASE (showtime_top5_summary);
111151 TEST_CASE (showtime_file);
@@ -148,15 +188,15 @@ class TestProcessExecutor : public TestFixture {
148188 }
149189
150190 void many_threads_plist () {
151- const char plistOutput[] = " plist_process /" ;
191+ const std::string plistOutput = " plist_ " + fprefix () + " /" ;
152192 ScopedFile plistFile (" dummy" , " " , plistOutput);
153193
154194 check (16 , 100 , 100 ,
155195 " int main()\n "
156196 " {\n "
157197 " char *a = malloc(10);\n "
158198 " return 0;\n "
159- " }" , dinit (CheckOptions, $.plistOutput = plistOutput));
199+ " }" , dinit (CheckOptions, $.plistOutput = plistOutput. c_str () ));
160200 }
161201
162202 void no_errors_more_files () {
@@ -241,6 +281,34 @@ class TestProcessExecutor : public TestFixture {
241281 settings = settingsOld;
242282 }
243283
284+ void clangTidy () {
285+ // TODO: we currently only invoke it with ImportProject::FileSettings
286+ if (!useFS)
287+ return ;
288+
289+ #ifdef _WIN32
290+ const char exe[] = " clang-tidy.exe" ;
291+ #else
292+ const char exe[] = " clang-tidy" ;
293+ #endif
294+ (void )exe;
295+
296+ const std::string file = fprefix () + " _1.cpp" ;
297+ // TODO: the invocation cannot be checked as the code is called in the forked process
298+ check (2 , 1 , 0 ,
299+ " int main()\n "
300+ " {\n "
301+ " return 0;\n "
302+ " }" ,
303+ dinit (CheckOptions,
304+ $.quiet = false ,
305+ $.clangTidy = true /* ,
306+ $.executeCommandCalled = true,
307+ $.exe = exe,
308+ $.args = {"-quiet", "-checks=*,-clang-analyzer-*,-llvm*", file, "--"}*/ ));
309+ ASSERT_EQUALS (" Checking " + file + " ...\n " , output.str ());
310+ }
311+
244312 // TODO: provide data which actually shows values above 0
245313
246314 // TODO: should this be logged only once like summary?
@@ -303,8 +371,18 @@ class TestProcessExecutor : public TestFixture {
303371 TODO_ASSERT (output_s.find (" Check time: " + fprefix () + " _2.cpp: " ) != std::string::npos);
304372 }
305373
306- // TODO: test clang-tidy
307374 // TODO: test whole program analysis
308375};
309376
310- REGISTER_TEST (TestProcessExecutor)
377+ class TestProcessExecutorFiles : public TestProcessExecutorBase {
378+ public:
379+ TestProcessExecutorFiles () : TestProcessExecutorBase(" TestProcessExecutorFiles" , false ) {}
380+ };
381+
382+ class TestProcessExecutorFS : public TestProcessExecutorBase {
383+ public:
384+ TestProcessExecutorFS () : TestProcessExecutorBase(" TestProcessExecutorFS" , true ) {}
385+ };
386+
387+ REGISTER_TEST (TestProcessExecutorFiles)
388+ REGISTER_TEST(TestProcessExecutorFS)
0 commit comments