mirror of https://github.com/Icinga/icinga2.git
Merge pull request #10149 from Icinga/fix-format-datetime-tests-on-darwin
tests: Fix test `FormatDateTime` with invalid formats on macOS/*BSD
This commit is contained in:
commit
8beb0b74ab
|
@ -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) << "]");
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue