[libc-commits] [libc] 0fd0b74 - [libc][NFC] Clean up matchers namespace

Guillaume Chatelet via libc-commits libc-commits at lists.llvm.org
Fri Jun 9 23:55:25 PDT 2023


Author: Guillaume Chatelet
Date: 2023-06-10T06:55:16Z
New Revision: 0fd0b7428925bc3531d1412561c4f05038fb65d5

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

LOG: [libc][NFC] Clean up matchers namespace

This is a follow up to https://reviews.llvm.org/D152503

Reviewed By: sivachandra

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

Added: 
    

Modified: 
    libc/test/UnitTest/ErrnoSetterMatcher.h
    libc/test/UnitTest/FPExceptMatcher.cpp
    libc/test/UnitTest/FPExceptMatcher.h
    libc/test/UnitTest/MemoryMatcher.cpp
    libc/test/UnitTest/MemoryMatcher.h
    libc/test/UnitTest/PrintfMatcher.cpp
    libc/test/UnitTest/PrintfMatcher.h
    libc/test/UnitTest/ScanfMatcher.cpp
    libc/test/UnitTest/ScanfMatcher.h
    libc/test/src/__support/File/file_test.cpp
    libc/test/src/stdio/fopencookie_test.cpp
    libc/test/src/time/TmMatcher.h

Removed: 
    


################################################################################
diff  --git a/libc/test/UnitTest/ErrnoSetterMatcher.h b/libc/test/UnitTest/ErrnoSetterMatcher.h
index a93d194e13d72..1d786c7e462b1 100644
--- a/libc/test/UnitTest/ErrnoSetterMatcher.h
+++ b/libc/test/UnitTest/ErrnoSetterMatcher.h
@@ -45,24 +45,20 @@ template <typename T> class ErrnoSetterMatcher : public Matcher<T> {
   void explainError() override {
     if (ActualReturn != ExpectedReturn) {
       if constexpr (cpp::is_floating_point_v<T>) {
-        __llvm_libc::testing::tlog
-            << "Expected return value to be: "
-            << str(__llvm_libc::fputil::FPBits<T>(ExpectedReturn)) << '\n';
-        __llvm_libc::testing::tlog
-            << "                    But got: "
-            << str(__llvm_libc::fputil::FPBits<T>(ActualReturn)) << '\n';
+        tlog << "Expected return value to be: "
+             << str(fputil::FPBits<T>(ExpectedReturn)) << '\n';
+        tlog << "                    But got: "
+             << str(fputil::FPBits<T>(ActualReturn)) << '\n';
       } else {
-        __llvm_libc::testing::tlog << "Expected return value to be "
-                                   << ExpectedReturn << " but got "
-                                   << ActualReturn << ".\n";
+        tlog << "Expected return value to be " << ExpectedReturn << " but got "
+             << ActualReturn << ".\n";
       }
     }
 
     if constexpr (!ignore_errno()) {
       if (ActualErrno != ExpectedErrno) {
-        __llvm_libc::testing::tlog
-            << "Expected errno to be \"" << get_error_string(ExpectedErrno)
-            << "\" but got \"" << get_error_string(ActualErrno) << "\".\n";
+        tlog << "Expected errno to be \"" << get_error_string(ExpectedErrno)
+             << "\" but got \"" << get_error_string(ActualErrno) << "\".\n";
       }
     }
   }

diff  --git a/libc/test/UnitTest/FPExceptMatcher.cpp b/libc/test/UnitTest/FPExceptMatcher.cpp
index b8b30d58ed255..c712fec01d485 100644
--- a/libc/test/UnitTest/FPExceptMatcher.cpp
+++ b/libc/test/UnitTest/FPExceptMatcher.cpp
@@ -14,7 +14,6 @@
 #include <signal.h>
 
 namespace __llvm_libc {
-namespace fputil {
 namespace testing {
 
 #if defined(_WIN32)
@@ -48,5 +47,4 @@ FPExceptMatcher::FPExceptMatcher(FunctionCaller *func) {
 }
 
 } // namespace testing
-} // namespace fputil
 } // namespace __llvm_libc

diff  --git a/libc/test/UnitTest/FPExceptMatcher.h b/libc/test/UnitTest/FPExceptMatcher.h
index e17b1e2883b50..1563561854abd 100644
--- a/libc/test/UnitTest/FPExceptMatcher.h
+++ b/libc/test/UnitTest/FPExceptMatcher.h
@@ -14,12 +14,11 @@
 #include "test/UnitTest/Test.h"
 
 namespace __llvm_libc {
-namespace fputil {
 namespace testing {
 
 // TODO: Make the matcher match specific exceptions instead of just identifying
 // that an exception was raised.
-class FPExceptMatcher : public __llvm_libc::testing::Matcher<bool> {
+class FPExceptMatcher : public Matcher<bool> {
   bool exceptionRaised;
 
 public:
@@ -45,22 +44,19 @@ class FPExceptMatcher : public __llvm_libc::testing::Matcher<bool> {
   bool match(bool unused) { return exceptionRaised; }
 
   void explainError() override {
-    __llvm_libc::testing::tlog
-        << "A floating point exception should have been raised but it "
-        << "wasn't\n";
+    tlog << "A floating point exception should have been raised but it "
+         << "wasn't\n";
   }
 };
 
 } // namespace testing
-} // namespace fputil
 } // namespace __llvm_libc
 
 #define ASSERT_RAISES_FP_EXCEPT(func)                                          \
   ASSERT_THAT(                                                                 \
       true,                                                                    \
-      __llvm_libc::fputil::testing::FPExceptMatcher(                           \
-          __llvm_libc::fputil::testing::FPExceptMatcher::getFunctionCaller(    \
-              func)))
+      __llvm_libc::testing::FPExceptMatcher(                                   \
+          __llvm_libc::testing::FPExceptMatcher::getFunctionCaller(func)))
 #else
 #define ASSERT_RAISES_FP_EXCEPT(func) ASSERT_DEATH(func, WITH_SIGNAL(SIGFPE))
 #endif // LIBC_COPT_TEST_USE_FUCHSIA

diff  --git a/libc/test/UnitTest/MemoryMatcher.cpp b/libc/test/UnitTest/MemoryMatcher.cpp
index 03fe7b34bc315..32f7d5e17e020 100644
--- a/libc/test/UnitTest/MemoryMatcher.cpp
+++ b/libc/test/UnitTest/MemoryMatcher.cpp
@@ -13,7 +13,6 @@
 using __llvm_libc::testing::tlog;
 
 namespace __llvm_libc {
-namespace memory {
 namespace testing {
 
 template <typename T>
@@ -76,5 +75,4 @@ void MemoryMatcher::explainError() {
 }
 
 } // namespace testing
-} // namespace memory
 } // namespace __llvm_libc

diff  --git a/libc/test/UnitTest/MemoryMatcher.h b/libc/test/UnitTest/MemoryMatcher.h
index 5e61ac70935de..e3df4c09315c9 100644
--- a/libc/test/UnitTest/MemoryMatcher.h
+++ b/libc/test/UnitTest/MemoryMatcher.h
@@ -14,38 +14,36 @@
 #include "test/UnitTest/Test.h"
 
 namespace __llvm_libc {
-namespace memory {
 namespace testing {
 
 using MemoryView = __llvm_libc::cpp::span<const char>;
 
 } // namespace testing
-} // namespace memory
 } // namespace __llvm_libc
 
 #ifdef LIBC_COPT_TEST_USE_FUCHSIA
 
 #define EXPECT_MEM_EQ(expected, actual)                                        \
   do {                                                                         \
-    __llvm_libc::memory::testing::MemoryView e = (expected);                   \
-    __llvm_libc::memory::testing::MemoryView a = (actual);                     \
+    __llvm_libc::testing::MemoryView e = (expected);                           \
+    __llvm_libc::testing::MemoryView a = (actual);                             \
     ASSERT_EQ(e.size(), a.size());                                             \
     EXPECT_BYTES_EQ(e.data(), a.data(), e.size());                             \
   } while (0)
 
 #define ASSERT_MEM_EQ(expected, actual)                                        \
   do {                                                                         \
-    __llvm_libc::memory::testing::MemoryView e = (expected);                   \
-    __llvm_libc::memory::testing::MemoryView a = (actual);                     \
+    __llvm_libc::testing::MemoryView e = (expected);                           \
+    __llvm_libc::testing::MemoryView a = (actual);                             \
     ASSERT_EQ(e.size(), a.size());                                             \
     ASSERT_BYTES_EQ(e.data(), a.data(), e.size());                             \
   } while (0)
 
 #else
 
-namespace __llvm_libc::memory::testing {
+namespace __llvm_libc::testing {
 
-class MemoryMatcher : public __llvm_libc::testing::Matcher<MemoryView> {
+class MemoryMatcher : public Matcher<MemoryView> {
   MemoryView expected;
   MemoryView actual;
   bool mismatch_size = false;
@@ -59,12 +57,12 @@ class MemoryMatcher : public __llvm_libc::testing::Matcher<MemoryView> {
   void explainError() override;
 };
 
-} // namespace __llvm_libc::memory::testing
+} // namespace __llvm_libc::testing
 
 #define EXPECT_MEM_EQ(expected, actual)                                        \
-  EXPECT_THAT(actual, __llvm_libc::memory::testing::MemoryMatcher(expected))
+  EXPECT_THAT(actual, __llvm_libc::testing::MemoryMatcher(expected))
 #define ASSERT_MEM_EQ(expected, actual)                                        \
-  ASSERT_THAT(actual, __llvm_libc::memory::testing::MemoryMatcher(expected))
+  ASSERT_THAT(actual, __llvm_libc::testing::MemoryMatcher(expected))
 
 #endif
 

diff  --git a/libc/test/UnitTest/PrintfMatcher.cpp b/libc/test/UnitTest/PrintfMatcher.cpp
index 39af53da5a929..019eafcfb4b22 100644
--- a/libc/test/UnitTest/PrintfMatcher.cpp
+++ b/libc/test/UnitTest/PrintfMatcher.cpp
@@ -16,12 +16,13 @@
 
 #include <stdint.h>
 
-using __llvm_libc::testing::tlog;
-
 namespace __llvm_libc {
-namespace printf_core {
 namespace testing {
 
+using printf_core::FormatFlags;
+using printf_core::FormatSection;
+using printf_core::LengthModifier;
+
 bool FormatSectionMatcher::match(FormatSection actualValue) {
   actual = actualValue;
   return expected == actual;
@@ -93,5 +94,4 @@ void FormatSectionMatcher::explainError() {
 }
 
 } // namespace testing
-} // namespace printf_core
 } // namespace __llvm_libc

diff  --git a/libc/test/UnitTest/PrintfMatcher.h b/libc/test/UnitTest/PrintfMatcher.h
index 6c0a9d8e97e47..148c9ff80931d 100644
--- a/libc/test/UnitTest/PrintfMatcher.h
+++ b/libc/test/UnitTest/PrintfMatcher.h
@@ -15,32 +15,28 @@
 #include <errno.h>
 
 namespace __llvm_libc {
-namespace printf_core {
 namespace testing {
 
-class FormatSectionMatcher
-    : public __llvm_libc::testing::Matcher<FormatSection> {
-  FormatSection expected;
-  FormatSection actual;
+class FormatSectionMatcher : public Matcher<printf_core::FormatSection> {
+  printf_core::FormatSection expected;
+  printf_core::FormatSection actual;
 
 public:
-  FormatSectionMatcher(FormatSection expectedValue) : expected(expectedValue) {}
+  FormatSectionMatcher(printf_core::FormatSection expectedValue)
+      : expected(expectedValue) {}
 
-  bool match(FormatSection actualValue);
+  bool match(printf_core::FormatSection actualValue);
 
   void explainError() override;
 };
 
 } // namespace testing
-} // namespace printf_core
 } // namespace __llvm_libc
 
 #define EXPECT_PFORMAT_EQ(expected, actual)                                    \
-  EXPECT_THAT(actual, __llvm_libc::printf_core::testing::FormatSectionMatcher( \
-                          expected))
+  EXPECT_THAT(actual, __llvm_libc::testing::FormatSectionMatcher(expected))
 
 #define ASSERT_PFORMAT_EQ(expected, actual)                                    \
-  ASSERT_THAT(actual, __llvm_libc::printf_core::testing::FormatSectionMatcher( \
-                          expected))
+  ASSERT_THAT(actual, __llvm_libc::testing::FormatSectionMatcher(expected))
 
 #endif // LLVM_LIBC_UTILS_UNITTEST_PRINTF_MATCHER_H

diff  --git a/libc/test/UnitTest/ScanfMatcher.cpp b/libc/test/UnitTest/ScanfMatcher.cpp
index 3d2f23db77aab..7374858910d54 100644
--- a/libc/test/UnitTest/ScanfMatcher.cpp
+++ b/libc/test/UnitTest/ScanfMatcher.cpp
@@ -16,12 +16,13 @@
 
 #include <stdint.h>
 
-using __llvm_libc::testing::tlog;
-
 namespace __llvm_libc {
-namespace scanf_core {
 namespace testing {
 
+using scanf_core::FormatFlags;
+using scanf_core::FormatSection;
+using scanf_core::LengthModifier;
+
 bool FormatSectionMatcher::match(FormatSection actualValue) {
   actual = actualValue;
   return expected == actual;
@@ -98,5 +99,4 @@ void FormatSectionMatcher::explainError() {
 }
 
 } // namespace testing
-} // namespace scanf_core
 } // namespace __llvm_libc

diff  --git a/libc/test/UnitTest/ScanfMatcher.h b/libc/test/UnitTest/ScanfMatcher.h
index 020bdf94412b0..864a35d74adeb 100644
--- a/libc/test/UnitTest/ScanfMatcher.h
+++ b/libc/test/UnitTest/ScanfMatcher.h
@@ -15,32 +15,28 @@
 #include <errno.h>
 
 namespace __llvm_libc {
-namespace scanf_core {
 namespace testing {
 
-class FormatSectionMatcher
-    : public __llvm_libc::testing::Matcher<FormatSection> {
-  FormatSection expected;
-  FormatSection actual;
+class FormatSectionMatcher : public Matcher<scanf_core::FormatSection> {
+  scanf_core::FormatSection expected;
+  scanf_core::FormatSection actual;
 
 public:
-  FormatSectionMatcher(FormatSection expectedValue) : expected(expectedValue) {}
+  FormatSectionMatcher(scanf_core::FormatSection expectedValue)
+      : expected(expectedValue) {}
 
-  bool match(FormatSection actualValue);
+  bool match(scanf_core::FormatSection actualValue);
 
   void explainError() override;
 };
 
 } // namespace testing
-} // namespace scanf_core
 } // namespace __llvm_libc
 
 #define EXPECT_SFORMAT_EQ(expected, actual)                                    \
-  EXPECT_THAT(actual, __llvm_libc::scanf_core::testing::FormatSectionMatcher(  \
-                          expected))
+  EXPECT_THAT(actual, __llvm_libc::testing::FormatSectionMatcher(expected))
 
 #define ASSERT_SFORMAT_EQ(expected, actual)                                    \
-  ASSERT_THAT(actual, __llvm_libc::scanf_core::testing::FormatSectionMatcher(  \
-                          expected))
+  ASSERT_THAT(actual, __llvm_libc::testing::FormatSectionMatcher(expected))
 
 #endif // LLVM_LIBC_UTILS_UNITTEST_SCANF_MATCHER_H

diff  --git a/libc/test/src/__support/File/file_test.cpp b/libc/test/src/__support/File/file_test.cpp
index 8287f38d3ac69..c8cb1e3daea26 100644
--- a/libc/test/src/__support/File/file_test.cpp
+++ b/libc/test/src/__support/File/file_test.cpp
@@ -16,7 +16,7 @@
 #include <stdlib.h>
 
 using ModeFlags = __llvm_libc::File::ModeFlags;
-using MemoryView = __llvm_libc::memory::testing::MemoryView;
+using MemoryView = __llvm_libc::testing::MemoryView;
 using __llvm_libc::ErrorOr;
 using __llvm_libc::File;
 using __llvm_libc::FileIOResult;

diff  --git a/libc/test/src/stdio/fopencookie_test.cpp b/libc/test/src/stdio/fopencookie_test.cpp
index 139700634ace8..cfdaef2149f5b 100644
--- a/libc/test/src/stdio/fopencookie_test.cpp
+++ b/libc/test/src/stdio/fopencookie_test.cpp
@@ -22,7 +22,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 
-using MemoryView = __llvm_libc::memory::testing::MemoryView;
+using MemoryView = __llvm_libc::testing::MemoryView;
 
 struct StringStream {
   char *buf;

diff  --git a/libc/test/src/time/TmMatcher.h b/libc/test/src/time/TmMatcher.h
index b881b14002402..fb2d57bb99add 100644
--- a/libc/test/src/time/TmMatcher.h
+++ b/libc/test/src/time/TmMatcher.h
@@ -14,10 +14,9 @@
 #include "test/UnitTest/Test.h"
 
 namespace __llvm_libc {
-namespace tmmatcher {
 namespace testing {
 
-class StructTmMatcher : public __llvm_libc::testing::Matcher<::tm> {
+class StructTmMatcher : public Matcher<::tm> {
   ::tm expected;
   ::tm actual;
 
@@ -38,17 +37,17 @@ class StructTmMatcher : public __llvm_libc::testing::Matcher<::tm> {
   }
 
   void describeValue(const char *label, ::tm value) {
-    __llvm_libc::testing::tlog << label;
-    __llvm_libc::testing::tlog << " sec: " << value.tm_sec;
-    __llvm_libc::testing::tlog << " min: " << value.tm_min;
-    __llvm_libc::testing::tlog << " hour: " << value.tm_hour;
-    __llvm_libc::testing::tlog << " mday: " << value.tm_mday;
-    __llvm_libc::testing::tlog << " mon: " << value.tm_mon;
-    __llvm_libc::testing::tlog << " year: " << value.tm_year;
-    __llvm_libc::testing::tlog << " wday: " << value.tm_wday;
-    __llvm_libc::testing::tlog << " yday: " << value.tm_yday;
-    __llvm_libc::testing::tlog << " isdst: " << value.tm_isdst;
-    __llvm_libc::testing::tlog << '\n';
+    tlog << label;
+    tlog << " sec: " << value.tm_sec;
+    tlog << " min: " << value.tm_min;
+    tlog << " hour: " << value.tm_hour;
+    tlog << " mday: " << value.tm_mday;
+    tlog << " mon: " << value.tm_mon;
+    tlog << " year: " << value.tm_year;
+    tlog << " wday: " << value.tm_wday;
+    tlog << " yday: " << value.tm_yday;
+    tlog << " isdst: " << value.tm_isdst;
+    tlog << '\n';
   }
 
   void explainError() override {
@@ -58,11 +57,9 @@ class StructTmMatcher : public __llvm_libc::testing::Matcher<::tm> {
 };
 
 } // namespace testing
-} // namespace tmmatcher
 } // namespace __llvm_libc
 
 #define EXPECT_TM_EQ(expected, actual)                                         \
-  EXPECT_THAT((actual),                                                        \
-              __llvm_libc::tmmatcher::testing::StructTmMatcher((expected)))
+  EXPECT_THAT((actual), __llvm_libc::testing::StructTmMatcher((expected)))
 
 #endif // LLVM_LIBC_TEST_SRC_TIME_TM_MATCHER_H


        


More information about the libc-commits mailing list