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

Method unique_errors_2

test/testcppcheck.cpp:394–435  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

392 }
393
394 void unique_errors_2() const
395 {
396 ScopedFile test_file("c.c",
397 "void f()\n"
398 "{\n"
399 "const long m[9] = {};\n"
400 "long a=m[9], b=m[9];\n"
401 "(void)a;\n"
402 "(void)b;\n"
403 "}");
404
405 // this is the "simple" format
406 const auto s = dinit(Settings, $.templateFormat = templateFormat); // TODO: remove when we only longer rely on toString() in unique message handling?
407 Suppressions supprs;
408 ErrorLogger2 errorLogger;
409 CppCheck cppcheck(s, supprs, errorLogger, nullptr, false, {});
410 ASSERT_EQUALS(1, cppcheck.check(FileWithDetails(test_file.path(), Path::identify(test_file.path(), false), 0)));
411 // TODO: how to properly disable these warnings?
412 errorLogger.errmsgs.erase(std::remove_if(errorLogger.errmsgs.begin(), errorLogger.errmsgs.end(), [](const ErrorMessage& msg) {
413 return msg.id == "logChecker";
414 }), errorLogger.errmsgs.end());
415 // the internal errorlist is cleared after each check() call
416 ASSERT_EQUALS(2, errorLogger.errmsgs.size());
417 auto it = errorLogger.errmsgs.cbegin();
418 ASSERT_EQUALS("c.c", it->file0);
419 ASSERT_EQUALS(1, it->callStack.size());
420 {
421 auto stack = it->callStack.cbegin();
422 ASSERT_EQUALS(4, stack->line);
423 ASSERT_EQUALS(9, stack->column);
424 }
425 ASSERT_EQUALS("arrayIndexOutOfBounds", it->id);
426 ++it;
427 ASSERT_EQUALS("c.c", it->file0);
428 ASSERT_EQUALS(1, it->callStack.size());
429 {
430 auto stack = it->callStack.cbegin();
431 ASSERT_EQUALS(4, stack->line);
432 ASSERT_EQUALS(17, stack->column);
433 }
434 ASSERT_EQUALS("arrayIndexOutOfBounds", it->id);
435 }
436
437 void isPremiumCodingStandardId() const {
438 Suppressions supprs;

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