test: generalize HasReason and use it in FailFmtWithError

Co-authored-by: Hodlinator <172445034+hodlinator@users.noreply.github.com>
This commit is contained in:
Lőrinc
2024-09-18 13:40:23 +02:00
parent ab0b5706b2
commit 6c3c619b35
2 changed files with 5 additions and 8 deletions

View File

@@ -5,6 +5,7 @@
#include <util/string.h>
#include <boost/test/unit_test.hpp>
#include <test/util/setup_common.h>
using namespace util;
@@ -21,9 +22,7 @@ inline void PassFmt(util::ConstevalFormatString<NumArgs> fmt)
template <unsigned WrongNumArgs>
inline void FailFmtWithError(std::string_view wrong_fmt, std::string_view error)
{
using ErrType = const char*;
auto check_throw{[error](const ErrType& str) { return str == error; }};
BOOST_CHECK_EXCEPTION(util::ConstevalFormatString<WrongNumArgs>::Detail_CheckNumFormatSpecifiers(wrong_fmt), ErrType, check_throw);
BOOST_CHECK_EXCEPTION(util::ConstevalFormatString<WrongNumArgs>::Detail_CheckNumFormatSpecifiers(wrong_fmt), const char*, HasReason(error));
}
BOOST_AUTO_TEST_CASE(ConstevalFormatString_NumSpec)