@@ -12,13 +12,27 @@ using util::detail::CheckNumFormatSpecifiers;
1212
1313BOOST_AUTO_TEST_SUITE (util_string_tests)
1414
15+ template <unsigned NumArgs>
16+ void TfmFormatZeroes(const std::string& fmt)
17+ {
18+ std::apply ([&](auto ... args) {
19+ (void )tfm::format (fmt, args...);
20+ }, std::array<int , NumArgs>{});
21+ }
22+
1523// Helper to allow compile-time sanity checks while providing the number of
1624// args directly. Normally PassFmt<sizeof...(Args)> would be used.
1725template <unsigned NumArgs>
1826void PassFmt (ConstevalFormatString<NumArgs> fmt)
1927{
2028 // Execute compile-time check again at run-time to get code coverage stats
2129 BOOST_CHECK_NO_THROW (CheckNumFormatSpecifiers<NumArgs>(fmt.fmt ));
30+
31+ // If ConstevalFormatString didn't throw above, make sure tinyformat doesn't
32+ // throw either for the same format string and parameter count combination.
33+ // Proves that we have some extent of protection from runtime errors
34+ // (tinyformat may still throw for some type mismatches).
35+ BOOST_CHECK_NO_THROW (TfmFormatZeroes<NumArgs>(fmt.fmt ));
2236}
2337template <unsigned WrongNumArgs>
2438void FailFmtWithError (const char * wrong_fmt, std::string_view error)
@@ -111,6 +125,15 @@ BOOST_AUTO_TEST_CASE(ConstevalFormatString_NumSpec)
111125 FailFmtWithError<2 >(" %1$*2$" , err_term);
112126 FailFmtWithError<2 >(" %1$.*2$" , err_term);
113127 FailFmtWithError<2 >(" %1$9.*2$" , err_term);
128+
129+ // Ensure that tinyformat throws if format string contains wrong number
130+ // of specifiers. PassFmt relies on this to verify tinyformat successfully
131+ // formats the strings, and will need to be updated if tinyformat is changed
132+ // not to throw on failure.
133+ BOOST_CHECK_EXCEPTION (TfmFormatZeroes<2 >(" %s" ), tfm::format_error,
134+ HasReason{" tinyformat: Not enough conversion specifiers in format string" });
135+ BOOST_CHECK_EXCEPTION (TfmFormatZeroes<1 >(" %s %s" ), tfm::format_error,
136+ HasReason{" tinyformat: Too many conversion specifiers in format string" });
114137}
115138
116139BOOST_AUTO_TEST_SUITE_END ()
0 commit comments