mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
test: generalize HasReason and use it in FailFmtWithError
Co-authored-by: Hodlinator <172445034+hodlinator@users.noreply.github.com>
This commit is contained in:
parent
ab0b5706b2
commit
6c3c619b35
2 changed files with 5 additions and 8 deletions
|
@ -274,11 +274,9 @@ std::ostream& operator<<(std::ostream& os, const uint256& num);
|
||||||
class HasReason
|
class HasReason
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
explicit HasReason(const std::string& reason) : m_reason(reason) {}
|
explicit HasReason(std::string_view reason) : m_reason(reason) {}
|
||||||
bool operator()(const std::exception& e) const
|
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()); }
|
||||||
return std::string(e.what()).find(m_reason) != std::string::npos;
|
|
||||||
};
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string m_reason;
|
const std::string m_reason;
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
#include <util/string.h>
|
#include <util/string.h>
|
||||||
|
|
||||||
#include <boost/test/unit_test.hpp>
|
#include <boost/test/unit_test.hpp>
|
||||||
|
#include <test/util/setup_common.h>
|
||||||
|
|
||||||
using namespace util;
|
using namespace util;
|
||||||
|
|
||||||
|
@ -21,9 +22,7 @@ inline void PassFmt(util::ConstevalFormatString<NumArgs> fmt)
|
||||||
template <unsigned WrongNumArgs>
|
template <unsigned WrongNumArgs>
|
||||||
inline void FailFmtWithError(std::string_view wrong_fmt, std::string_view error)
|
inline void FailFmtWithError(std::string_view wrong_fmt, std::string_view error)
|
||||||
{
|
{
|
||||||
using ErrType = const char*;
|
BOOST_CHECK_EXCEPTION(util::ConstevalFormatString<WrongNumArgs>::Detail_CheckNumFormatSpecifiers(wrong_fmt), const char*, HasReason(error));
|
||||||
auto check_throw{[error](const ErrType& str) { return str == error; }};
|
|
||||||
BOOST_CHECK_EXCEPTION(util::ConstevalFormatString<WrongNumArgs>::Detail_CheckNumFormatSpecifiers(wrong_fmt), ErrType, check_throw);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(ConstevalFormatString_NumSpec)
|
BOOST_AUTO_TEST_CASE(ConstevalFormatString_NumSpec)
|
||||||
|
|
Loading…
Add table
Reference in a new issue