mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-02 09:46:14 +00:00
test: move and simplify BOOST_CHECK ostream helpers
Move the operator<< overloads used by BOOST_CHECK_* out of the unit test machinery test/setup_common, into test/util/common.h. And replace the individual per-type ToString() overloads with a single concept-constrained template that covers any type exposing a ToString() method. This is important to not add uint256.h and transaction_identifier.h dependencies to the shared test/util/common.h file. Co-authored-by: furszy <matiasfurszyfer@protonmail.com>
This commit is contained in:
parent
3b7cbcafcb
commit
dbbb780af0
@ -3,7 +3,7 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <arith_uint256.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <test/util/common.h>
|
||||
#include <uint256.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/txmempool.h>
|
||||
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#include <node/miner.h>
|
||||
#include <pow.h>
|
||||
#include <test/util/blockfilter.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <validation.h>
|
||||
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <test/data/blockfilters.json.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <test/util/common.h>
|
||||
|
||||
#include <blockfilter.h>
|
||||
#include <core_io.h>
|
||||
|
||||
@ -14,6 +14,7 @@
|
||||
#include <validation.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/logging.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
#include <random.h>
|
||||
#include <serialize.h>
|
||||
#include <streams.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <uint256.h>
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#include <clientversion.h>
|
||||
#include <coins.h>
|
||||
#include <streams.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/poolresourcetester.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
#include <crypto/muhash.h>
|
||||
#include <random.h>
|
||||
#include <streams.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <util/strencodings.h>
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <dbwrapper.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <uint256.h>
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#include <common/args.h>
|
||||
#include <common/settings.h>
|
||||
#include <logging.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <univalue.h>
|
||||
#include <util/strencodings.h>
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
#include <headerssync.h>
|
||||
#include <net_processing.h>
|
||||
#include <pow.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <validation.h>
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#include <chainparams.h>
|
||||
#include <consensus/validation.h>
|
||||
#include <interfaces/chain.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <script/solver.h>
|
||||
#include <validation.h>
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
#include <span.h>
|
||||
#include <streams.h>
|
||||
#include <secp256k1_extrakeys.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <uint256.h>
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#include <logging.h>
|
||||
#include <logging/timer.h>
|
||||
#include <scheduler.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/logging.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <tinyformat.h>
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <consensus/merkle.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <merkleblock.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <uint256.h>
|
||||
|
||||
|
||||
@ -25,6 +25,7 @@
|
||||
#include <versionbits.h>
|
||||
#include <pow.h>
|
||||
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#include <minisketch.h>
|
||||
#include <node/minisketchwrapper.h>
|
||||
#include <random.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
#include <script/script_error.h>
|
||||
#include <script/sign.h>
|
||||
#include <script/signingprovider.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <test/util/transaction_utils.h>
|
||||
#include <tinyformat.h>
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#include <protocol.h>
|
||||
#include <serialize.h>
|
||||
#include <streams.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <util/strencodings.h>
|
||||
#include <util/translation.h>
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include <rpc/server.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
using node::NodeContext;
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#include <pubkey.h>
|
||||
#include <script/sign.h>
|
||||
#include <script/signingprovider.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <test/util/transaction_utils.h>
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#include <common/pcp.h>
|
||||
#include <netbase.h>
|
||||
#include <test/util/logging.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <util/time.h>
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#include <chainparams.h>
|
||||
#include <pow.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <util/chaintype.h>
|
||||
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <rest.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
#include <rpc/client.h>
|
||||
#include <rpc/server.h>
|
||||
#include <rpc/util.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <univalue.h>
|
||||
#include <util/time.h>
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#include <script/script.h>
|
||||
#include <script/signingprovider.h>
|
||||
#include <script/solver.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <util/strencodings.h>
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
#include <streams.h>
|
||||
#include <test/util/json.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <test/util/transaction_utils.h>
|
||||
#include <util/fs.h>
|
||||
@ -26,7 +27,6 @@
|
||||
#include <util/string.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#include <hash.h>
|
||||
#include <serialize.h>
|
||||
#include <streams.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <util/strencodings.h>
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include <serialize.h>
|
||||
#include <streams.h>
|
||||
#include <test/data/sighash.json.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/json.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#include <flatfile.h>
|
||||
#include <node/blockstorage.h>
|
||||
#include <streams.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <util/fs.h>
|
||||
|
||||
@ -26,6 +26,7 @@
|
||||
#include <script/signingprovider.h>
|
||||
#include <script/solver.h>
|
||||
#include <streams.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/json.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/script.h>
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
#include <node/txdownloadman_impl.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <script/script.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <validation.h>
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#include <index/txospenderindex.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <validation.h>
|
||||
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include <script/script.h>
|
||||
#include <serialize.h>
|
||||
#include <streams.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/script.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
#include <node/txreconciliation.h>
|
||||
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include <primitives/transaction.h>
|
||||
#include <random.h>
|
||||
#include <script/script.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <test/util/txmempool.h>
|
||||
#include <validation.h>
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
#include <primitives/transaction_identifier.h>
|
||||
#include <streams.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <test/util/common.h>
|
||||
#include <uint256.h>
|
||||
#include <util/strencodings.h>
|
||||
|
||||
|
||||
39
src/test/util/common.h
Normal file
39
src/test/util/common.h
Normal file
@ -0,0 +1,39 @@
|
||||
// Copyright (c) The Bitcoin Core developers
|
||||
// Distributed under the MIT software license, see the accompanying
|
||||
// file COPYING or https://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
#ifndef BITCOIN_TEST_UTIL_COMMON_H
|
||||
#define BITCOIN_TEST_UTIL_COMMON_H
|
||||
|
||||
#include <ostream>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
||||
// 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
|
||||
|
||||
template <typename T>
|
||||
concept HasToString = requires(const T& t) { t.ToString(); };
|
||||
|
||||
template <HasToString T>
|
||||
inline std::ostream& operator<<(std::ostream& os, const T& obj)
|
||||
{
|
||||
return os << obj.ToString();
|
||||
}
|
||||
|
||||
// @}
|
||||
|
||||
#endif // BITCOIN_TEST_UTIL_COMMON_H
|
||||
@ -620,26 +620,3 @@ 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();
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Txid& txid) {
|
||||
return os << txid.ToString();
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& os, const Wtxid& wtxid) {
|
||||
return os << wtxid.ToString();
|
||||
}
|
||||
|
||||
@ -261,29 +261,6 @@ std::unique_ptr<T> MakeNoLogFileContext(const ChainType chain_type = ChainType::
|
||||
|
||||
CBlock getBlock13b8a();
|
||||
|
||||
// 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);
|
||||
std::ostream& operator<<(std::ostream& os, const Txid& txid);
|
||||
std::ostream& operator<<(std::ostream& os, const Wtxid& wtxid);
|
||||
// @}
|
||||
|
||||
/**
|
||||
* BOOST_CHECK_EXCEPTION predicates to check the specific validation error.
|
||||
* Use as
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include <vector>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
using namespace util;
|
||||
|
||||
@ -9,6 +9,7 @@
|
||||
#include <script/parsing.h>
|
||||
#include <span.h>
|
||||
#include <sync.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <uint256.h>
|
||||
|
||||
@ -10,6 +10,7 @@
|
||||
#include <node/miner.h>
|
||||
#include <pow.h>
|
||||
#include <random.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/script.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
@ -11,6 +11,7 @@
|
||||
#include <script/script.h>
|
||||
#include <sync.h>
|
||||
#include <test/util/chainstate.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/coins.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
@ -12,6 +12,7 @@
|
||||
#include <rpc/blockchain.h>
|
||||
#include <sync.h>
|
||||
#include <test/util/chainstate.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/logging.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
@ -5,6 +5,7 @@
|
||||
#include <sync.h>
|
||||
#include <test/util/coins.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <validation.h>
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@
|
||||
#include <chainparams.h>
|
||||
#include <consensus/params.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <util/chaintype.h>
|
||||
#include <versionbits.h>
|
||||
|
||||
@ -7,6 +7,7 @@
|
||||
#include <policy/policy.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <random.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <util/translation.h>
|
||||
#include <wallet/coincontrol.h>
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/setup_common.h>
|
||||
#include <util/check.h>
|
||||
#include <util/fs.h>
|
||||
@ -14,7 +15,6 @@
|
||||
#include <wallet/walletutil.h>
|
||||
|
||||
#include <cstddef>
|
||||
#include <fstream>
|
||||
#include <memory>
|
||||
#include <span>
|
||||
#include <string>
|
||||
|
||||
@ -17,6 +17,7 @@
|
||||
#include <policy/policy.h>
|
||||
#include <rpc/server.h>
|
||||
#include <script/solver.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/logging.h>
|
||||
#include <test/util/random.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
#include <wallet/transaction.h>
|
||||
|
||||
#include <test/util/common.h>
|
||||
#include <wallet/test/wallet_test_fixture.h>
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
||||
@ -4,6 +4,7 @@
|
||||
|
||||
#include <wallet/test/util.h>
|
||||
#include <wallet/wallet.h>
|
||||
#include <test/util/common.h>
|
||||
#include <test/util/logging.h>
|
||||
#include <test/util/setup_common.h>
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user