* For a given `location` and `message`, ensure that the on-disk debug log behaviour resembles what * we'd expect it to be for `status` and `suppressions_active`. */
| 400 | * we'd expect it to be for `status` and `suppressions_active`. |
| 401 | */ |
| 402 | void TestLogFromLocation(Location location, const std::string& message, |
| 403 | BCLog::LogRateLimiter::Status status, bool suppressions_active, |
| 404 | std::source_location source = std::source_location::current()) |
| 405 | { |
| 406 | BOOST_TEST_INFO_SCOPE("TestLogFromLocation called from " << source.file_name() << ":" << source.line()); |
| 407 | using Status = BCLog::LogRateLimiter::Status; |
| 408 | if (!suppressions_active) assert(status == Status::UNSUPPRESSED); // developer error |
| 409 | |
| 410 | std::ofstream ofs(LogInstance().m_file_path.std_path(), std::ios::out | std::ios::trunc); // clear debug log |
| 411 | LogFromLocation(location, message); |
| 412 | auto log_lines{ReadDebugLogLines()}; |
| 413 | BOOST_TEST_INFO_SCOPE(log_lines.size() << " log_lines read: \n" << util::Join(log_lines, "\n")); |
| 414 | |
| 415 | if (status == Status::STILL_SUPPRESSED) { |
| 416 | BOOST_CHECK_EQUAL(log_lines.size(), 0); |
| 417 | return; |
| 418 | } |
| 419 | |
| 420 | if (status == Status::NEWLY_SUPPRESSED) { |
| 421 | BOOST_REQUIRE_EQUAL(log_lines.size(), 2); |
| 422 | BOOST_CHECK(log_lines[0].starts_with("[*] [warning] Excessive logging detected")); |
| 423 | log_lines.erase(log_lines.begin()); |
| 424 | } |
| 425 | BOOST_REQUIRE_EQUAL(log_lines.size(), 1); |
| 426 | auto& payload{log_lines.back()}; |
| 427 | BOOST_CHECK_EQUAL(suppressions_active, payload.starts_with("[*]")); |
| 428 | BOOST_CHECK(payload.ends_with(message)); |
| 429 | } |
| 430 | |
| 431 | } // namespace |
| 432 |
no test coverage detected