MCPcopy Create free account
hub / github.com/cppcheck-opensource/cppcheck / checkWithFSInternal

Method checkWithFSInternal

test/testcppcheck.cpp:255–325  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

253 }
254
255 void checkWithFSInternal(const std::string& fname, bool tools, bool nocmd = false) const
256 {
257 REDIRECT;
258 ScopedFile file(fname,
259 "void f()\n"
260 "{\n"
261 " (void)(*((int*)0));\n"
262 "}");
263
264 int called = 0;
265 std::unordered_set<std::string> addons;
266 std::vector<AddonInfo> addonInfo;
267 if (tools)
268 {
269 addons.emplace("testcppcheck");
270 addonInfo.emplace_back(/*AddonInfo()*/);
271 }
272 const auto s = dinit(Settings,
273 $.templateFormat = templateFormat,
274 $.clangTidy = tools,
275 $.addons = std::move (addons),
276 $.addonInfos = std::move (addonInfo));
277 Suppressions supprs;
278 ErrorLogger2 errorLogger;
279 CppCheck::ExecuteCmdFn f;
280 if (tools && !nocmd) {
281 f = getExecuteCommand(fname, called);
282 }
283 CppCheck cppcheck(s, supprs, errorLogger, nullptr, false, f);
284 FileSettings fs{file.path(), Path::identify(file.path(), false), 0};
285 ASSERT_EQUALS(1, cppcheck.check(fs));
286 // TODO: how to properly disable these warnings?
287 errorLogger.ids.erase(std::remove_if(errorLogger.ids.begin(), errorLogger.ids.end(), [](const std::string& id) {
288 return id == "logChecker";
289 }), errorLogger.ids.end());
290 errorLogger.errmsgs.erase(std::remove_if(errorLogger.errmsgs.begin(), errorLogger.errmsgs.end(), [](const ErrorMessage& msg) {
291 return msg.id == "logChecker";
292 }), errorLogger.errmsgs.end());
293 if (tools)
294 {
295 ASSERT_EQUALS(2, errorLogger.ids.size());
296 auto it = errorLogger.errmsgs.cbegin();
297 ASSERT_EQUALS("nullPointer", it->id);
298 ++it;
299
300 if (nocmd)
301 {
302 ASSERT_EQUALS("internalError", it->id);
303 ASSERT_EQUALS("Bailing out from analysis: Checking file failed: Failed to execute addon - no command callback provided", it->shortMessage()); // TODO: add addon name
304
305 // TODO: needs to become a proper error
306 ASSERT_EQUALS("Failed to execute '" + exename_("clang-tidy") + "' (no command callback provided)\n", GET_REDIRECT_ERROUT);
307
308 ASSERT_EQUALS(0, called); // not called because we check if the callback exists
309 }
310 else
311 {
312 ASSERT_EQUALS("internalError", it->id);

Callers

nothing calls this directly

Calls 5

checkMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected