Skip to content

Commit 988edd2

Browse files
authored
TestSingleExecutor: test clang-tidy invocation (#5294)
1 parent dcdf67a commit 988edd2

6 files changed

Lines changed: 59 additions & 5 deletions

File tree

cli/processexecutor.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,11 @@ unsigned int ProcessExecutor::check()
280280

281281
if (iFileSettings != mSettings.project.fileSettings.end()) {
282282
resultOfCheck = fileChecker.check(*iFileSettings);
283+
// TODO: call analyseClangTidy()
283284
} else {
284285
// Read file from a file
285286
resultOfCheck = fileChecker.check(iFile->first);
287+
// TODO: call analyseClangTidy()?
286288
}
287289

288290
pipewriter.writeEnd(std::to_string(resultOfCheck));

cli/singleexecutor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ unsigned int SingleExecutor::check()
6161
processedsize += i->second;
6262
if (!mSettings.quiet)
6363
reportStatus(c + 1, mFiles.size(), processedsize, totalfilesize);
64-
// TODO: call analyseClangTidy()
64+
// TODO: call analyseClangTidy()?
6565
c++;
6666
}
6767
}
@@ -92,7 +92,7 @@ unsigned int SingleExecutor::check()
9292
processedsize += i->second;
9393
if (!mSettings.quiet)
9494
reportStatus(c + 1, mFiles.size(), processedsize, totalfilesize);
95-
// TODO: call analyseClangTidy()
95+
// TODO: call analyseClangTidy()?
9696
c++;
9797
}
9898
}

cli/threadexecutor.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ class ThreadData
129129
} else {
130130
// Read file from a file
131131
result = fileChecker.check(*file);
132+
// TODO: call analyseClangTidy()?
132133
}
133134
return result;
134135
}

test/testprocessexecutor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,9 @@ class TestProcessExecutor : public TestFixture {
229229
output.str());*/
230230
settings = settingsOld;
231231
}
232+
233+
// TODO: test clang-tidy
234+
// TODO: test whole program analysis
232235
};
233236

234237
REGISTER_TEST(TestProcessExecutor)

test/testsingleexecutor.cpp

Lines changed: 48 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

test/testthreadexecutor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,9 @@ class TestThreadExecutor : public TestFixture {
228228
output.str());*/
229229
settings = settingsOld;
230230
}
231+
232+
// TODO: test clang-tidy
233+
// TODO: test whole program analysis
231234
};
232235

233236
REGISTER_TEST(TestThreadExecutor)

0 commit comments

Comments
 (0)