2020-04-16 13:14:08 -04:00
|
|
|
// Copyright (c) 2011-2020 The Bitcoin Core developers
|
2019-02-28 14:51:11 -05:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2019-09-27 11:53:34 -04:00
|
|
|
/**
|
|
|
|
* See https://www.boost.org/doc/libs/1_71_0/libs/test/doc/html/boost_test/utf_reference/link_references/link_boost_test_module_macro.html
|
|
|
|
*/
|
2019-02-28 14:51:11 -05:00
|
|
|
#define BOOST_TEST_MODULE Bitcoin Core Test Suite
|
|
|
|
|
|
|
|
#include <boost/test/unit_test.hpp>
|
2019-09-27 11:53:34 -04:00
|
|
|
|
|
|
|
#include <test/util/setup_common.h>
|
|
|
|
|
2021-10-08 18:11:40 +02:00
|
|
|
#include <functional>
|
2020-03-30 13:59:13 -04:00
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
/** Redirect debug log to unit_test.log files */
|
2019-09-27 11:53:34 -04:00
|
|
|
const std::function<void(const std::string&)> G_TEST_LOG_FUN = [](const std::string& s) {
|
2020-03-30 13:59:13 -04:00
|
|
|
static const bool should_log{std::any_of(
|
|
|
|
&boost::unit_test::framework::master_test_suite().argv[1],
|
|
|
|
&boost::unit_test::framework::master_test_suite().argv[boost::unit_test::framework::master_test_suite().argc],
|
|
|
|
[](const char* arg) {
|
|
|
|
return std::string{"DEBUG_LOG_OUT"} == arg;
|
|
|
|
})};
|
|
|
|
if (!should_log) return;
|
|
|
|
std::cout << s;
|
2019-09-27 11:53:34 -04:00
|
|
|
};
|
2021-10-08 18:11:40 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve the command line arguments from boost.
|
|
|
|
* Allows usage like:
|
|
|
|
* `test_bitcoin --run_test="net_tests/cnode_listen_port" -- -checkaddrman=1 -printtoconsole=1`
|
|
|
|
* which would return `["-checkaddrman=1", "-printtoconsole=1"]`.
|
|
|
|
*/
|
|
|
|
const std::function<std::vector<const char*>()> G_TEST_COMMAND_LINE_ARGUMENTS = []() {
|
|
|
|
std::vector<const char*> args;
|
|
|
|
for (int i = 1; i < boost::unit_test::framework::master_test_suite().argc; ++i) {
|
|
|
|
args.push_back(boost::unit_test::framework::master_test_suite().argv[i]);
|
|
|
|
}
|
|
|
|
return args;
|
|
|
|
};
|