TODO: how to actually get duplicated findings
| 359 | |
| 360 | // TODO: how to actually get duplicated findings |
| 361 | void unique_errors() const |
| 362 | { |
| 363 | ScopedFile file("inc.h", |
| 364 | "inline void f()\n" |
| 365 | "{\n" |
| 366 | " (void)(*((int*)0));\n" |
| 367 | "}"); |
| 368 | ScopedFile test_file_a("a.c", |
| 369 | "#include \"inc.h\""); |
| 370 | ScopedFile test_file_b("b.c", |
| 371 | "#include \"inc.h\""); |
| 372 | |
| 373 | // this is the "simple" format |
| 374 | const auto s = dinit(Settings, $.templateFormat = templateFormat); // TODO: remove when we only longer rely on toString() in unique message handling |
| 375 | Suppressions supprs; |
| 376 | ErrorLogger2 errorLogger; |
| 377 | CppCheck cppcheck(s, supprs, errorLogger, nullptr, false, {}); |
| 378 | ASSERT_EQUALS(1, cppcheck.check(FileWithDetails(test_file_a.path(), Path::identify(test_file_a.path(), false), 0))); |
| 379 | ASSERT_EQUALS(1, cppcheck.check(FileWithDetails(test_file_b.path(), Path::identify(test_file_b.path(), false), 0))); |
| 380 | // TODO: how to properly disable these warnings? |
| 381 | errorLogger.errmsgs.erase(std::remove_if(errorLogger.errmsgs.begin(), errorLogger.errmsgs.end(), [](const ErrorMessage& msg) { |
| 382 | return msg.id == "logChecker"; |
| 383 | }), errorLogger.errmsgs.end()); |
| 384 | // the internal errorlist is cleared after each check() call |
| 385 | ASSERT_EQUALS(2, errorLogger.errmsgs.size()); |
| 386 | auto it = errorLogger.errmsgs.cbegin(); |
| 387 | ASSERT_EQUALS("a.c", it->file0); |
| 388 | ASSERT_EQUALS("nullPointer", it->id); |
| 389 | ++it; |
| 390 | ASSERT_EQUALS("b.c", it->file0); |
| 391 | ASSERT_EQUALS("nullPointer", it->id); |
| 392 | } |
| 393 | |
| 394 | void unique_errors_2() const |
| 395 | { |