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

Method checkWithFileInternal

test/testcppcheck.cpp:171–241  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169 }
170
171 void checkWithFileInternal(const std::string& fname, bool tools, bool nocmd = false) const
172 {
173 REDIRECT;
174 ScopedFile file(fname,
175 "void f()\n"
176 "{\n"
177 " (void)(*((int*)0));\n"
178 "}");
179
180 int called = 0;
181 std::unordered_set<std::string> addons;
182 std::vector<AddonInfo> addonInfo;
183 if (tools)
184 {
185 addons.emplace("testcppcheck");
186 addonInfo.emplace_back(/*AddonInfo()*/);
187 }
188 const auto s = dinit(Settings,
189 $.templateFormat = templateFormat,
190 $.clangTidy = tools,
191 $.addons = std::move (addons),
192 $.addonInfos = std::move (addonInfo));
193 Suppressions supprs;
194 ErrorLogger2 errorLogger;
195 CppCheck::ExecuteCmdFn f;
196 if (tools && !nocmd) {
197 f = getExecuteCommand(fname, called);
198 }
199 CppCheck cppcheck(s, supprs, errorLogger, nullptr, false, f);
200 ASSERT_EQUALS(1, cppcheck.check(FileWithDetails(file.path(), Path::identify(file.path(), false), 0)));
201 // TODO: how to properly disable these warnings?
202 errorLogger.ids.erase(std::remove_if(errorLogger.ids.begin(), errorLogger.ids.end(), [](const std::string& id) {
203 return id == "logChecker";
204 }), errorLogger.ids.end());
205 errorLogger.errmsgs.erase(std::remove_if(errorLogger.errmsgs.begin(), errorLogger.errmsgs.end(), [](const ErrorMessage& msg) {
206 return msg.id == "logChecker";
207 }), errorLogger.errmsgs.end());
208 if (tools)
209 {
210 ASSERT_EQUALS(2, errorLogger.ids.size());
211 auto it = errorLogger.errmsgs.cbegin();
212 ASSERT_EQUALS("nullPointer", it->id);
213 ++it;
214
215 if (nocmd)
216 {
217 ASSERT_EQUALS("internalError", it->id);
218 ASSERT_EQUALS("Bailing out from analysis: Checking file failed: Failed to execute addon - no command callback provided", it->shortMessage()); // TODO: add addon name
219
220 // TODO: clang-tidy is currently not invoked for file inputs - see #12053
221 // TODO: needs to become a proper error
222 TODO_ASSERT_EQUALS("Failed to execute '" + exename_("clang-tidy") + "' (no command callback provided)\n", "", GET_REDIRECT_ERROUT);
223
224 ASSERT_EQUALS(0, called); // not called because we check if the callback exists
225 }
226 else
227 {
228 ASSERT_EQUALS("internalError", it->id);

Callers

nothing calls this directly

Calls 6

FileWithDetailsClass · 0.50
checkMethod · 0.45
eraseMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected