Skip to content

Commit

Permalink
tests: Fix test FormatDateTime with invalid formats on MacOS
Browse files Browse the repository at this point in the history
  • Loading branch information
yhabteab committed Sep 10, 2024
1 parent c0b047b commit 838d20d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion test/base-utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,15 @@ BOOST_AUTO_TEST_CASE(FormatDateTime) {
// treat them as an error which our implementation currently maps to the empty string due to strftime() not
// properly reporting errors. If this limitation of our implementation is lifted, other behavior like throwing
// an exception would also be valid.
BOOST_CHECK_MESSAGE(result.empty() || result == format,

std::string darwinBug(format);
// On Darwin/MacOS, strftime() appears to have a nasty bug that causes the '%' character not to be
// populated into the results buffer if invalid format specifiers such as "x %! y" are given.
// If such specifiers are provided, the output will contain "x ! y" instead of the given invalid
// format specifiers.
darwinBug.erase(std::remove(darwinBug.begin(), darwinBug.end(), '%'), darwinBug.end());

BOOST_CHECK_MESSAGE(result.empty() || result == format || result == darwinBug,
"FormatDateTime(" << std::quoted(format) << ", " << ts << ") = " << std::quoted(result) <<
" should be one of [\"\", " << std::quoted(format) << "]");
}
Expand Down

0 comments on commit 838d20d

Please sign in to comment.