[libcxx-commits] [libcxx] e7cee55 - [libc++] Remove uses of printf in some test support headers

Louis Dionne via libcxx-commits libcxx-commits at lists.llvm.org
Mon Nov 22 09:01:58 PST 2021


Author: Louis Dionne
Date: 2021-11-22T12:01:18-05:00
New Revision: e7cee55c9d6b178baae3388ae2f620b44cf51e63

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

LOG: [libc++] Remove uses of printf in some test support headers

In the test suite, we generally don't use printf or other reporting
utilities. It's not that it wouldn't be useful, it's just that some
platforms don't support IO.

Instead, we try to keep test cases small and self-contained so that
we can reasonably easily reproduce failures locally and debug them.
This patch removes printf in some of the last places in the test suite
that used it. The only remaining places are in a deque test and in the
filesystem tests. The filesystem tests are arguably fine to keep using
IO, since we're testing <filesystem>. The deque test will be handled
separately.

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

Added: 
    

Modified: 
    libcxx/test/support/controlled_allocators.h
    libcxx/test/support/type_id.h
    libcxx/test/support/uses_alloc_types.h

Removed: 
    


################################################################################
diff  --git a/libcxx/test/support/controlled_allocators.h b/libcxx/test/support/controlled_allocators.h
index b00f7fdc4a64b..fa9f04eab364e 100644
--- a/libcxx/test/support/controlled_allocators.h
+++ b/libcxx/test/support/controlled_allocators.h
@@ -183,13 +183,18 @@ struct AllocController {
 
     template <class ...Args, class Alloc, class Tp>
     bool checkConstruct(Alloc const&, Tp *p) const {
-      auto expectAlloc = &makeTypeID<Alloc>();
-      auto expectTp = &makeTypeID<Tp>();
-      auto expectArgs = &makeArgumentID<Args...>();
-      return last_construct_pointer == p &&
-          COMPARE_TYPEID(last_construct_alloc, expectAlloc) &&
-          COMPARE_TYPEID(last_construct_type, expectTp) &&
-          COMPARE_TYPEID(last_construct_args, expectArgs);
+        auto expectAlloc = &makeTypeID<Alloc>();
+        auto expectTp = &makeTypeID<Tp>();
+        auto expectArgs = &makeArgumentID<Args...>();
+        if (last_construct_pointer != p)
+            return false;
+        if (last_construct_alloc != expectAlloc)
+            return false;
+        if (last_construct_type != expectTp)
+            return false;
+        if (last_construct_args != expectArgs)
+            return false;
+        return true;
     }
 
     template <class Alloc, class Tp>

diff  --git a/libcxx/test/support/type_id.h b/libcxx/test/support/type_id.h
index 0450b88368131..c31819421579f 100644
--- a/libcxx/test/support/type_id.h
+++ b/libcxx/test/support/type_id.h
@@ -8,9 +8,7 @@
 #ifndef SUPPORT_TYPE_ID_H
 #define SUPPORT_TYPE_ID_H
 
-#include <functional>
 #include <string>
-#include <cstdio>
 #include <cassert>
 
 #include "test_macros.h"
@@ -70,20 +68,4 @@ inline  TypeID const& makeArgumentID() {
   return makeTypeIDImp<ArgumentListID<Args...>>();
 }
 
-
-// COMPARE_TYPEID(...) is a utility macro for generating diagnostics when
-// two typeid's are expected to be equal
-#define COMPARE_TYPEID(LHS, RHS) CompareTypeIDVerbose(#LHS, LHS, #RHS, RHS)
-
-inline bool CompareTypeIDVerbose(const char* LHSString, TypeID const* LHS,
-                                 const char* RHSString, TypeID const* RHS) {
-  if (*LHS == *RHS)
-    return true;
-  std::printf("TypeID's not equal:\n");
-  std::printf("%s: %s\n----------\n%s: %s\n",
-              LHSString, LHS->name().c_str(),
-              RHSString, RHS->name().c_str());
-  return false;
-}
-
 #endif // SUPPORT_TYPE_ID_H

diff  --git a/libcxx/test/support/uses_alloc_types.h b/libcxx/test/support/uses_alloc_types.h
index c849bd50db46d..94035726077e7 100644
--- a/libcxx/test/support/uses_alloc_types.h
+++ b/libcxx/test/support/uses_alloc_types.h
@@ -10,7 +10,6 @@
 #define USES_ALLOC_TYPES_H
 
 #include <cassert>
-#include <cstdio>
 #include <cstdlib>
 #include <memory>
 
@@ -44,17 +43,6 @@ inline const char* toString(UsesAllocatorType UA) {
     }
 }
 
-#define COMPARE_ALLOC_TYPE(LHS, RHS) CompareVerbose(#LHS, LHS, #RHS, RHS)
-
-inline bool CompareVerbose(const char* LHSString, UsesAllocatorType LHS,
-                           const char* RHSString, UsesAllocatorType RHS) {
-    if (LHS == RHS)
-        return true;
-    std::printf("UsesAllocatorType's don't match:\n%s %s\n----------\n%s %s\n",
-                LHSString, toString(LHS), RHSString, toString(RHS));
-    return false;
-}
-
 template <class Alloc, std::size_t N>
 class UsesAllocatorV1;
     // Implements form (1) of uses-allocator construction from the specified
@@ -191,26 +179,36 @@ struct UsesAllocatorTestBase {
     template <class ...ArgTypes>
     bool checkConstruct(UsesAllocatorType expectType) const {
         auto expectArgs = &makeArgumentID<ArgTypes...>();
-        return COMPARE_ALLOC_TYPE(expectType, constructor_called) &&
-               COMPARE_TYPEID(args_id, expectArgs);
+        if (expectType != constructor_called)
+            return false;
+        if (args_id != expectArgs)
+            return false;
+        return true;
     }
 
     template <class ...ArgTypes>
     bool checkConstruct(UsesAllocatorType expectType,
                         CtorAlloc const& expectAlloc) const {
         auto ExpectID = &makeArgumentID<ArgTypes...>() ;
-        return COMPARE_ALLOC_TYPE(expectType, constructor_called) &&
-               COMPARE_TYPEID(args_id, ExpectID) &&
-               has_alloc() && expectAlloc == *get_alloc();
-
+        if (expectType != constructor_called)
+            return false;
+        if (args_id != ExpectID)
+            return false;
+        if (!has_alloc() || expectAlloc != *get_alloc())
+            return false;
+        return true;
     }
 
     bool checkConstructEquiv(UsesAllocatorTestBase& O) const {
         if (has_alloc() != O.has_alloc())
             return false;
-        return COMPARE_ALLOC_TYPE(constructor_called, O.constructor_called)
-            && COMPARE_TYPEID(args_id, O.args_id)
-            && (!has_alloc() || *get_alloc() == *O.get_alloc());
+        if (constructor_called != O.constructor_called)
+            return false;
+        if (args_id != O.args_id)
+            return false;
+        if (has_alloc() && *get_alloc() != *O.get_alloc())
+            return false;
+        return true;
     }
 
 protected:


        


More information about the libcxx-commits mailing list