mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-02 01:36:13 +00:00
test: refactor, decouple HasReason from test framework machinery
Avoid providing the entire unit test framework dependency to tests that only require access to the HasReason utility class. E.g. reverselock_tests.cpp, sync_tests.cpp, util_check_tests.cpp, util_string_tests.cpp, and script_parse_tests.cpp only require access to HasReason and nothing else.
This commit is contained in:
parent
dbbb780af0
commit
d9c6769d03
@ -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>
|
||||
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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>
|
||||
|
||||
|
||||
@ -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>
|
||||
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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>
|
||||
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user