aboutsummaryrefslogtreecommitdiff
path: root/src/test
diff options
context:
space:
mode:
authorLőrinc <pap.lorinc@gmail.com>2024-09-01 15:09:42 +0200
committerLőrinc <pap.lorinc@gmail.com>2024-09-09 21:29:44 +0200
commit743ac30e349e181c26a2d2af0bcb93b0835ce521 (patch)
treedf88fe23b02301bd63224bda5feeb0c77a85da59 /src/test
parent712a2b5453cdf2568fece94b969d6e0923b6ba16 (diff)
downloadbitcoin-743ac30e349e181c26a2d2af0bcb93b0835ce521.tar.xz
Add std::optional support to Boost's equality check
Also moved the operators to the bottom of the file since they're less important and to group them together. Co-authored-by: Hodlinator <172445034+hodlinator@users.noreply.github.com> Co-authored-by: stickies-v <stickies-v@protonmail.com>
Diffstat (limited to 'src/test')
-rw-r--r--src/test/util/setup_common.cpp33
-rw-r--r--src/test/util/setup_common.h31
2 files changed, 36 insertions, 28 deletions
diff --git a/src/test/util/setup_common.cpp b/src/test/util/setup_common.cpp
index 10363f2247..fa89ceb332 100644
--- a/src/test/util/setup_common.cpp
+++ b/src/test/util/setup_common.cpp
@@ -78,24 +78,6 @@ constexpr inline auto TEST_DIR_PATH_ELEMENT{"test_common bitcoin"}; // Includes
/** Random context to get unique temp data dirs. Separate from m_rng, which can be seeded from a const env var */
static FastRandomContext g_rng_temp_path;
-std::ostream& operator<<(std::ostream& os, const arith_uint256& num)
-{
- os << num.ToString();
- return os;
-}
-
-std::ostream& operator<<(std::ostream& os, const uint160& num)
-{
- os << num.ToString();
- return os;
-}
-
-std::ostream& operator<<(std::ostream& os, const uint256& num)
-{
- os << num.ToString();
- return os;
-}
-
struct NetworkSetup
{
NetworkSetup()
@@ -606,3 +588,18 @@ CBlock getBlock13b8a()
stream >> TX_WITH_WITNESS(block);
return block;
}
+
+std::ostream& operator<<(std::ostream& os, const arith_uint256& num)
+{
+ return os << num.ToString();
+}
+
+std::ostream& operator<<(std::ostream& os, const uint160& num)
+{
+ return os << num.ToString();
+}
+
+std::ostream& operator<<(std::ostream& os, const uint256& num)
+{
+ return os << num.ToString();
+}
diff --git a/src/test/util/setup_common.h b/src/test/util/setup_common.h
index a9a890b1a5..30d4280fa5 100644
--- a/src/test/util/setup_common.h
+++ b/src/test/util/setup_common.h
@@ -10,6 +10,8 @@
#include <key.h>
#include <node/caches.h>
#include <node/context.h> // IWYU pragma: export
+#include <optional>
+#include <ostream>
#include <primitives/transaction.h>
#include <pubkey.h>
#include <stdexcept>
@@ -29,6 +31,8 @@ class arith_uint256;
class CFeeRate;
class Chainstate;
class FastRandomContext;
+class uint160;
+class uint256;
/** This is connected to the logger. Can be used to redirect logs to any other log */
extern const std::function<void(const std::string&)> G_TEST_LOG_FUN;
@@ -39,15 +43,6 @@ extern const std::function<std::vector<const char*>()> G_TEST_COMMAND_LINE_ARGUM
/** Retrieve the unit test name. */
extern const std::function<std::string()> G_TEST_GET_FULL_NAME;
-// Enable BOOST_CHECK_EQUAL for enum class types
-namespace std {
-template <typename T>
-std::ostream& operator<<(typename std::enable_if<std::is_enum<T>::value, std::ostream>::type& stream, const T& e)
-{
- return stream << static_cast<typename std::underlying_type<T>::type>(e);
-}
-} // namespace std
-
static constexpr CAmount CENT{1000000};
struct TestOpts {
@@ -250,10 +245,26 @@ std::unique_ptr<T> MakeNoLogFileContext(const ChainType chain_type = ChainType::
CBlock getBlock13b8a();
-// Make types usable in BOOST_CHECK_*
+// Make types usable in BOOST_CHECK_* @{
+namespace std {
+template <typename T> requires std::is_enum_v<T>
+inline std::ostream& operator<<(std::ostream& os, const T& e)
+{
+ return os << static_cast<std::underlying_type_t<T>>(e);
+}
+
+template <typename T>
+inline std::ostream& operator<<(std::ostream& os, const std::optional<T>& v)
+{
+ return v ? os << *v
+ : os << "std::nullopt";
+}
+} // namespace std
+
std::ostream& operator<<(std::ostream& os, const arith_uint256& num);
std::ostream& operator<<(std::ostream& os, const uint160& num);
std::ostream& operator<<(std::ostream& os, const uint256& num);
+// @}
/**
* BOOST_CHECK_EXCEPTION predicates to check the specific validation error.