From b8932e67fc0989089703e96fae7ee2626b6656ff Mon Sep 17 00:00:00 2001 From: Yonas Habteab Date: Tue, 10 Sep 2024 11:03:50 +0200 Subject: [PATCH] tests: Fix test `FormatDateTime` with invalid formats on macOS/*BSD --- test/base-utility.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/test/base-utility.cpp b/test/base-utility.cpp index 8fe1814da..51eba962b 100644 --- a/test/base-utility.cpp +++ b/test/base-utility.cpp @@ -199,7 +199,16 @@ 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 percentLessOutput(format); + // `strftime(3)` seems to return the provided invalid format specifiers on all Platforms as documented above, + // i.e. even on macOS, but the macOS/*BSD libc implementations of `strftime(3)` appears to behave differently + // and 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. + percentLessOutput.erase(std::remove(percentLessOutput.begin(), percentLessOutput.end(), '%'), percentLessOutput.end()); + + BOOST_CHECK_MESSAGE(result.empty() || result == format || result == percentLessOutput, "FormatDateTime(" << std::quoted(format) << ", " << ts << ") = " << std::quoted(result) << " should be one of [\"\", " << std::quoted(format) << "]"); }