test: refactor, decouple HasReason from test framework machinery
What changed, and why it matters
This is a harmless code cleanup in Bitcoin Core's test suite. It moves a small helper class called HasReason from a large test-framework header into a smaller, more focused header so that simple unit tests don't need to pull in the entire testing framework. There is no change to how the software behaves in production, no bug fix, and no security issue.
No security action needed. This is a routine refactoring change and can be reviewed as normal code quality.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit refactors the test-only HasReason predicate class from src/test/util/setup_common.h into src/test/util/common.h. It then updates test files that only need HasReason to include the lighter common.h instead of the heavier setup_common.h. The class implementation is unchanged. This is purely a build/test dependency hygiene change.
Changed components
src/test/util/common.hsrc/test/util/setup_common.hsrc/ipc/test/ipc_tests.cppsrc/test/httpserver_tests.cppsrc/test/net_tests.cppsrc/test/reverselock_tests.cppsrc/test/script_parse_tests.cppsrc/test/sock_tests.cppsrc/test/sync_tests.cppsrc/test/system_tests.cppsrc/test/util_check_tests.cppsrc/test/util_string_tests.cppInspect captured patch +26 / −21
diff --git a/src/ipc/test/ipc_tests.cpp b/src/ipc/test/ipc_tests.cpp
index cc03904e..ebe4b397 100644
--- a/src/ipc/test/ipc_tests.cpp
+++ b/src/ipc/test/ipc_tests.cpp
@@ -5,6 +5,7 @@
#include <ipc/process.h>
#include <ipc/test/ipc_test.h>
+#include <test/util/common.h>
#include <test/util/setup_common.h>
#include <boost/test/unit_test.hpp>
diff --git a/src/test/httpserver_tests.cpp b/src/test/httpserver_tests.cpp
index 2770c0c3..030d48db 100644
--- a/src/test/httpserver_tests.cpp
+++ b/src/test/httpserver_tests.cpp
@@ -3,6 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <httpserver.h>
+#include <test/util/common.h>
#include <test/util/setup_common.h>
#include <boost/test/unit_test.hpp>
diff --git a/src/test/net_tests.cpp b/src/test/net_tests.cpp
index defec028..1fc8d526 100644
--- a/src/test/net_tests.cpp
+++ b/src/test/net_tests.cpp
@@ -15,6 +15,7 @@
#include <serialize.h>
#include <span.h>
#include <streams.h>
+#include <test/util/common.h>
#include <test/util/net.h>
#include <test/util/random.h>
#include <test/util/setup_common.h>
diff --git a/src/test/reverselock_tests.cpp b/src/test/reverselock_tests.cpp
index b792dbe4..20edb22a 100644
--- a/src/test/reverselock_tests.cpp
+++ b/src/test/reverselock_tests.cpp
@@ -3,7 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <sync.h>
-#include <test/util/setup_common.h>
+#include <test/util/common.h>
#include <boost/test/unit_test.hpp>
diff --git a/src/test/script_parse_tests.cpp b/src/test/script_parse_tests.cpp
index a4e01120..9f67215e 100644
--- a/src/test/script_parse_tests.cpp
+++ b/src/test/script_parse_tests.cpp
@@ -5,7 +5,7 @@
#include <core_io.h>
#include <script/script.h>
#include <util/strencodings.h>
-#include <test/util/setup_common.h>
+#include <test/util/common.h>
#include <boost/test/unit_test.hpp>
diff --git a/src/test/sock_tests.cpp b/src/test/sock_tests.cpp
index 98f25279..2b7e4a78 100644
--- a/src/test/sock_tests.cpp
+++ b/src/test/sock_tests.cpp
@@ -4,6 +4,7 @@
#include <common/system.h>
#include <compat/compat.h>
+#include <test/util/common.h>
#include <test/util/setup_common.h>
#include <util/sock.h>
#include <util/threadinterrupt.h>
diff --git a/src/test/sync_tests.cpp b/src/test/sync_tests.cpp
index 9240691b..09a96be9 100644
--- a/src/test/sync_tests.cpp
+++ b/src/test/sync_tests.cpp
@@ -3,7 +3,7 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
#include <sync.h>
-#include <test/util/setup_common.h>
+#include <test/util/common.h>
#include <boost/test/unit_test.hpp>
diff --git a/src/test/system_tests.cpp b/src/test/system_tests.cpp
index f4490dec..f960a3d8 100644
--- a/src/test/system_tests.cpp
+++ b/src/test/system_tests.cpp
@@ -6,6 +6,7 @@
#include <bitcoin-build-config.h> // IWYU pragma: keep
#include <common/run_command.h>
+#include <test/util/common.h>
#include <test/util/setup_common.h>
#include <univalue.h>
#include <util/string.h>
diff --git a/src/test/util/common.h b/src/test/util/common.h
index c19c0888..591f651f 100644
--- a/src/test/util/common.h
+++ b/src/test/util/common.h
@@ -9,6 +9,22 @@
#include <optional>
#include <string>
+/**
+ * BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
+ * Use as
+ * BOOST_CHECK_EXCEPTION(code that throws, exception type, HasReason("foo"));
+ */
+class HasReason
+{
+public:
+ explicit HasReason(std::string_view reason) : m_reason(reason) {}
+ bool operator()(std::string_view s) const { return s.find(m_reason) != std::string_view::npos; }
+ bool operator()(const std::exception& e) const { return (*this)(e.what()); }
+
+private:
+ const std::string m_reason;
+};
+
// Make types usable in BOOST_CHECK_* @{
namespace std {
template <typename T> requires std::is_enum_v<T>
diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h
index cc0d7ffd..c02a4fd3 100644
--- a/src/test/util/setup_common.h
+++ b/src/test/util/setup_common.h
@@ -261,20 +261,4 @@ std::unique_ptr<T> MakeNoLogFileContext(const ChainType chain_type = ChainType::
CBlock getBlock13b8a();
-/**
- * BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
- * Use as
- * BOOST_CHECK_EXCEPTION(code that throws, exception type, HasReason("foo"));
- */
-class HasReason
-{
-public:
- explicit HasReason(std::string_view reason) : m_reason(reason) {}
- bool operator()(std::string_view s) const { return s.find(m_reason) != std::string_view::npos; }
- bool operator()(const std::exception& e) const { return (*this)(e.what()); }
-
-private:
- const std::string m_reason;
-};
-
#endif // BITCOIN_TEST_UTIL_SETUP_COMMON_H
diff --git a/src/test/util_check_tests.cpp b/src/test/util_check_tests.cpp
index 93ac9194..0053f9bd 100644
--- a/src/test/util_check_tests.cpp
+++ b/src/test/util_check_tests.cpp
@@ -5,7 +5,7 @@
#include <util/check.h>
#include <boost/test/unit_test.hpp>
-#include <test/util/setup_common.h>
+#include <test/util/common.h>
BOOST_AUTO_TEST_SUITE(util_check_tests)
diff --git a/src/test/util_string_tests.cpp b/src/test/util_string_tests.cpp
index ad737ce9..77576950 100644
--- a/src/test/util_string_tests.cpp
+++ b/src/test/util_string_tests.cpp
@@ -8,7 +8,7 @@
#include <boost/test/unit_test.hpp>
#include <test/util/common.h>
-#include <test/util/setup_common.h>
+#include <tinyformat.h>
using namespace util;
using util::detail::CheckNumFormatSpecifiers;
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.