Skip to content

Commit 6c3c619

Browse files
l0rinchodlinator
andcommitted
test: generalize HasReason and use it in FailFmtWithError
Co-authored-by: Hodlinator <[email protected]>
1 parent ab0b570 commit 6c3c619

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/test/util/setup_common.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,9 @@ std::ostream& operator<<(std::ostream& os, const uint256& num);
274274
class HasReason
275275
{
276276
public:
277-
explicit HasReason(const std::string& reason) : m_reason(reason) {}
278-
bool operator()(const std::exception& e) const
279-
{
280-
return std::string(e.what()).find(m_reason) != std::string::npos;
281-
};
277+
explicit HasReason(std::string_view reason) : m_reason(reason) {}
278+
bool operator()(std::string_view s) const { return s.find(m_reason) != std::string_view::npos; }
279+
bool operator()(const std::exception& e) const { return (*this)(e.what()); }
282280

283281
private:
284282
const std::string m_reason;

src/test/util_string_tests.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <util/string.h>
66

77
#include <boost/test/unit_test.hpp>
8+
#include <test/util/setup_common.h>
89

910
using namespace util;
1011

@@ -21,9 +22,7 @@ inline void PassFmt(util::ConstevalFormatString<NumArgs> fmt)
2122
template <unsigned WrongNumArgs>
2223
inline void FailFmtWithError(std::string_view wrong_fmt, std::string_view error)
2324
{
24-
using ErrType = const char*;
25-
auto check_throw{[error](const ErrType& str) { return str == error; }};
26-
BOOST_CHECK_EXCEPTION(util::ConstevalFormatString<WrongNumArgs>::Detail_CheckNumFormatSpecifiers(wrong_fmt), ErrType, check_throw);
25+
BOOST_CHECK_EXCEPTION(util::ConstevalFormatString<WrongNumArgs>::Detail_CheckNumFormatSpecifiers(wrong_fmt), const char*, HasReason(error));
2726
}
2827

2928
BOOST_AUTO_TEST_CASE(ConstevalFormatString_NumSpec)

0 commit comments

Comments
 (0)