Skip to content

Commit

Permalink
test: Document non-parity between tinyformat and ConstevalFormatstring
Browse files Browse the repository at this point in the history
- for "%n" (which is supposed write to the arg for printf).
- for string/integer mismatches of width/precision specifiers.

Co-Authored-By: Ryan Ofsky <[email protected]>
  • Loading branch information
hodlinator and ryanofsky committed Dec 5, 2024
1 parent 4352596 commit f71933c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/test/util_string_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,17 @@ BOOST_AUTO_TEST_CASE(ConstevalFormatString_NumSpec)
FailFmtWithError<2>("%1$.*2$", err_term);
FailFmtWithError<2>("%1$9.*2$", err_term);

// Non-parity between tinyformat and ConstevalFormatString
BOOST_CHECK_NO_THROW(util::detail::CheckNumFormatSpecifiers<1>("%n"));
BOOST_CHECK_EXCEPTION(tfm::format(std::string{"%n"}, 0), tfm::format_error,
HasReason{"tinyformat: %n conversion spec not supported"});
BOOST_CHECK_NO_THROW(util::detail::CheckNumFormatSpecifiers<2>("%*s"));
BOOST_CHECK_EXCEPTION(tfm::format(std::string{"%*s"}, "hi", "hi"), tfm::format_error,
HasReason{"tinyformat: Cannot convert from argument type to integer for use as variable width or precision"});
BOOST_CHECK_NO_THROW(util::detail::CheckNumFormatSpecifiers<2>("%.*s"));
BOOST_CHECK_EXCEPTION(tfm::format(std::string{"%.*s"}, "hi", "hi"), tfm::format_error,
HasReason{"tinyformat: Cannot convert from argument type to integer for use as variable width or precision"});

// Belt & suspenders for tinyformat behavior
BOOST_CHECK_EXCEPTION(TfmFormatZeroes<2>("%s"), tfm::format_error,
HasReason{"tinyformat: Not enough conversion specifiers in format string"});
Expand Down
2 changes: 2 additions & 0 deletions test/lint/run-lint-format-strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
FALSE_POSITIVES = [
("src/clientversion.cpp", "strprintf(_(COPYRIGHT_HOLDERS), COPYRIGHT_HOLDERS_SUBSTITUTION)"),
("src/test/translation_tests.cpp", "strprintf(format, arg)"),
("src/test/util_string_tests.cpp", 'tfm::format(std::string{"%*s"}, "hi", "hi")'),
("src/test/util_string_tests.cpp", 'tfm::format(std::string{"%.*s"}, "hi", "hi")'),
]


Expand Down

0 comments on commit f71933c

Please sign in to comment.