[libcxx-commits] [libcxx] dbe6894 - [libc++] Extract std::fprintf into a function for use within the test suite

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Tue Mar 7 06:07:30 PST 2023


Author: Louis Dionne
Date: 2023-03-07T09:07:19-05:00
New Revision: dbe6894ac634b96b4156c6becd0825be6e9639ab

URL: https://github.com/llvm/llvm-project/commit/dbe6894ac634b96b4156c6becd0825be6e9639ab
DIFF: https://github.com/llvm/llvm-project/commit/dbe6894ac634b96b4156c6becd0825be6e9639ab.diff

LOG: [libc++] Extract std::fprintf into a function for use within the test suite

This provides a single place for downstream to customize (or turn off)
printing information to stderr within the test suite.

Differential Revision: https://reviews.llvm.org/D145405

Added: 
    

Modified: 
    libcxx/test/support/assert_macros.h
    libcxx/test/support/concat_macros.h

Removed: 
    


################################################################################
diff  --git a/libcxx/test/support/assert_macros.h b/libcxx/test/support/assert_macros.h
index eb143896ba72a..bf382e19d5e04 100644
--- a/libcxx/test/support/assert_macros.h
+++ b/libcxx/test/support/assert_macros.h
@@ -29,14 +29,23 @@
 #include <cstdio>
 #include <cstdlib>
 
+// 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 <class ...Args>
+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 <class F>
 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
index 4dadf95a18eef..d6396a76dde73 100644
--- a/libcxx/test/support/concat_macros.h
+++ b/libcxx/test/support/concat_macros.h
@@ -12,6 +12,7 @@
 #include <cstdio>
 #include <string>
 
+#include "assert_macros.h"
 #include "test_macros.h"
 
 #ifndef TEST_HAS_NO_LOCALIZATION
@@ -46,7 +47,7 @@ std::string test_concat_message([[maybe_unused]] Args&&... args) {
 }
 
 // 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
 


        


More information about the libcxx-commits mailing list