diff --git a/libcxx/test/support/assert_macros.h b/libcxx/test/support/assert_macros.h --- a/libcxx/test/support/assert_macros.h +++ b/libcxx/test/support/assert_macros.h @@ -29,14 +29,23 @@ #include #include +// This function prints the given arguments to standard error. +// +// Keeping this as a separate function is important since it provides a single point for +// downstreams to customize how errors are printed on exotic targets, if needed. +template +void test_eprintf(char const* fmt, Args const& ...args) { + std::fprintf(stderr, fmt, args...); +} + void test_log(const char* condition, const char* file, int line, const char* message) { const char* msg = condition ? "Assertion failure: " : "Unconditional failure:"; - std::fprintf(stderr, "%s%s %s %d\n%s", msg, condition, file, line, message); + test_eprintf("%s%s %s %d\n%s", msg, condition, file, line, message); } template void test_log(const char* condition, const char* file, int line, const F& functor) { - std::fprintf(stderr, "Assertion failure: %s %s %d\n", condition, file, line); + test_eprintf("Assertion failure: %s %s %d\n", condition, file, line); functor(); } diff --git a/libcxx/test/support/concat_macros.h b/libcxx/test/support/concat_macros.h --- a/libcxx/test/support/concat_macros.h +++ b/libcxx/test/support/concat_macros.h @@ -12,6 +12,7 @@ #include #include +#include "assert_macros.h" #include "test_macros.h" #ifndef TEST_HAS_NO_LOCALIZATION @@ -46,7 +47,7 @@ } // Writes its arguments to stderr, using the test_concat_message helper. -# define TEST_WRITE_CONCATENATED(...) [&] { ::std::fprintf(stderr, "%s", ::test_concat_message(__VA_ARGS__).c_str()); } +# define TEST_WRITE_CONCATENATED(...) [&] { ::test_eprintf("%s", ::test_concat_message(__VA_ARGS__).c_str()); } #endif // TEST_STD_VER > 17