refactor test: Profit from using namespace + using detail function

Also adds BOOST_CHECK_NO_THROW() while touching that line, clarifying part of what we are checking for.

Also removed redundant inline from template functions in .cpp file.
This commit is contained in:
Hodlinator 2024-12-06 21:45:18 +01:00
parent 083770adbe
commit b81a465995
No known key found for this signature in database

View file

@ -8,21 +8,22 @@
#include <test/util/setup_common.h> #include <test/util/setup_common.h>
using namespace util; using namespace util;
using util::detail::CheckNumFormatSpecifiers;
BOOST_AUTO_TEST_SUITE(util_string_tests) BOOST_AUTO_TEST_SUITE(util_string_tests)
// Helper to allow compile-time sanity checks while providing the number of // Helper to allow compile-time sanity checks while providing the number of
// args directly. Normally PassFmt<sizeof...(Args)> would be used. // args directly. Normally PassFmt<sizeof...(Args)> would be used.
template <unsigned NumArgs> template <unsigned NumArgs>
inline void PassFmt(util::ConstevalFormatString<NumArgs> fmt) void PassFmt(ConstevalFormatString<NumArgs> fmt)
{ {
// Execute compile-time check again at run-time to get code coverage stats // Execute compile-time check again at run-time to get code coverage stats
util::detail::CheckNumFormatSpecifiers<NumArgs>(fmt.fmt); BOOST_CHECK_NO_THROW(CheckNumFormatSpecifiers<NumArgs>(fmt.fmt));
} }
template <unsigned WrongNumArgs> template <unsigned WrongNumArgs>
inline void FailFmtWithError(const char* wrong_fmt, std::string_view error) void FailFmtWithError(const char* wrong_fmt, std::string_view error)
{ {
BOOST_CHECK_EXCEPTION(util::detail::CheckNumFormatSpecifiers<WrongNumArgs>(wrong_fmt), const char*, HasReason{error}); BOOST_CHECK_EXCEPTION(CheckNumFormatSpecifiers<WrongNumArgs>(wrong_fmt), const char*, HasReason{error});
} }
BOOST_AUTO_TEST_CASE(ConstevalFormatString_NumSpec) BOOST_AUTO_TEST_CASE(ConstevalFormatString_NumSpec)