Skip to content

Commit 76cca4a

Browse files
hodlinatorryanofsky
andcommitted
test: Document non-parity between tinyformat and ConstevalFormatstring
- For "%n", which is supposed to write to the argument for printf. - For string/integer mismatches of width/precision specifiers. Co-Authored-By: Ryan Ofsky <ryan@ofsky.org>
1 parent 533013c commit 76cca4a

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/test/util_string_tests.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,15 @@ BOOST_AUTO_TEST_CASE(ConstevalFormatString_NumSpec)
126126
FailFmtWithError<2>("%1$.*2$", err_term);
127127
FailFmtWithError<2>("%1$9.*2$", err_term);
128128

129+
// Non-parity between tinyformat and ConstevalFormatString.
130+
// tinyformat throws but ConstevalFormatString does not.
131+
BOOST_CHECK_EXCEPTION(tfm::format(ConstevalFormatString<1>{"%n"}, 0), tfm::format_error,
132+
HasReason{"tinyformat: %n conversion spec not supported"});
133+
BOOST_CHECK_EXCEPTION(tfm::format(ConstevalFormatString<2>{"%*s"}, "hi", "hi"), tfm::format_error,
134+
HasReason{"tinyformat: Cannot convert from argument type to integer for use as variable width or precision"});
135+
BOOST_CHECK_EXCEPTION(tfm::format(ConstevalFormatString<2>{"%.*s"}, "hi", "hi"), tfm::format_error,
136+
HasReason{"tinyformat: Cannot convert from argument type to integer for use as variable width or precision"});
137+
129138
// Ensure that tinyformat throws if format string contains wrong number
130139
// of specifiers. PassFmt relies on this to verify tinyformat successfully
131140
// formats the strings, and will need to be updated if tinyformat is changed

test/lint/run-lint-format-strings.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
FALSE_POSITIVES = [
1616
("src/clientversion.cpp", "strprintf(_(COPYRIGHT_HOLDERS), COPYRIGHT_HOLDERS_SUBSTITUTION)"),
1717
("src/test/translation_tests.cpp", "strprintf(format, arg)"),
18+
("src/test/util_string_tests.cpp", 'tfm::format(ConstevalFormatString<2>{"%*s"}, "hi", "hi")'),
19+
("src/test/util_string_tests.cpp", 'tfm::format(ConstevalFormatString<2>{"%.*s"}, "hi", "hi")'),
1820
]
1921

2022

0 commit comments

Comments
 (0)