mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 22:18:54 +01:00
test: parse the command line arguments in unit tests
Retrieve the command line arguments from boost and pass them to `BasicTestingSetup` so that we gain extra flexibility of passing any config options on the test command line, e.g.: ``` test_bitcoin -- -printtoconsole=1 -checkaddrman=5 ```
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
|
||||
/** Redirect debug log to unit_test.log files */
|
||||
@@ -24,3 +25,17 @@ const std::function<void(const std::string&)> G_TEST_LOG_FUN = [](const std::str
|
||||
if (!should_log) return;
|
||||
std::cout << s;
|
||||
};
|
||||
|
||||
/**
|
||||
* 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;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user