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

Louis Dionne via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Mon Mar 6 11:07:53 PST 2023


ldionne created this revision.
Herald added a project: All.
ldionne requested review of this revision.
Herald added a project: libc++.
Herald added a subscriber: libcxx-commits.
Herald added a reviewer: libc++.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D145405

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


Index: libcxx/test/support/concat_macros.h
===================================================================
--- libcxx/test/support/concat_macros.h
+++ 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 @@
 }
 
 // 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
 
Index: libcxx/test/support/assert_macros.h
===================================================================
--- libcxx/test/support/assert_macros.h
+++ 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();
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145405.502735.patch
Type: text/x-patch
Size: 1934 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20230306/49089d17/attachment.bin>


More information about the libcxx-commits mailing list