aboutsummaryrefslogtreecommitdiff
path: root/src/test/main.cpp
diff options
context:
space:
mode:
authorVasil Dimov <vd@FreeBSD.org>2021-10-08 18:11:40 +0200
committerVasil Dimov <vd@FreeBSD.org>2022-01-11 11:53:30 +0100
commit92a0f7e58d4b6323d21f1c45d4c20266c35df030 (patch)
tree1f51f10f2aae10beaaf897c014510f3df10bd396 /src/test/main.cpp
parentc561f2f06ed25f08f7776ac41aeb2999ebe79550 (diff)
downloadbitcoin-92a0f7e58d4b6323d21f1c45d4c20266c35df030.tar.xz
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 ```
Diffstat (limited to 'src/test/main.cpp')
-rw-r--r--src/test/main.cpp15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/test/main.cpp b/src/test/main.cpp
index 5885564074..1ad8fcce3a 100644
--- a/src/test/main.cpp
+++ b/src/test/main.cpp
@@ -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;
+};