Adding a dependency on setup_common.h is a case of making implicit dependencies explicit in my view. What the current version signifies is a different argument description (starting with "Run benchmarks " like the others) and a default directory value that can't be as clear as the original. We shouldn't be duplicating code snippets to avoid #includes. Even if it minimizes the size of this specific PR, going forward one has to make sure to keep both the original and duplicated place up to date which I argue is a worse state of tech debt.
I'm happy to hear stronger counter-arguments if you feel it's worth your time, but I can understand if you want to drop this subject too.
Summarizing my intent:
diff --git a/src/bench/bench_bitcoin.cpp b/src/bench/bench_bitcoin.cpp
index 3d649a8436..3ae3f7dd4c 100644
--- a/src/bench/bench_bitcoin.cpp
+++ b/src/bench/bench_bitcoin.cpp
@@ -8,6 +8,7 @@
#include <tinyformat.h>
#include <util/fs.h>
#include <util/string.h>
+#include <test/util/setup_common.h>
#include <chrono>
#include <cstdint>
@@ -37,7 +38,7 @@ static void SetupBenchArgs(ArgsManager& argsman)
argsman.AddArg("-sanity-check", "Run benchmarks for only one iteration with no output", ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
argsman.AddArg("-priority-level=<l1,l2,l3>", strprintf("Run benchmarks of one or multiple priority level(s) (%s), default: '%s'",
benchmark::ListPriorities(), DEFAULT_PRIORITY), ArgsManager::ALLOW_ANY, OptionsCategory::OPTIONS);
- argsman.AddArg("-testdatadir", "Run benchmarks on a custom directory (default: </tmp/>)", ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
+ SetupCommonTestArgs(argsman);
}
// parses a comma separated list like "10,20,30,50"
diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp
index fa89ceb332..2471290fe9 100644
--- a/src/test/util/setup_common.cpp
+++ b/src/test/util/setup_common.cpp
@@ -87,8 +87,8 @@ struct NetworkSetup
};
static NetworkSetup g_networksetup_instance;
-/** Register test-only arguments */
-static void SetupUnitTestArgs(ArgsManager& argsman)
+/** Register common test and bench arguments */
+void SetupCommonTestArgs(ArgsManager& argsman)
{
argsman.AddArg("-testdatadir", strprintf("Custom data directory (default: %s<random_string>)", fs::PathToString(fs::temp_directory_path() / TEST_DIR_PATH_ELEMENT / "")),
ArgsManager::ALLOW_ANY, OptionsCategory::DEBUG_TEST);
@@ -126,7 +126,7 @@ BasicTestingSetup::BasicTestingSetup(const ChainType chainType, TestOpts opts)
gArgs.ClearPathCache();
{
SetupServerArgs(*m_node.args);
- SetupUnitTestArgs(*m_node.args);
+ SetupCommonTestArgs(*m_node.args);
std::string error;
if (!m_node.args->ParseParameters(arguments.size(), arguments.data(), error)) {
m_node.args->ClearArgs();
diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h
index f5a3c0dcee..4d8b9370ca 100644
--- a/src/test/util/setup_common.h
+++ b/src/test/util/setup_common.h
@@ -45,6 +45,8 @@ extern const std::function<std::string()> G_TEST_GET_FULL_NAME;
static constexpr CAmount CENT{1000000};
+void SetupCommonTestArgs(ArgsManager& argsman);
+
struct TestOpts {
std::vector<const char*> extra_args{};
bool coins_db_in_memory{true};