2019-08-02 17:06:37 -04:00
|
|
|
// Copyright (c) 2019 The Bitcoin Core developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2019-11-05 17:18:59 -03:00
|
|
|
#include <test/util/logging.h>
|
2019-08-02 17:06:37 -04:00
|
|
|
|
|
|
|
#include <logging.h>
|
|
|
|
#include <noui.h>
|
|
|
|
#include <tinyformat.h>
|
|
|
|
#include <util/memory.h>
|
|
|
|
|
|
|
|
#include <stdexcept>
|
|
|
|
|
2020-04-21 12:41:35 -04:00
|
|
|
DebugLogHelper::DebugLogHelper(std::string message, MatchFn match)
|
|
|
|
: m_message{std::move(message)}, m_match(std::move(match))
|
2019-08-02 17:06:37 -04:00
|
|
|
{
|
|
|
|
m_print_connection = LogInstance().PushBackCallback(
|
|
|
|
[this](const std::string& s) {
|
|
|
|
if (m_found) return;
|
2020-04-21 12:41:35 -04:00
|
|
|
m_found = s.find(m_message) != std::string::npos && m_match(&s);
|
2019-08-02 17:06:37 -04:00
|
|
|
});
|
|
|
|
noui_test_redirect();
|
|
|
|
}
|
|
|
|
|
|
|
|
void DebugLogHelper::check_found()
|
|
|
|
{
|
|
|
|
noui_reconnect();
|
|
|
|
LogInstance().DeleteCallback(m_print_connection);
|
2020-04-21 12:41:35 -04:00
|
|
|
if (!m_found && m_match(nullptr)) {
|
2019-08-02 17:06:37 -04:00
|
|
|
throw std::runtime_error(strprintf("'%s' not found in debug log\n", m_message));
|
|
|
|
}
|
|
|
|
}
|