[libc-commits] [libc] 549f019 - Revert "[libc][test] Align custom matchers with GoogleMock" (#241124)

via libc-commits libc-commits at lists.llvm.org
Tue Nov 10 20:51:30 PST 2026


Author: Kewen Meng
Date: 2026-11-10T20:51:25-08:00
New Revision: 549f019f7bfa39d249d7ff419ae05687decb18f3

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

LOG: Revert "[libc][test] Align custom matchers with GoogleMock" (#241124)

Reverts llvm/llvm-project#240616 

unblock bot. For errors, please refer
https://lab.llvm.org/buildbot/#/builders/10/builds/39183.

Added: 
    

Modified: 
    libc/.clang-tidy
    libc/test/UnitTest/ErrnoSetterMatcher.h
    libc/test/UnitTest/FPExceptMatcher.h
    libc/test/UnitTest/FPMatcher.h
    libc/test/UnitTest/LibcTest.cpp
    libc/test/UnitTest/LibcTest.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/include/sys/queue_test.cpp
    libc/test/src/sys/socket/linux/socket_test_support.h
    libc/test/src/time/TmMatcher.h
    libc/utils/MPCWrapper/MPCUtils.cpp
    libc/utils/MPCWrapper/MPCUtils.h
    libc/utils/MPFRWrapper/MPFRUtils.cpp
    libc/utils/MPFRWrapper/MPFRUtils.h

Removed: 
    


################################################################################
diff  --git a/libc/.clang-tidy b/libc/.clang-tidy
index 873d4226f05162..1b10533953f265 100644
--- a/libc/.clang-tidy
+++ b/libc/.clang-tidy
@@ -18,14 +18,6 @@ CheckOptions:
     value:           lower_case
   - key:             readability-identifier-naming.FunctionIgnoredRegexp
     value:           "_?(_[A-Za-z0-9]+)*"
-  - key:             readability-identifier-naming.MethodCase
-    value:           lower_case
-  - key:             readability-identifier-naming.MethodIgnoredRegexp
-    value:           "(_?(_[A-Za-z0-9]+)*|SetUp|TearDown|MatchAndExplain|DescribeTo|DescribeNegationTo|IsInterested)"
-  - key:             readability-identifier-naming.ConstexprMethodCase
-    value:           lower_case
-  - key:             readability-identifier-naming.ConstexprMethodIgnoredRegexp
-    value:           "(_?(_[A-Za-z0-9]+)*|MatchAndExplain|DescribeTo|DescribeNegationTo|IsInterested)"
   - key:             readability-identifier-naming.GlobalConstantCase
     value:           UPPER_CASE
   - key:             readability-identifier-naming.LocalConstantIgnoredRegexp

diff  --git a/libc/test/UnitTest/ErrnoSetterMatcher.h b/libc/test/UnitTest/ErrnoSetterMatcher.h
index 6d490824073396..6c31df81d8425e 100644
--- a/libc/test/UnitTest/ErrnoSetterMatcher.h
+++ b/libc/test/UnitTest/ErrnoSetterMatcher.h
@@ -37,7 +37,6 @@
 #include "src/__support/FPUtil/FPBits.h"
 #include "src/__support/FPUtil/fpbits_str.h"
 #include "src/__support/StringUtil/error_to_string.h"
-#include "src/__support/integer_to_string.h"
 #include "src/__support/libc_errno.h"
 #include "src/__support/macros/config.h"
 #include "src/__support/macros/properties/architectures.h"
@@ -65,7 +64,7 @@ constexpr const char *CompareMessage[] = {
 template <typename T> struct Comparator {
   CompareAction cmp;
   T expected;
-  bool compare(T actual) const {
+  bool compare(T actual) {
     switch (cmp) {
     case CompareAction::EQ:
       return actual == expected;
@@ -86,9 +85,9 @@ template <typename T> struct Comparator {
   // The NVPTX backend cannot handle circular dependencies on global variables.
   // We provide a constant dummy implementation to prevent this from occurring.
 #ifdef LIBC_TARGET_ARCH_IS_NVPTX
-  constexpr const char *str() const { return ""; }
+  constexpr const char *str() { return ""; }
 #else
-  const char *str() const { return CompareMessage[static_cast<int>(cmp)]; }
+  const char *str() { return CompareMessage[static_cast<int>(cmp)]; }
 #endif
 };
 
@@ -131,25 +130,25 @@ class ErrnoCheck {
     return false;
   }
 
-  template <typename Stream> void print_expected(Stream &os) const {
+  void print_expected() const {
     if (type == Type::EQ) {
       auto expected_str = try_get_errno_name(expected);
-      os << "equal to " << (expected_str ? *expected_str : "<unknown>") << "("
-         << expected << ")";
+      tlog << "equal to " << (expected_str ? *expected_str : "<unknown>") << "("
+           << expected << ")";
     } else if (type == Type::NE) {
       auto expected_str = try_get_errno_name(expected);
-      os << "not equal to " << (expected_str ? *expected_str : "<unknown>")
-         << "(" << expected << ")";
+      tlog << "not equal to " << (expected_str ? *expected_str : "<unknown>")
+           << "(" << expected << ")";
     } else if (type == Type::ANY_OF) {
-      os << "one of [";
+      tlog << "one of [";
       for (size_t i = 0; i < list_count; ++i) {
         auto expected_str = try_get_errno_name(expected_list[i]);
-        os << (expected_str ? *expected_str : "<unknown>") << "("
-           << expected_list[i] << ")";
+        tlog << (expected_str ? *expected_str : "<unknown>") << "("
+             << expected_list[i] << ")";
         if (i + 1 < list_count)
-          os << ", ";
+          tlog << ", ";
       }
-      os << "]";
+      tlog << "]";
     }
   }
 };
@@ -157,13 +156,8 @@ class ErrnoCheck {
 template <typename T> class ErrnoSetterMatcher : public Matcher<T> {
   Comparator<T> return_cmp;
   ErrnoCheck errno_cmp;
-  // EXPECT_THAT copies the matcher per assertion and calls MatchAndExplain
-  // twice when a match fails: once with an uninterested listener to test the
-  // condition, and again with a live listener to format the explanation. Cache
-  // libc_errno before resetting it on the first call so the explanation pass
-  // sees the original errno value.
-  mutable int actual_errno = 0;
-  mutable bool has_errno = false;
+  T actual_return;
+  int actual_errno;
 
   // Even though this is a errno matcher primarily, it has to cater to platforms
   // which do not have an errno. This predicate checks if errno matching is to
@@ -186,50 +180,39 @@ template <typename T> class ErrnoSetterMatcher : public Matcher<T> {
     return *this;
   }
 
-  bool MatchAndExplain(T got, MatchResultListener *listener) const {
-    if constexpr (!ignore_errno()) {
-      if (!has_errno) {
-        actual_errno = libc_errno;
-        libc_errno = 0;
-        has_errno = true;
-      }
-    }
-    bool ret_ok = return_cmp.compare(got);
-    bool errno_ok = ignore_errno() || errno_cmp.compare(actual_errno);
-    if (ret_ok && errno_ok)
-      return true;
-    if (!listener->IsInterested())
-      return false;
-
-    if (!ret_ok) {
+  void explainError() override {
+    if (!return_cmp.compare(actual_return)) {
       if constexpr (cpp::is_floating_point_v<T>) {
-        *listener << "Expected return value to be " << return_cmp.str() << ": "
-                  << str(fputil::FPBits<T>(return_cmp.expected)) << '\n'
-                  << "                    But got: "
-                  << str(fputil::FPBits<T>(got)) << '\n';
-      } else if constexpr (cpp::is_pointer_v<T>) {
-        const IntegerToString<uintptr_t, radix::Hex::WithPrefix> exp_hex(
-            reinterpret_cast<uintptr_t>(return_cmp.expected));
-        const IntegerToString<uintptr_t, radix::Hex::WithPrefix> got_hex(
-            reinterpret_cast<uintptr_t>(got));
-        *listener << "Expected return value to be " << return_cmp.str() << " "
-                  << exp_hex.view() << " but got " << got_hex.view() << ".\n";
+        tlog << "Expected return value to be " << return_cmp.str() << ": "
+             << str(fputil::FPBits<T>(return_cmp.expected)) << '\n'
+             << "                    But got: "
+             << str(fputil::FPBits<T>(actual_return)) << '\n';
       } else {
-        *listener << "Expected return value to be " << return_cmp.str() << " "
-                  << return_cmp.expected << " but got " << got << ".\n";
+        tlog << "Expected return value to be " << return_cmp.str() << " "
+             << return_cmp.expected << " but got " << actual_return << ".\n";
       }
     }
 
     if constexpr (!ignore_errno()) {
-      if (!errno_ok) {
+      if (!errno_cmp.compare(actual_errno)) {
         auto actual_str = try_get_errno_name(actual_errno);
-        *listener << "Expected errno to be ";
-        errno_cmp.print_expected(*listener);
-        *listener << " but got " << (actual_str ? *actual_str : "<unknown>")
-                  << "(" << actual_errno << ").\n";
+        tlog << "Expected errno to be ";
+        errno_cmp.print_expected();
+        tlog << " but got " << (actual_str ? *actual_str : "<unknown>") << "("
+             << actual_errno << ").\n";
       }
     }
-    return false;
+  }
+
+  bool match(T got) {
+    actual_return = got;
+    actual_errno = libc_errno;
+    libc_errno = 0;
+    if constexpr (ignore_errno())
+      return return_cmp.compare(actual_return);
+    else
+      return return_cmp.compare(actual_return) &&
+             errno_cmp.compare(actual_errno);
   }
 };
 

diff  --git a/libc/test/UnitTest/FPExceptMatcher.h b/libc/test/UnitTest/FPExceptMatcher.h
index 389ad515496c99..732ac09557acbf 100644
--- a/libc/test/UnitTest/FPExceptMatcher.h
+++ b/libc/test/UnitTest/FPExceptMatcher.h
@@ -12,6 +12,7 @@
 #include "src/__support/CPP/functional.h"
 #include "src/__support/macros/config.h"
 #include "test/UnitTest/Test.h"
+#include "test/UnitTest/TestLogger.h"
 
 #if LIBC_TEST_HAS_MATCHERS()
 
@@ -26,13 +27,11 @@ class FPExceptMatcher : public Matcher<bool> {
 public:
   explicit FPExceptMatcher(cpp::function_ref<void(void)> func);
 
-  bool MatchAndExplain([[maybe_unused]] bool unused,
-                       MatchResultListener *listener) const {
-    if (exceptionRaised)
-      return true;
-    *listener << "A floating point exception should have been raised but it "
-              << "wasn't\n";
-    return false;
+  bool match([[maybe_unused]] bool unused) { return exceptionRaised; }
+
+  void explainError() override {
+    tlog << "A floating point exception should have been raised but it "
+         << "wasn't\n";
   }
 };
 

diff  --git a/libc/test/UnitTest/FPMatcher.h b/libc/test/UnitTest/FPMatcher.h
index 00b368fb80b698..50a880e8f0f9b6 100644
--- a/libc/test/UnitTest/FPMatcher.h
+++ b/libc/test/UnitTest/FPMatcher.h
@@ -39,11 +39,13 @@ template <typename T, TestCond Condition> class FPMatcher : public Matcher<T> {
                 "Unsupported FPMatcher test condition.");
 
   T expected;
+  T actual;
 
 public:
   FPMatcher(T expectedValue) : expected(expectedValue) {}
 
-  bool match(T actual) const {
+  bool match(T actualValue) {
+    actual = actualValue;
     fputil::FPBits<T> actualBits(actual), expectedBits(expected);
     if (Condition == TestCond::EQ)
       return (actualBits.is_nan() && expectedBits.is_nan()) ||
@@ -56,16 +58,11 @@ template <typename T, TestCond Condition> class FPMatcher : public Matcher<T> {
            (actualBits.uintval() != expectedBits.uintval());
   }
 
-  bool MatchAndExplain(T actual, MatchResultListener *listener) const {
-    if (match(actual))
-      return true;
-    if (listener->IsInterested()) {
-      *listener << "Expected floating point value: "
-                << str(fputil::FPBits<T>(expected)) << '\n'
-                << "Actual floating point value: "
-                << str(fputil::FPBits<T>(actual)) << '\n';
-    }
-    return false;
+  void explainError() override {
+    tlog << "Expected floating point value: "
+         << str(fputil::FPBits<T>(expected)) << '\n';
+    tlog << "Actual floating point value: " << str(fputil::FPBits<T>(actual))
+         << '\n';
   }
 };
 
@@ -77,13 +74,14 @@ template <typename T, TestCond Condition> class CFPMatcher : public Matcher<T> {
                 "Unsupported CFPMatcher test condition.");
 
   T expected;
+  T actual;
 
 public:
   CFPMatcher(T expectedValue) : expected(expectedValue) {}
 
-  template <typename CFT> bool matchComplex(T actual) const {
-    const CFT *actualCmplxPtr = reinterpret_cast<const CFT *>(&actual);
-    const CFT *expectedCmplxPtr = reinterpret_cast<const CFT *>(&expected);
+  template <typename CFT> bool matchComplex() {
+    CFT *actualCmplxPtr = reinterpret_cast<CFT *>(&actual);
+    CFT *expectedCmplxPtr = reinterpret_cast<CFT *>(&expected);
     CFT actualReal = actualCmplxPtr[0];
     CFT actualImag = actualCmplxPtr[1];
     CFT expectedReal = expectedCmplxPtr[0];
@@ -111,68 +109,62 @@ template <typename T, TestCond Condition> class CFPMatcher : public Matcher<T> {
             actualImagBits.uintval() != expectedImagBits.uintval());
   }
 
-  template <typename CFT>
-  void explainErrorComplex(T actual, MatchResultListener *listener) const {
-    const CFT *actualCmplxPtr = reinterpret_cast<const CFT *>(&actual);
-    const CFT *expectedCmplxPtr = reinterpret_cast<const CFT *>(&expected);
+  template <typename CFT> void explainErrorComplex() {
+    CFT *actualCmplxPtr = reinterpret_cast<CFT *>(&actual);
+    CFT *expectedCmplxPtr = reinterpret_cast<CFT *>(&expected);
     CFT actualReal = actualCmplxPtr[0];
     CFT actualImag = actualCmplxPtr[1];
     CFT expectedReal = expectedCmplxPtr[0];
     CFT expectedImag = expectedCmplxPtr[1];
-    *listener << "Expected complex floating point value: "
-              << str(fputil::FPBits<CFT>(expectedReal)) + " + " +
-                     str(fputil::FPBits<CFT>(expectedImag)) + "i"
-              << '\n'
-              << "Actual complex floating point value: "
-              << str(fputil::FPBits<CFT>(actualReal)) + " + " +
-                     str(fputil::FPBits<CFT>(actualImag)) + "i"
-              << '\n';
+    tlog << "Expected complex floating point value: "
+         << str(fputil::FPBits<CFT>(expectedReal)) + " + " +
+                str(fputil::FPBits<CFT>(expectedImag)) + "i"
+         << '\n';
+    tlog << "Actual complex floating point value: "
+         << str(fputil::FPBits<CFT>(actualReal)) + " + " +
+                str(fputil::FPBits<CFT>(actualImag)) + "i"
+         << '\n';
   }
 
-  bool match(T actual) const {
+  bool match(T actualValue) {
+    actual = actualValue;
 #ifndef LIBC_COMPILER_IS_MSVC
     if constexpr (cpp::is_complex_type_same<T, _Complex float>())
-      return matchComplex<float>(actual);
+      return matchComplex<float>();
     else if constexpr (cpp::is_complex_type_same<T, _Complex double>())
-      return matchComplex<double>(actual);
+      return matchComplex<double>();
     else if constexpr (cpp::is_complex_type_same<T, _Complex long double>())
-      return matchComplex<long double>(actual);
+      return matchComplex<long double>();
 #ifdef LIBC_TYPES_HAS_CFLOAT16
     else if constexpr (cpp::is_complex_type_same<T, cfloat16>())
-      return matchComplex<float16>(actual);
+      return matchComplex<float16>();
 #endif // LIBC_TYPES_HAS_CFLOAT16
 #ifdef LIBC_TYPES_HAS_CFLOAT128
     else if constexpr (cpp::is_complex_type_same<T, cfloat128>())
-      return matchComplex<float128>(actual);
+      return matchComplex<float128>();
 #endif // LIBC_TYPES_HAS_CFLOAT128
 #else  // LIBC_COMPILER_IS_MSVC
-    (void)actual;
     return true;
 #endif // LIBC_COMPILER_IS_MSVC
   }
 
-  bool MatchAndExplain(T actual, MatchResultListener *listener) const {
-    if (match(actual))
-      return true;
-    if (!listener->IsInterested())
-      return false;
+  void explainError() override {
 #ifndef LIBC_COMPILER_IS_MSVC
     if constexpr (cpp::is_complex_type_same<T, _Complex float>())
-      explainErrorComplex<float>(actual, listener);
+      return explainErrorComplex<float>();
     else if constexpr (cpp::is_complex_type_same<T, _Complex double>())
-      explainErrorComplex<double>(actual, listener);
+      return explainErrorComplex<double>();
     else if constexpr (cpp::is_complex_type_same<T, _Complex long double>())
-      explainErrorComplex<long double>(actual, listener);
+      return explainErrorComplex<long double>();
 #ifdef LIBC_TYPES_HAS_CFLOAT16
     else if constexpr (cpp::is_complex_type_same<T, cfloat16>())
-      explainErrorComplex<float16>(actual, listener);
+      return explainErrorComplex<float16>();
 #endif // LIBC_TYPES_HAS_CFLOAT16
 #ifdef LIBC_TYPES_HAS_CFLOAT128
     else if constexpr (cpp::is_complex_type_same<T, cfloat128>())
-      explainErrorComplex<float128>(actual, listener);
+      return explainErrorComplex<float128>();
 #endif // LIBC_TYPES_HAS_CFLOAT128
 #endif // LIBC_COMPILER_IS_MSVC
-    return false;
   }
 };
 

diff  --git a/libc/test/UnitTest/LibcTest.cpp b/libc/test/UnitTest/LibcTest.cpp
index e5caeb070154da..a00d0ff32f1153 100644
--- a/libc/test/UnitTest/LibcTest.cpp
+++ b/libc/test/UnitTest/LibcTest.cpp
@@ -313,13 +313,21 @@ bool test_str_ne(const wchar_t *LHS, const wchar_t *RHS, const char *LHSStr,
                    RHSStr, Loc);
 }
 
-void mark_match_failure(const char *lhs_str, const char *rhs_str,
-                        Location loc) {
-  current_context->markFail();
-  tlog << loc;
-  tlog << "Failed to match " << lhs_str << " against " << rhs_str << ".\n";
+} // namespace internal
+
+bool Test::testMatch(bool MatchResult, MatcherBase &Matcher, const char *LHSStr,
+                     const char *RHSStr, internal::Location Loc) {
+  if (MatchResult)
+    return true;
+
+  internal::current_context->markFail();
+  if (!Matcher.is_silent()) {
+    tlog << Loc;
+    tlog << "Failed to match " << LHSStr << " against " << RHSStr << ".\n";
+    Matcher.explainError();
+  }
+  return false;
 }
 
-} // namespace internal
 } // namespace testing
 } // namespace LIBC_NAMESPACE_DECL

diff  --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h
index e847309a775b67..42c15fa4decf45 100644
--- a/libc/test/UnitTest/LibcTest.h
+++ b/libc/test/UnitTest/LibcTest.h
@@ -44,40 +44,17 @@ namespace testing {
 // conditions for such cases.
 enum class TestCond { EQ, NE, LT, LE, GT, GE };
 
-// Source-compatible with GoogleMock's ::testing::MatchResultListener so custom
-// matchers work unchanged under both LibcTest and GoogleTest.
-class MatchResultListener {
-  TestLogger *logger;
-
-public:
-  LIBC_INLINE explicit MatchResultListener(TestLogger *logger)
-      : logger(logger) {}
-
-  LIBC_INLINE TestLogger *stream() { return logger; }
-  LIBC_INLINE bool IsInterested() const { return logger != nullptr; }
-
-  template <typename T>
-  LIBC_INLINE MatchResultListener &operator<<(const T &val) {
-    if (logger != nullptr)
-      *logger << val;
-    return *this;
-  }
-};
-
 struct MatcherBase {
-  using is_gtest_matcher = void;
-
-  template <typename Stream> LIBC_INLINE void DescribeTo(Stream *os) const {
-    *os << "matches";
-  }
+  virtual ~MatcherBase() {}
+  virtual void explainError() { tlog << "unknown error\n"; }
+  // Override and return true to skip `explainError` step.
+  virtual bool is_silent() const { return false; }
+};
 
-  template <typename Stream>
-  LIBC_INLINE void DescribeNegationTo(Stream *os) const {
-    *os << "does not match";
-  }
+template <typename T> struct Matcher : public MatcherBase {
+  bool match(const T &t);
 };
 
-template <typename T> struct Matcher : public MatcherBase {};
 namespace internal {
 
 // A simple location object to allow consistent passing of __FILE__ and
@@ -200,20 +177,6 @@ bool test_str_ne(const char *LHS, const char *RHS, const char *LHSStr,
 bool test_str_ne(const wchar_t *LHS, const wchar_t *RHS, const char *LHSStr,
                  const char *RHSStr, internal::Location Loc);
 
-void mark_match_failure(const char *lhs_str, const char *rhs_str, Location loc);
-
-template <typename MatcherT, typename ValType>
-LIBC_INLINE bool match_and_explain(MatcherT matcher, const ValType &value,
-                                   const char *matcher_str,
-                                   const char *value_str, Location loc) {
-  MatchResultListener null_listener(nullptr);
-  if (matcher.MatchAndExplain(value, &null_listener))
-    return true;
-  mark_match_failure(value_str, matcher_str, loc);
-  MatchResultListener listener(&tlog);
-  matcher.MatchAndExplain(value, &listener);
-  return false;
-}
 } // namespace internal
 
 struct TestOptions {
@@ -239,6 +202,17 @@ class Test {
 
   static int runTests(const TestOptions &Options);
 
+  static bool testMatch(bool MatchResult, MatcherBase &Matcher,
+                        const char *LHSStr, const char *RHSStr,
+                        internal::Location Loc);
+
+  template <typename MatcherT, typename ValType>
+  static bool matchAndExplain(MatcherT &&Matcher, ValType Value,
+                              const char *MatcherStr, const char *ValueStr,
+                              internal::Location Loc) {
+    return testMatch(Matcher.match(Value), Matcher, ValueStr, MatcherStr, Loc);
+  }
+
   static bool testProcessExits(cpp::function_ref<void(void)> Func, int ExitCode,
                                const char *LHSStr, const char *RHSStr,
                                internal::Location Loc);
@@ -544,7 +518,7 @@ CString libc_make_test_file_path_func(const char *file_name);
 
 #define LIBC_TEST_MATCH_(MATCHER, MATCH, MATCHER_STR, MATCH_STR, RET_OR_EMPTY) \
   LIBC_TEST_SCAFFOLDING_(                                                      \
-      LIBC_NAMESPACE::testing::internal::match_and_explain(                    \
+      LIBC_NAMESPACE::testing::Test::matchAndExplain(                          \
           MATCHER, MATCH, MATCHER_STR, MATCH_STR, LIBC_TEST_LOC_()),           \
       RET_OR_EMPTY)
 

diff  --git a/libc/test/UnitTest/MemoryMatcher.cpp b/libc/test/UnitTest/MemoryMatcher.cpp
index f42dd99255f9ee..405f226798f7a5 100644
--- a/libc/test/UnitTest/MemoryMatcher.cpp
+++ b/libc/test/UnitTest/MemoryMatcher.cpp
@@ -14,6 +14,8 @@
 
 #if LIBC_TEST_HAS_MATCHERS()
 
+using LIBC_NAMESPACE::testing::tlog;
+
 namespace LIBC_NAMESPACE_DECL {
 namespace testing {
 
@@ -32,42 +34,49 @@ bool equals(const cpp::span<T> &Span1, const cpp::span<T> &Span2,
   return true;
 }
 
-static void display(MatchResultListener &listener, char C) {
-  const auto print = [&listener](unsigned char i) {
-    listener << LIBC_NAMESPACE::internal::toupper(
+bool MemoryMatcher::match(MemoryView actualValue) {
+  actual = actualValue;
+  return equals(expected, actual, mismatch_size, mismatch_index);
+}
+
+static void display(char C) {
+  const auto print = [](unsigned char i) {
+    tlog << LIBC_NAMESPACE::internal::toupper(
         LIBC_NAMESPACE::internal::int_to_b36_char(i));
   };
   print(static_cast<unsigned char>(C) / 16);
   print(static_cast<unsigned char>(C) & 15);
 }
 
-static void display(MatchResultListener &listener, MemoryView View) {
+static void display(MemoryView View) {
   for (auto C : View) {
-    listener << ' ';
-    display(listener, C);
+    tlog << ' ';
+    display(C);
   }
 }
 
-bool MemoryMatcher::MatchAndExplain(MemoryView actual,
-                                    MatchResultListener *listener) const {
-  bool mismatch_size = false;
-  size_t mismatch_index = cpp::numeric_limits<size_t>::max();
-  if (equals(expected, actual, mismatch_size, mismatch_index))
-    return true;
-  if (!listener->IsInterested())
-    return false;
+void MemoryMatcher::explainError() {
   if (mismatch_size) {
-    *listener << "Size mismatch :expected : " << expected.size() << '\n'
-              << "actual   : " << actual.size() << '\n';
+    tlog << "Size mismatch :";
+    tlog << "expected : ";
+    tlog << expected.size();
+    tlog << '\n';
+    tlog << "actual   : ";
+    tlog << actual.size();
+    tlog << '\n';
   } else {
-    *listener << "Mismatch at position : " << mismatch_index << " / "
-              << expected.size() << "\nexpected :";
-    display(*listener, expected);
-    *listener << "\nactual   :";
-    display(*listener, actual);
-    *listener << '\n';
+    tlog << "Mismatch at position : ";
+    tlog << mismatch_index;
+    tlog << " / ";
+    tlog << expected.size();
+    tlog << "\n";
+    tlog << "expected :";
+    display(expected);
+    tlog << '\n';
+    tlog << "actual   :";
+    display(actual);
+    tlog << '\n';
   }
-  return false;
 }
 
 } // namespace testing

diff  --git a/libc/test/UnitTest/MemoryMatcher.h b/libc/test/UnitTest/MemoryMatcher.h
index d39c9f952ed21c..cbbf3286c02acc 100644
--- a/libc/test/UnitTest/MemoryMatcher.h
+++ b/libc/test/UnitTest/MemoryMatcher.h
@@ -47,11 +47,16 @@ namespace testing {
 
 class MemoryMatcher : public Matcher<MemoryView> {
   MemoryView expected;
+  MemoryView actual;
+  bool mismatch_size = false;
+  size_t mismatch_index = cpp::numeric_limits<size_t>::max();
 
 public:
   MemoryMatcher(MemoryView expectedValue) : expected(expectedValue) {}
 
-  bool MatchAndExplain(MemoryView actual, MatchResultListener *listener) const;
+  bool match(MemoryView actualValue);
+
+  void explainError() override;
 };
 
 } // namespace testing

diff  --git a/libc/test/UnitTest/PrintfMatcher.cpp b/libc/test/UnitTest/PrintfMatcher.cpp
index 563f2dfc896460..2fe3482ea54383 100644
--- a/libc/test/UnitTest/PrintfMatcher.cpp
+++ b/libc/test/UnitTest/PrintfMatcher.cpp
@@ -30,20 +30,19 @@ namespace {
 #define IF_FLAG_SHOW_FLAG(flag_name)                                           \
   do {                                                                         \
     if ((form.flags & FormatFlags::flag_name) == FormatFlags::flag_name)       \
-      listener << "\n\t\t" << #flag_name;                                      \
+      tlog << "\n\t\t" << #flag_name;                                          \
   } while (false)
 #define CASE_LM(lm)                                                            \
   case (LengthModifier::lm):                                                   \
-    listener << #lm;                                                           \
+    tlog << #lm;                                                               \
     break
 #define CASE_LM_BIT_WIDTH(lm, bw)                                              \
   case (LengthModifier::lm):                                                   \
-    listener << #lm << "\n\tbit width: :" << bw;                               \
+    tlog << #lm << "\n\tbit width: :" << bw;                                   \
     break
 
-template <typename CharT>
-void display_impl(MatchResultListener &listener, FormatSection<CharT> form) {
-  listener << "Raw String (len " << form.raw_string.size() << "): \"";
+template <typename CharT> void display_impl(FormatSection<CharT> form) {
+  tlog << "Raw String (len " << form.raw_string.size() << "): \"";
   cpp::string raw_string_utf8;
   if constexpr (cpp::is_same_v<CharT, char>) {
     raw_string_utf8 = form.raw_string;
@@ -51,20 +50,20 @@ void display_impl(MatchResultListener &listener, FormatSection<CharT> form) {
     raw_string_utf8 = try_convert_to_utf8(form.raw_string);
   }
   for (size_t i = 0; i < raw_string_utf8.size(); ++i) {
-    listener << raw_string_utf8[i];
+    tlog << raw_string_utf8[i];
   }
-  listener << "\"";
+  tlog << "\"";
   if (form.has_conv) {
-    listener << "\n\tHas Conv\n\tFlags:";
+    tlog << "\n\tHas Conv\n\tFlags:";
     IF_FLAG_SHOW_FLAG(LEFT_JUSTIFIED);
     IF_FLAG_SHOW_FLAG(FORCE_SIGN);
     IF_FLAG_SHOW_FLAG(SPACE_PREFIX);
     IF_FLAG_SHOW_FLAG(ALTERNATE_FORM);
     IF_FLAG_SHOW_FLAG(LEADING_ZEROES);
-    listener << "\n";
-    listener << "\tmin width: " << form.min_width << "\n";
-    listener << "\tprecision: " << form.precision << "\n";
-    listener << "\tlength modifier: ";
+    tlog << "\n";
+    tlog << "\tmin width: " << form.min_width << "\n";
+    tlog << "\tprecision: " << form.precision << "\n";
+    tlog << "\tlength modifier: ";
     switch (form.length_modifier) {
       CASE_LM(none);
       CASE_LM(l);
@@ -91,28 +90,26 @@ void display_impl(MatchResultListener &listener, FormatSection<CharT> form) {
       conv_name_utf8 =
           try_convert_to_utf8(cpp::wstring_view(&form.conv_name, 1));
     }
-    listener << "\n";
-    listener << "\tconversion name: " << conv_name_utf8 << "\n";
+    tlog << "\n";
+    tlog << "\tconversion name: " << conv_name_utf8 << "\n";
     if (conv_name_utf8 == "p" || conv_name_utf8 == "n" || conv_name_utf8 == "s")
-      listener << "\tpointer value: "
-               << int_to_hex<uintptr_t>(
-                      reinterpret_cast<uintptr_t>(form.conv_val_ptr))
-               << "\n";
+      tlog << "\tpointer value: "
+           << int_to_hex<uintptr_t>(
+                  reinterpret_cast<uintptr_t>(form.conv_val_ptr))
+           << "\n";
     else if (conv_name_utf8 != "%")
-      listener << "\tvalue: " << int_to_hex(form.conv_val_raw) << "\n";
+      tlog << "\tvalue: " << int_to_hex(form.conv_val_raw) << "\n";
   }
 }
 
 } // anonymous namespace
 
-void display(MatchResultListener &listener,
-             const FormatSection<char> &format_section) {
-  display_impl(listener, format_section);
+void display(const FormatSection<char> &format_section) {
+  display_impl(format_section);
 }
 
-void display(MatchResultListener &listener,
-             const FormatSection<wchar_t> &format_section) {
-  display_impl(listener, format_section);
+void display(const FormatSection<wchar_t> &format_section) {
+  display_impl(format_section);
 }
 
 } // namespace testing

diff  --git a/libc/test/UnitTest/PrintfMatcher.h b/libc/test/UnitTest/PrintfMatcher.h
index b47d19d9d49688..656856e25b708f 100644
--- a/libc/test/UnitTest/PrintfMatcher.h
+++ b/libc/test/UnitTest/PrintfMatcher.h
@@ -16,31 +16,30 @@
 namespace LIBC_NAMESPACE_DECL {
 namespace testing {
 
-void display(MatchResultListener &listener,
-             const printf_core::FormatSection<char> &format_section);
-void display(MatchResultListener &listener,
-             const printf_core::FormatSection<wchar_t> &format_section);
+void display(const printf_core::FormatSection<char> &format_section);
+void display(const printf_core::FormatSection<wchar_t> &format_section);
 
 template <typename CharT>
 class FormatSectionMatcher : public Matcher<printf_core::FormatSection<CharT>> {
   printf_core::FormatSection<CharT> expected;
+  printf_core::FormatSection<CharT> actual;
 
 public:
   FormatSectionMatcher(printf_core::FormatSection<CharT> expectedValue)
       : expected(expectedValue) {}
 
-  bool MatchAndExplain(const printf_core::FormatSection<CharT> &actual,
-                       MatchResultListener *listener) const {
-    if (expected == actual)
-      return true;
-    if (!listener->IsInterested())
-      return false;
-    *listener << "expected format section: ";
-    display(*listener, expected);
-    *listener << "\nactual format section  : ";
-    display(*listener, actual);
-    *listener << '\n';
-    return false;
+  bool match(printf_core::FormatSection<CharT> actualValue) {
+    actual = actualValue;
+    return expected == actual;
+  }
+
+  void explainError() override {
+    tlog << "expected format section: ";
+    display(expected);
+    tlog << '\n';
+    tlog << "actual format section  : ";
+    display(actual);
+    tlog << '\n';
   }
 };
 

diff  --git a/libc/test/UnitTest/ScanfMatcher.cpp b/libc/test/UnitTest/ScanfMatcher.cpp
index 2853578352ecda..d47ad71a3b6f42 100644
--- a/libc/test/UnitTest/ScanfMatcher.cpp
+++ b/libc/test/UnitTest/ScanfMatcher.cpp
@@ -23,31 +23,36 @@ using scanf_core::FormatFlags;
 using scanf_core::FormatSection;
 using scanf_core::LengthModifier;
 
+bool FormatSectionMatcher::match(FormatSection actualValue) {
+  actual = actualValue;
+  return expected == actual;
+}
+
 namespace {
 
 #define IF_FLAG_SHOW_FLAG(flag_name)                                           \
   do {                                                                         \
     if ((form.flags & FormatFlags::flag_name) == FormatFlags::flag_name)       \
-      listener << "\n\t\t" << #flag_name;                                      \
+      tlog << "\n\t\t" << #flag_name;                                          \
   } while (false)
 #define CASE_LM(lm)                                                            \
   case (LengthModifier::lm):                                                   \
-    listener << #lm;                                                           \
+    tlog << #lm;                                                               \
     break
 
-void display(MatchResultListener &listener, const FormatSection &form) {
-  listener << "Raw String (len " << form.raw_string.size() << "): \"";
+void display(FormatSection form) {
+  tlog << "Raw String (len " << form.raw_string.size() << "): \"";
   for (size_t i = 0; i < form.raw_string.size(); ++i) {
-    listener << form.raw_string[i];
+    tlog << form.raw_string[i];
   }
-  listener << "\"";
+  tlog << "\"";
   if (form.has_conv) {
-    listener << "\n\tHas Conv\n\tFlags:";
+    tlog << "\n\tHas Conv\n\tFlags:";
     IF_FLAG_SHOW_FLAG(NO_WRITE);
     IF_FLAG_SHOW_FLAG(ALLOCATE);
-    listener << "\n";
-    listener << "\tmax width: " << form.max_width << "\n";
-    listener << "\tlength modifier: ";
+    tlog << "\n";
+    tlog << "\tmax width: " << form.max_width << "\n";
+    tlog << "\tlength modifier: ";
     switch (form.length_modifier) {
       CASE_LM(NONE);
       CASE_LM(l);
@@ -59,43 +64,38 @@ void display(MatchResultListener &listener, const FormatSection &form) {
       CASE_LM(t);
       CASE_LM(L);
     }
-    listener << "\n";
+    tlog << "\n";
     // If the pointer is used (NO_WRITE is not set and the conversion isn't %).
     if (((form.flags & FormatFlags::NO_WRITE) == 0) &&
         (form.conv_name != '%')) {
-      listener << "\tpointer value: "
-               << int_to_hex<uintptr_t>(
-                      reinterpret_cast<uintptr_t>(form.output_ptr))
-               << "\n";
+      tlog << "\tpointer value: "
+           << int_to_hex<uintptr_t>(
+                  reinterpret_cast<uintptr_t>(form.output_ptr))
+           << "\n";
     }
 
-    listener << "\tconversion name: " << form.conv_name << "\n";
+    tlog << "\tconversion name: " << form.conv_name << "\n";
 
     if (form.conv_name == '[') {
-      listener << "\t\t";
+      tlog << "\t\t";
       for (size_t i = 0; i < 256 /* char max */; ++i) {
         if (form.scan_set.test(i)) {
-          listener << static_cast<char>(i);
+          tlog << static_cast<char>(i);
         }
       }
-      listener << "\n\t]\n";
+      tlog << "\n\t]\n";
     }
   }
 }
 } // anonymous namespace
 
-bool FormatSectionMatcher::MatchAndExplain(
-    const FormatSection &actual, MatchResultListener *listener) const {
-  if (expected == actual)
-    return true;
-  if (!listener->IsInterested())
-    return false;
-  *listener << "expected format section: ";
-  display(*listener, expected);
-  *listener << "\nactual format section  : ";
-  display(*listener, actual);
-  *listener << '\n';
-  return false;
+void FormatSectionMatcher::explainError() {
+  tlog << "expected format section: ";
+  display(expected);
+  tlog << '\n';
+  tlog << "actual format section  : ";
+  display(actual);
+  tlog << '\n';
 }
 
 } // namespace testing

diff  --git a/libc/test/UnitTest/ScanfMatcher.h b/libc/test/UnitTest/ScanfMatcher.h
index 9158f2e096d966..cb9d13f7572b75 100644
--- a/libc/test/UnitTest/ScanfMatcher.h
+++ b/libc/test/UnitTest/ScanfMatcher.h
@@ -18,13 +18,15 @@ namespace testing {
 
 class FormatSectionMatcher : public Matcher<scanf_core::FormatSection> {
   scanf_core::FormatSection expected;
+  scanf_core::FormatSection actual;
 
 public:
   FormatSectionMatcher(scanf_core::FormatSection expectedValue)
       : expected(expectedValue) {}
 
-  bool MatchAndExplain(const scanf_core::FormatSection &actual,
-                       MatchResultListener *listener) const;
+  bool match(scanf_core::FormatSection actualValue);
+
+  void explainError() override;
 };
 
 } // namespace testing

diff  --git a/libc/test/include/sys/queue_test.cpp b/libc/test/include/sys/queue_test.cpp
index 2b7f026c77c7cc..ce3ae8e8f9810f 100644
--- a/libc/test/include/sys/queue_test.cpp
+++ b/libc/test/include/sys/queue_test.cpp
@@ -7,7 +7,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "src/__support/CPP/string.h"
-#include "src/__support/CPP/string_view.h"
 #include "src/__support/char_vector.h"
 #include "src/__support/macros/config.h"
 #include "test/UnitTest/Test.h"
@@ -32,16 +31,11 @@ TEST(LlvmLibcQueueTest, SList) {
   struct Contains : public testing::Matcher<Head> {
     string s;
     Contains(string s) : s(s) {}
-    bool MatchAndExplain(Head head,
-                         testing::MatchResultListener *listener) const {
+    bool match(Head head) {
       Entry *e;
       CharVector v;
       SLIST_FOREACH(e, &head, entries) { v.append(e->c); }
-      if (s == v.c_str())
-        return true;
-      *listener << "expected elements: " << s << "\nactual elements: "
-                << cpp::string_view(v.c_str(), v.length()) << '\n';
-      return false;
+      return s == v.c_str();
     }
   };
 
@@ -104,16 +98,11 @@ TEST(LlvmLibcQueueTest, STailQ) {
   struct Contains : public testing::Matcher<Head> {
     string s;
     Contains(string s) : s(s) {}
-    bool MatchAndExplain(Head head,
-                         testing::MatchResultListener *listener) const {
+    bool match(Head head) {
       Entry *e;
       CharVector v;
       STAILQ_FOREACH(e, &head, entries) { v.append(e->c); }
-      if (s == v.c_str())
-        return true;
-      *listener << "expected elements: " << s << "\nactual elements: "
-                << cpp::string_view(v.c_str(), v.length()) << '\n';
-      return false;
+      return s == v.c_str();
     }
   };
 

diff  --git a/libc/test/src/sys/socket/linux/socket_test_support.h b/libc/test/src/sys/socket/linux/socket_test_support.h
index dad46aad8ad2f1..ac092f454f05e8 100644
--- a/libc/test/src/sys/socket/linux/socket_test_support.h
+++ b/libc/test/src/sys/socket/linux/socket_test_support.h
@@ -80,6 +80,8 @@ struct SocketAddress {
 
 class SocketAddressMatcher : public Matcher<SocketAddress> {
   cpp::string_view expected_path;
+  struct sockaddr_un actual_addr;
+  socklen_t actual_addrlen;
 
   static constexpr size_t SUN_PATH_OFFSET =
       offsetof(struct sockaddr_un, sun_path);
@@ -87,39 +89,55 @@ class SocketAddressMatcher : public Matcher<SocketAddress> {
 public:
   explicit SocketAddressMatcher(cpp::string_view path) : expected_path(path) {}
 
-  bool MatchAndExplain(const SocketAddress &actual,
-                       MatchResultListener *listener) const {
-    if (actual.addr.sun_family != AF_UNIX) {
-      *listener << "Expected address family to be AF_UNIX but got "
-                << actual.addr.sun_family << "\n";
+  bool match(const SocketAddress &actual) {
+    actual_addr = actual.addr;
+    actual_addrlen = actual.addrlen;
+    if (actual_addr.sun_family != AF_UNIX)
       return false;
-    }
-    if (actual.addrlen > sizeof(actual.addr)) {
-      *listener << "Expected address length to be less than or equal to "
-                << sizeof(actual.addr) << " but got " << actual.addrlen << "\n";
+    if (actual_addrlen > sizeof(actual_addr))
       return false;
-    }
     size_t expected_path_len = expected_path.size();
-    if (expected_path_len + 1 + SUN_PATH_OFFSET > actual.addrlen) {
-      *listener << "Expected address length to be less than or equal to "
-                << expected_path_len + 1 + SUN_PATH_OFFSET << " but got "
-                << actual.addrlen << "\n";
+    if (expected_path_len + 1 + SUN_PATH_OFFSET > actual_addrlen)
       return false;
-    }
-    if (actual.addrlen < SUN_PATH_OFFSET) {
-      *listener << "Expected address length to be greater than or equal to "
-                << SUN_PATH_OFFSET << " but got " << actual.addrlen << "\n";
+    if (actual_addrlen < SUN_PATH_OFFSET)
       return false;
+    cpp::string_view actual_path(
+        actual_addr.sun_path,
+        strnlen(actual_addr.sun_path, actual_addrlen - SUN_PATH_OFFSET));
+    return actual_path == expected_path;
+  }
+
+  void explainError() override {
+    if (actual_addr.sun_family != AF_UNIX) {
+      tlog << "Expected address family to be AF_UNIX but got "
+           << actual_addr.sun_family << "\n";
+      return;
+    }
+    if (actual_addrlen > sizeof(actual_addr)) {
+      tlog << "Expected address length to be less than or equal to "
+           << sizeof(actual_addr) << " but got " << actual_addrlen << "\n";
+      return;
+    }
+    size_t expected_path_len = expected_path.size();
+    if (expected_path_len + 1 + SUN_PATH_OFFSET > actual_addrlen) {
+      tlog << "Expected address length to be less than or equal to "
+           << expected_path_len + 1 + SUN_PATH_OFFSET << " but got "
+           << actual_addrlen << "\n";
+      return;
+    }
+    if (actual_addrlen < SUN_PATH_OFFSET) {
+      tlog << "Expected address length to be greater than or equal to "
+           << SUN_PATH_OFFSET << " but got " << actual_addrlen << "\n";
+      return;
     }
     cpp::string_view actual_path(
-        actual.addr.sun_path,
-        strnlen(actual.addr.sun_path, actual.addrlen - SUN_PATH_OFFSET));
+        actual_addr.sun_path,
+        strnlen(actual_addr.sun_path, actual_addrlen - SUN_PATH_OFFSET));
     if (actual_path != expected_path) {
-      *listener << "Expected address path to be " << expected_path
-                << " but got " << actual_path << "\n";
-      return false;
+      tlog << "Expected address path to be " << expected_path << " but got "
+           << actual_path << "\n";
+      return;
     }
-    return true;
   }
 };
 

diff  --git a/libc/test/src/time/TmMatcher.h b/libc/test/src/time/TmMatcher.h
index 839c13dca99edd..5715a3c1203acc 100644
--- a/libc/test/src/time/TmMatcher.h
+++ b/libc/test/src/time/TmMatcher.h
@@ -18,35 +18,41 @@ namespace testing {
 
 class StructTmMatcher : public Matcher<::tm> {
   ::tm expected;
-
-  static void describeValue(MatchResultListener &listener, const char *label,
-                            const ::tm &value) {
-    listener << label << " sec: " << value.tm_sec << " min: " << value.tm_min
-             << " hour: " << value.tm_hour << " mday: " << value.tm_mday
-             << " mon: " << value.tm_mon << " year: " << value.tm_year
-             << " wday: " << value.tm_wday << " yday: " << value.tm_yday
-             << " isdst: " << value.tm_isdst << '\n';
-  }
+  ::tm actual;
 
 public:
   StructTmMatcher(::tm expectedValue) : expected(expectedValue) {}
 
-  bool MatchAndExplain(const ::tm &actual,
-                       MatchResultListener *listener) const {
-    if (actual.tm_sec == expected.tm_sec && actual.tm_min == expected.tm_min &&
-        actual.tm_hour == expected.tm_hour &&
-        actual.tm_mday == expected.tm_mday &&
-        actual.tm_mon == expected.tm_mon &&
-        actual.tm_year == expected.tm_year &&
-        actual.tm_wday == expected.tm_wday &&
-        actual.tm_yday == expected.tm_yday &&
-        actual.tm_isdst == expected.tm_isdst)
-      return true;
-    if (!listener->IsInterested())
-      return false;
-    describeValue(*listener, "Expected tm_struct value: ", expected);
-    describeValue(*listener, "  Actual tm_struct value: ", actual);
-    return false;
+  bool match(::tm actualValue) {
+    actual = actualValue;
+    return (actual.tm_sec == expected.tm_sec &&
+            actual.tm_min == expected.tm_min &&
+            actual.tm_hour == expected.tm_hour &&
+            actual.tm_mday == expected.tm_mday &&
+            actual.tm_mon == expected.tm_mon &&
+            actual.tm_year == expected.tm_year &&
+            actual.tm_wday == expected.tm_wday &&
+            actual.tm_yday == expected.tm_yday &&
+            actual.tm_isdst == expected.tm_isdst);
+  }
+
+  void describeValue(const char *label, ::tm value) {
+    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 {
+    describeValue("Expected tm_struct value: ", expected);
+    describeValue("  Actual tm_struct value: ", actual);
   }
 };
 

diff  --git a/libc/utils/MPCWrapper/MPCUtils.cpp b/libc/utils/MPCWrapper/MPCUtils.cpp
index 0e51f66f402e22..20e2637912ee04 100644
--- a/libc/utils/MPCWrapper/MPCUtils.cpp
+++ b/libc/utils/MPCWrapper/MPCUtils.cpp
@@ -235,7 +235,7 @@ template bool compare_unary_operation_single_output_
diff erent_type(
 template <typename InputType, typename OutputType>
 void explain_unary_operation_single_output_
diff erent_type_error(
     Operation op, InputType input, OutputType libc_result, double ulp_tolerance,
-    RoundingMode rounding, MatchResultListener *listener) {
+    RoundingMode rounding) {
 
   unsigned int precision =
       mpfr::get_precision<make_real_t<InputType>>(ulp_tolerance);
@@ -271,22 +271,20 @@ void explain_unary_operation_single_output_
diff erent_type_error(
       << '\n'
       << "  ULP error: " << mpfr_result.ulp_as_mpfr_number(libc_result).str()
       << '\n';
-  *listener << msg.str();
+  tlog << msg.str();
   mpc_clear(mpc_result_val);
   mpfr_clear(real);
 }
 
 template void explain_unary_operation_single_output_
diff erent_type_error(
-    Operation, _Complex float, float, double, RoundingMode,
-    MatchResultListener *);
+    Operation, _Complex float, float, double, RoundingMode);
 template void explain_unary_operation_single_output_
diff erent_type_error(
-    Operation, _Complex double, double, double, RoundingMode,
-    MatchResultListener *);
+    Operation, _Complex double, double, double, RoundingMode);
 
 template <typename InputType, typename OutputType>
 void explain_unary_operation_single_output_same_type_error(
     Operation op, InputType input, OutputType libc_result, double ulp_tolerance,
-    RoundingMode rounding, MatchResultListener *listener) {
+    RoundingMode rounding) {
 
   unsigned int precision =
       mpfr::get_precision<make_real_t<InputType>>(ulp_tolerance);
@@ -342,18 +340,16 @@ void explain_unary_operation_single_output_same_type_error(
                      .imag)
              .str()
       << '\n';
-  *listener << msg.str();
+  tlog << msg.str();
   mpc_clear(mpc_result_val);
   mpfr_clear(real);
   mpfr_clear(imag);
 }
 
 template void explain_unary_operation_single_output_same_type_error(
-    Operation, _Complex float, _Complex float, double, RoundingMode,
-    MatchResultListener *);
+    Operation, _Complex float, _Complex float, double, RoundingMode);
 template void explain_unary_operation_single_output_same_type_error(
-    Operation, _Complex double, _Complex double, double, RoundingMode,
-    MatchResultListener *);
+    Operation, _Complex double, _Complex double, double, RoundingMode);
 
 } // namespace internal
 

diff  --git a/libc/utils/MPCWrapper/MPCUtils.h b/libc/utils/MPCWrapper/MPCUtils.h
index 50e6c9c15d468c..d4ab672bcddbe8 100644
--- a/libc/utils/MPCWrapper/MPCUtils.h
+++ b/libc/utils/MPCWrapper/MPCUtils.h
@@ -96,22 +96,23 @@ bool compare_binary_operation_one_output(Operation op,
 template <typename InputType, typename OutputType>
 void explain_unary_operation_single_output_same_type_error(
     Operation op, InputType input, OutputType match_value, double ulp_tolerance,
-    RoundingMode rounding, MatchResultListener *listener);
+    RoundingMode rounding);
 
 template <typename InputType, typename OutputType>
 void explain_unary_operation_single_output_
diff erent_type_error(
     Operation op, InputType input, OutputType match_value, double ulp_tolerance,
-    RoundingMode rounding, MatchResultListener *listener);
+    RoundingMode rounding);
 
 template <typename InputType, typename OutputType>
 void explain_binary_operation_one_output_error(
     Operation op, const BinaryInput<InputType> &input, OutputType match_value,
-    double ulp_tolerance, RoundingMode rounding, MatchResultListener *listener);
+    double ulp_tolerance, RoundingMode rounding);
 
 template <Operation op, typename InputType, typename OutputType>
 class MPCMatcher : public testing::Matcher<OutputType> {
 private:
   InputType input;
+  OutputType match_value;
   double ulp_tolerance;
   RoundingMode rounding;
 
@@ -119,20 +120,18 @@ class MPCMatcher : public testing::Matcher<OutputType> {
   MPCMatcher(InputType testInput, double ulp_tolerance, RoundingMode rounding)
       : input(testInput), ulp_tolerance(ulp_tolerance), rounding(rounding) {}
 
-  bool match(OutputType libcResult) const { return match(input, libcResult); }
+  bool match(OutputType libcResult) {
+    match_value = libcResult;
+    return match(input, match_value);
+  }
 
-  bool MatchAndExplain(OutputType libcResult,
-                       MatchResultListener *listener) const {
-    if (match(libcResult))
-      return true;
-    if (listener->IsInterested())
-      explain_error(input, libcResult, listener);
-    return false;
+  void explainError() override { // NOLINT
+    explain_error(input, match_value);
   }
 
 private:
   template <typename InType, typename OutType>
-  bool match(InType in, OutType out) const {
+  bool match(InType in, OutType out) {
     if (cpp::is_same_v<InType, OutType>) {
       return compare_unary_operation_single_output_same_type(
           op, in, out, ulp_tolerance, rounding);
@@ -143,28 +142,26 @@ class MPCMatcher : public testing::Matcher<OutputType> {
   }
 
   template <typename T, typename U>
-  bool match(const BinaryInput<T> &in, U out) const {
+  bool match(const BinaryInput<T> &in, U out) {
     return compare_binary_operation_one_output(op, in, out, ulp_tolerance,
                                                rounding);
   }
 
   template <typename InType, typename OutType>
-  void explain_error(InType in, OutType out,
-                     MatchResultListener *listener) const {
+  void explain_error(InType in, OutType out) {
     if (cpp::is_same_v<InType, OutType>) {
       explain_unary_operation_single_output_same_type_error(
-          op, in, out, ulp_tolerance, rounding, listener);
+          op, in, out, ulp_tolerance, rounding);
     } else {
       explain_unary_operation_single_output_
diff erent_type_error(
-          op, in, out, ulp_tolerance, rounding, listener);
+          op, in, out, ulp_tolerance, rounding);
     }
   }
 
   template <typename T, typename U>
-  void explain_error(const BinaryInput<T> &in, U out,
-                     MatchResultListener *listener) const {
+  void explain_error(const BinaryInput<T> &in, U out) {
     explain_binary_operation_one_output_error(op, in, out, ulp_tolerance,
-                                              rounding, listener);
+                                              rounding);
   }
 };
 

diff  --git a/libc/utils/MPFRWrapper/MPFRUtils.cpp b/libc/utils/MPFRWrapper/MPFRUtils.cpp
index 5432c6504b8d68..fea8c5512977dc 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.cpp
+++ b/libc/utils/MPFRWrapper/MPFRUtils.cpp
@@ -202,9 +202,10 @@ ternary_operation_one_output(Operation op, InputType x, InputType y,
 // once at the end.  This will stop the error messages from interleaving when
 // the tests are running concurrently.
 template <typename InputType, typename OutputType>
-void explain_unary_operation_single_output_error(
-    Operation op, InputType input, OutputType matchValue, double ulp_tolerance,
-    RoundingMode rounding, MatchResultListener *listener) {
+void explain_unary_operation_single_output_error(Operation op, InputType input,
+                                                 OutputType matchValue,
+                                                 double ulp_tolerance,
+                                                 RoundingMode rounding) {
   unsigned int precision = get_precision<InputType>(ulp_tolerance);
   MPFRNumber mpfrInput(input, precision);
   MPFRNumber mpfr_result;
@@ -225,76 +226,72 @@ void explain_unary_operation_single_output_error(
       << '\n';
   if (msg.overflow())
     __builtin_unreachable();
-  *listener << msg.str();
+  tlog << msg.str();
 }
 
-template void explain_unary_operation_single_output_error(
-    Operation op, float, float, double, RoundingMode, MatchResultListener *);
-template void explain_unary_operation_single_output_error(
-    Operation op, double, double, double, RoundingMode, MatchResultListener *);
-template void
-explain_unary_operation_single_output_error(Operation op, long double,
-                                            long double, double, RoundingMode,
-                                            MatchResultListener *);
-template void explain_unary_operation_single_output_error(
-    Operation op, double, float, double, RoundingMode, MatchResultListener *);
-template void
-explain_unary_operation_single_output_error(Operation op, long double, float,
-                                            double, RoundingMode,
-                                            MatchResultListener *);
-template void
-explain_unary_operation_single_output_error(Operation op, long double, double,
-                                            double, RoundingMode,
-                                            MatchResultListener *);
+template void explain_unary_operation_single_output_error(Operation op, float,
+                                                          float, double,
+                                                          RoundingMode);
+template void explain_unary_operation_single_output_error(Operation op, double,
+                                                          double, double,
+                                                          RoundingMode);
+template void explain_unary_operation_single_output_error(Operation op,
+                                                          long double,
+                                                          long double, double,
+                                                          RoundingMode);
+template void explain_unary_operation_single_output_error(Operation op, double,
+                                                          float, double,
+                                                          RoundingMode);
+template void explain_unary_operation_single_output_error(Operation op,
+                                                          long double, float,
+                                                          double, RoundingMode);
+template void explain_unary_operation_single_output_error(Operation op,
+                                                          long double, double,
+                                                          double, RoundingMode);
 
 #ifdef LIBC_TYPES_HAS_FLOAT16
-template void
-explain_unary_operation_single_output_error(Operation op, float16, float16,
-                                            double, RoundingMode,
-                                            MatchResultListener *);
-template void explain_unary_operation_single_output_error(
-    Operation op, float, float16, double, RoundingMode, MatchResultListener *);
-template void explain_unary_operation_single_output_error(
-    Operation op, double, float16, double, RoundingMode, MatchResultListener *);
-template void
-explain_unary_operation_single_output_error(Operation op, long double, float16,
-                                            double, RoundingMode,
-                                            MatchResultListener *);
+template void explain_unary_operation_single_output_error(Operation op, float16,
+                                                          float16, double,
+                                                          RoundingMode);
+template void explain_unary_operation_single_output_error(Operation op, float,
+                                                          float16, double,
+                                                          RoundingMode);
+template void explain_unary_operation_single_output_error(Operation op, double,
+                                                          float16, double,
+                                                          RoundingMode);
+template void explain_unary_operation_single_output_error(Operation op,
+                                                          long double, float16,
+                                                          double, RoundingMode);
 #ifdef LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
-template void
-explain_unary_operation_single_output_error(Operation op, float128, float16,
-                                            double, RoundingMode,
-                                            MatchResultListener *);
+template void explain_unary_operation_single_output_error(Operation op,
+                                                          float128, float16,
+                                                          double, RoundingMode);
 #endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
 #endif // LIBC_TYPES_HAS_FLOAT16
 
 #ifdef LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
-template void
-explain_unary_operation_single_output_error(Operation op, float128, float128,
-                                            double, RoundingMode,
-                                            MatchResultListener *);
-template void explain_unary_operation_single_output_error(
-    Operation op, float128, float, double, RoundingMode, MatchResultListener *);
-template void
-explain_unary_operation_single_output_error(Operation op, float128, double,
-                                            double, RoundingMode,
-                                            MatchResultListener *);
-template void
-explain_unary_operation_single_output_error(Operation op, float128, long double,
-                                            double, RoundingMode,
-                                            MatchResultListener *);
+template void explain_unary_operation_single_output_error(Operation op,
+                                                          float128, float128,
+                                                          double, RoundingMode);
+template void explain_unary_operation_single_output_error(Operation op,
+                                                          float128, float,
+                                                          double, RoundingMode);
+template void explain_unary_operation_single_output_error(Operation op,
+                                                          float128, double,
+                                                          double, RoundingMode);
+template void explain_unary_operation_single_output_error(Operation op,
+                                                          float128, long double,
+                                                          double, RoundingMode);
 #endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
 
-template void
-explain_unary_operation_single_output_error(Operation op, bfloat16, bfloat16,
-                                            double, RoundingMode,
-                                            MatchResultListener *);
+template void explain_unary_operation_single_output_error(Operation op,
+                                                          bfloat16, bfloat16,
+                                                          double, RoundingMode);
 
 template <typename T>
 void explain_unary_operation_two_outputs_error(
     Operation op, T input, const BinaryOutput<T> &libc_result,
-    double ulp_tolerance, RoundingMode rounding,
-    MatchResultListener *listener) {
+    double ulp_tolerance, RoundingMode rounding) {
   unsigned int precision = get_precision<T>(ulp_tolerance);
   MPFRNumber mpfrInput(input, precision);
   int mpfrIntResult;
@@ -302,61 +299,55 @@ void explain_unary_operation_two_outputs_error(
                                                        precision, rounding);
 
   if (mpfrIntResult != libc_result.i) {
-    *listener << "MPFR integral result: " << mpfrIntResult << '\n'
-              << "Libc integral result: " << libc_result.i << '\n';
+    tlog << "MPFR integral result: " << mpfrIntResult << '\n'
+         << "Libc integral result: " << libc_result.i << '\n';
   } else {
-    *listener
-        << "Integral result from libc matches integral result from MPFR.\n";
+    tlog << "Integral result from libc matches integral result from MPFR.\n";
   }
 
   MPFRNumber mpfrMatchValue(libc_result.f);
-  *listener
+  tlog
       << "Libc floating point result is not within tolerance value of the MPFR "
       << "result.\n\n";
 
-  *listener << "            Input decimal: " << mpfrInput.str() << "\n\n";
+  tlog << "            Input decimal: " << mpfrInput.str() << "\n\n";
 
-  *listener << "Libc floating point value: " << mpfrMatchValue.str() << '\n';
-  *listener << " Libc floating point bits: " << str(FPBits<T>(libc_result.f))
-            << '\n';
-  *listener << "\n\n";
+  tlog << "Libc floating point value: " << mpfrMatchValue.str() << '\n';
+  tlog << " Libc floating point bits: " << str(FPBits<T>(libc_result.f))
+       << '\n';
+  tlog << "\n\n";
 
-  *listener << "              MPFR result: " << mpfr_result.str() << '\n';
-  *listener << "             MPFR rounded: "
-            << str(FPBits<T>(mpfr_result.as<T>())) << '\n';
-  *listener << '\n'
-            << "                ULP error: "
-            << mpfr_result.ulp_as_mpfr_number(libc_result.f).str() << '\n';
+  tlog << "              MPFR result: " << mpfr_result.str() << '\n';
+  tlog << "             MPFR rounded: " << str(FPBits<T>(mpfr_result.as<T>()))
+       << '\n';
+  tlog << '\n'
+       << "                ULP error: "
+       << mpfr_result.ulp_as_mpfr_number(libc_result.f).str() << '\n';
 }
 
 template void explain_unary_operation_two_outputs_error<float>(
-    Operation, float, const BinaryOutput<float> &, double, RoundingMode,
-    MatchResultListener *);
+    Operation, float, const BinaryOutput<float> &, double, RoundingMode);
 template void explain_unary_operation_two_outputs_error<double>(
-    Operation, double, const BinaryOutput<double> &, double, RoundingMode,
-    MatchResultListener *);
+    Operation, double, const BinaryOutput<double> &, double, RoundingMode);
 template void explain_unary_operation_two_outputs_error<long double>(
     Operation, long double, const BinaryOutput<long double> &, double,
-    RoundingMode, MatchResultListener *);
+    RoundingMode);
 #ifdef LIBC_TYPES_HAS_FLOAT16
 template void explain_unary_operation_two_outputs_error<float16>(
-    Operation, float16, const BinaryOutput<float16> &, double, RoundingMode,
-    MatchResultListener *);
+    Operation, float16, const BinaryOutput<float16> &, double, RoundingMode);
 #endif
 template void explain_unary_operation_two_outputs_error<bfloat16>(
-    Operation, bfloat16, const BinaryOutput<bfloat16> &, double, RoundingMode,
-    MatchResultListener *);
+    Operation, bfloat16, const BinaryOutput<bfloat16> &, double, RoundingMode);
 #ifdef LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
 template void explain_unary_operation_two_outputs_error<float128>(
-    Operation, float128, const BinaryOutput<float128> &, double, RoundingMode,
-    MatchResultListener *);
+    Operation, float128, const BinaryOutput<float128> &, double, RoundingMode);
 #endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
 
 template <typename T>
 void explain_binary_operation_two_outputs_error(
     Operation op, const BinaryInput<T> &input,
     const BinaryOutput<T> &libc_result, double ulp_tolerance,
-    RoundingMode rounding, MatchResultListener *listener) {
+    RoundingMode rounding) {
   unsigned int precision = get_precision<T>(ulp_tolerance);
   MPFRNumber mpfrX(input.x, precision);
   MPFRNumber mpfrY(input.y, precision);
@@ -365,49 +356,46 @@ void explain_binary_operation_two_outputs_error(
       op, input.x, input.y, mpfrIntResult, precision, rounding);
   MPFRNumber mpfrMatchValue(libc_result.f);
 
-  *listener << "Input decimal: x: " << mpfrX.str() << " y: " << mpfrY.str()
-            << '\n'
-            << "MPFR integral result: " << mpfrIntResult << '\n'
-            << "Libc integral result: " << libc_result.i << '\n'
-            << "Libc floating point result: " << mpfrMatchValue.str() << '\n'
-            << "               MPFR result: " << mpfr_result.str() << '\n';
-  *listener << "Libc floating point result bits: "
-            << str(FPBits<T>(libc_result.f)) << '\n';
-  *listener << "              MPFR rounded bits: "
-            << str(FPBits<T>(mpfr_result.as<T>())) << '\n';
-  *listener << "ULP error: "
-            << mpfr_result.ulp_as_mpfr_number(libc_result.f).str() << '\n';
+  tlog << "Input decimal: x: " << mpfrX.str() << " y: " << mpfrY.str() << '\n'
+       << "MPFR integral result: " << mpfrIntResult << '\n'
+       << "Libc integral result: " << libc_result.i << '\n'
+       << "Libc floating point result: " << mpfrMatchValue.str() << '\n'
+       << "               MPFR result: " << mpfr_result.str() << '\n';
+  tlog << "Libc floating point result bits: " << str(FPBits<T>(libc_result.f))
+       << '\n';
+  tlog << "              MPFR rounded bits: "
+       << str(FPBits<T>(mpfr_result.as<T>())) << '\n';
+  tlog << "ULP error: " << mpfr_result.ulp_as_mpfr_number(libc_result.f).str()
+       << '\n';
 }
 
 template void explain_binary_operation_two_outputs_error<float>(
     Operation, const BinaryInput<float> &, const BinaryOutput<float> &, double,
-    RoundingMode, MatchResultListener *);
+    RoundingMode);
 template void explain_binary_operation_two_outputs_error<double>(
     Operation, const BinaryInput<double> &, const BinaryOutput<double> &,
-    double, RoundingMode, MatchResultListener *);
+    double, RoundingMode);
 template void explain_binary_operation_two_outputs_error<long double>(
     Operation, const BinaryInput<long double> &,
-    const BinaryOutput<long double> &, double, RoundingMode,
-    MatchResultListener *);
+    const BinaryOutput<long double> &, double, RoundingMode);
 #ifdef LIBC_TYPES_HAS_FLOAT16
 template void explain_binary_operation_two_outputs_error<float16>(
     Operation, const BinaryInput<float16> &, const BinaryOutput<float16> &,
-    double, RoundingMode, MatchResultListener *);
+    double, RoundingMode);
 #endif
 template void explain_binary_operation_two_outputs_error<bfloat16>(
     Operation, const BinaryInput<bfloat16> &, const BinaryOutput<bfloat16> &,
-    double, RoundingMode, MatchResultListener *);
+    double, RoundingMode);
 #ifdef LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
 template void explain_binary_operation_two_outputs_error<float128>(
     Operation, const BinaryInput<float128> &, const BinaryOutput<float128> &,
-    double, RoundingMode, MatchResultListener *);
+    double, RoundingMode);
 #endif // LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE
 
 template <typename InputType, typename OutputType>
 void explain_binary_operation_one_output_error(
     Operation op, const BinaryInput<InputType> &input, OutputType libc_result,
-    double ulp_tolerance, RoundingMode rounding,
-    MatchResultListener *listener) {
+    double ulp_tolerance, RoundingMode rounding) {
   unsigned int precision = get_precision<InputType>(ulp_tolerance);
   MPFRNumber mpfrX(input.x, precision);
   MPFRNumber mpfrY(input.y, precision);
@@ -417,87 +405,73 @@ void explain_binary_operation_one_output_error(
       binary_operation_one_output(op, input.x, input.y, precision, rounding);
   MPFRNumber mpfrMatchValue(libc_result);
 
-  *listener << "Input decimal: x: " << mpfrX.str() << " y: " << mpfrY.str()
-            << '\n';
-  *listener << "First input bits: " << str(FPBits<InputType>(input.x)) << '\n';
-  *listener << "Second input bits: " << str(FPBits<InputType>(input.y)) << '\n';
-
-  *listener << "Libc result: " << mpfrMatchValue.str() << '\n'
-            << "MPFR result: " << mpfr_result.str() << '\n';
-  *listener << "Libc floating point result bits: "
-            << str(FPBits<OutputType>(libc_result)) << '\n';
-  *listener << "              MPFR rounded bits: "
-            << str(FPBits<OutputType>(mpfr_result.as<OutputType>())) << '\n';
-  *listener << "ULP error: "
-            << mpfr_result.ulp_as_mpfr_number(libc_result).str() << '\n';
+  tlog << "Input decimal: x: " << mpfrX.str() << " y: " << mpfrY.str() << '\n';
+  tlog << "First input bits: " << str(FPBits<InputType>(input.x)) << '\n';
+  tlog << "Second input bits: " << str(FPBits<InputType>(input.y)) << '\n';
+
+  tlog << "Libc result: " << mpfrMatchValue.str() << '\n'
+       << "MPFR result: " << mpfr_result.str() << '\n';
+  tlog << "Libc floating point result bits: "
+       << str(FPBits<OutputType>(libc_result)) << '\n';
+  tlog << "              MPFR rounded bits: "
+       << str(FPBits<OutputType>(mpfr_result.as<OutputType>())) << '\n';
+  tlog << "ULP error: " << mpfr_result.ulp_as_mpfr_number(libc_result).str()
+       << '\n';
 }
 
 template void
 explain_binary_operation_one_output_error(Operation, const BinaryInput<float> &,
-                                          float, double, RoundingMode,
-                                          MatchResultListener *);
+                                          float, double, RoundingMode);
 template void explain_binary_operation_one_output_error(
-    Operation, const BinaryInput<double> &, float, double, RoundingMode,
-    MatchResultListener *);
+    Operation, const BinaryInput<double> &, float, double, RoundingMode);
 template void explain_binary_operation_one_output_error(
-    Operation, const BinaryInput<double> &, double, double, RoundingMode,
-    MatchResultListener *);
+    Operation, const BinaryInput<double> &, double, double, RoundingMode);
 template void explain_binary_operation_one_output_error(
-    Operation, const BinaryInput<long double> &, float, double, RoundingMode,
-    MatchResultListener *);
+    Operation, const BinaryInput<long double> &, float, double, RoundingMode);
 template void explain_binary_operation_one_output_error(
-    Operation, const BinaryInput<long double> &, double, double, RoundingMode,
-    MatchResultListener *);
-template void explain_binary_operation_one_output_error(
-    Operation, const BinaryInput<long double> &, long double, double,
-    RoundingMode, MatchResultListener *);
+    Operation, const BinaryInput<long double> &, double, double, RoundingMode);
+template void
+explain_binary_operation_one_output_error(Operation,
+                                          const BinaryInput<long double> &,
+                                          long double, double, RoundingMode);
 #ifdef LIBC_TYPES_HAS_FLOAT16
 template void explain_binary_operation_one_output_error(
-    Operation, const BinaryInput<float16> &, float16, double, RoundingMode,
-    MatchResultListener *);
+    Operation, const BinaryInput<float16> &, float16, double, RoundingMode);
 template void
 explain_binary_operation_one_output_error(Operation, const BinaryInput<float> &,
-                                          float16, double, RoundingMode,
-                                          MatchResultListener *);
+                                          float16, double, RoundingMode);
 template void explain_binary_operation_one_output_error(
-    Operation, const BinaryInput<double> &, float16, double, RoundingMode,
-    MatchResultListener *);
+    Operation, const BinaryInput<double> &, float16, double, RoundingMode);
 template void explain_binary_operation_one_output_error(
-    Operation, const BinaryInput<long double> &, float16, double, RoundingMode,
-    MatchResultListener *);
+    Operation, const BinaryInput<long double> &, float16, double, RoundingMode);
 #endif
 #if defined(LIBC_TYPES_HAS_NATIVE_FLOAT128) &&                                 \
     defined(LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE)
 template void explain_binary_operation_one_output_error(
-    Operation, const BinaryInput<float128> &, float128, double, RoundingMode,
-    MatchResultListener *);
+    Operation, const BinaryInput<float128> &, float128, double, RoundingMode);
 #endif
 template void explain_binary_operation_one_output_error(
-    Operation, const BinaryInput<bfloat16> &, bfloat16, double, RoundingMode,
-    MatchResultListener *);
+    Operation, const BinaryInput<bfloat16> &, bfloat16, double, RoundingMode);
 template void
 explain_binary_operation_one_output_error(Operation, const BinaryInput<float> &,
-                                          bfloat16, double, RoundingMode,
-                                          MatchResultListener *);
+                                          bfloat16, double, RoundingMode);
 template void explain_binary_operation_one_output_error(
-    Operation, const BinaryInput<double> &, bfloat16, double, RoundingMode,
-    MatchResultListener *);
-template void explain_binary_operation_one_output_error(
-    Operation, const BinaryInput<long double> &, bfloat16, double, RoundingMode,
-    MatchResultListener *);
+    Operation, const BinaryInput<double> &, bfloat16, double, RoundingMode);
+template void
+explain_binary_operation_one_output_error(Operation,
+                                          const BinaryInput<long double> &,
+                                          bfloat16, double, RoundingMode);
 #if defined(LIBC_TYPES_HAS_NATIVE_FLOAT128) &&                                 \
     defined(LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE)
 template void explain_binary_operation_one_output_error(
-    Operation, const BinaryInput<float128> &, bfloat16, double, RoundingMode,
-    MatchResultListener *);
+    Operation, const BinaryInput<float128> &, bfloat16, double, RoundingMode);
 #endif // defined(LIBC_TYPES_HAS_NATIVE_FLOAT128) &&
        // defined(LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE)
 
 template <typename InputType, typename OutputType>
 void explain_ternary_operation_one_output_error(
     Operation op, const TernaryInput<InputType> &input, OutputType libc_result,
-    double ulp_tolerance, RoundingMode rounding,
-    MatchResultListener *listener) {
+    double ulp_tolerance, RoundingMode rounding) {
   unsigned int precision = get_precision<InputType>(ulp_tolerance);
   MPFRNumber mpfrX(input.x, precision);
   MPFRNumber mpfrY(input.y, precision);
@@ -509,73 +483,64 @@ void explain_ternary_operation_one_output_error(
       op, input.x, input.y, input.z, precision, rounding);
   MPFRNumber mpfrMatchValue(libc_result);
 
-  *listener << "Input decimal: x: " << mpfrX.str() << " y: " << mpfrY.str()
-            << " z: " << mpfrZ.str() << '\n';
-  *listener << " First input bits: " << str(FPBits<InputType>(input.x)) << '\n';
-  *listener << "Second input bits: " << str(FPBits<InputType>(input.y)) << '\n';
-  *listener << " Third input bits: " << str(FPBits<InputType>(input.z)) << '\n';
-
-  *listener << "Libc result: " << mpfrMatchValue.str() << '\n'
-            << "MPFR result: " << mpfr_result.str() << '\n';
-  *listener << "Libc floating point result bits: "
-            << str(FPBits<OutputType>(libc_result)) << '\n';
-  *listener << "              MPFR rounded bits: "
-            << str(FPBits<OutputType>(mpfr_result.as<OutputType>())) << '\n';
-  *listener << "ULP error: "
-            << mpfr_result.ulp_as_mpfr_number(libc_result).str() << '\n';
+  tlog << "Input decimal: x: " << mpfrX.str() << " y: " << mpfrY.str()
+       << " z: " << mpfrZ.str() << '\n';
+  tlog << " First input bits: " << str(FPBits<InputType>(input.x)) << '\n';
+  tlog << "Second input bits: " << str(FPBits<InputType>(input.y)) << '\n';
+  tlog << " Third input bits: " << str(FPBits<InputType>(input.z)) << '\n';
+
+  tlog << "Libc result: " << mpfrMatchValue.str() << '\n'
+       << "MPFR result: " << mpfr_result.str() << '\n';
+  tlog << "Libc floating point result bits: "
+       << str(FPBits<OutputType>(libc_result)) << '\n';
+  tlog << "              MPFR rounded bits: "
+       << str(FPBits<OutputType>(mpfr_result.as<OutputType>())) << '\n';
+  tlog << "ULP error: " << mpfr_result.ulp_as_mpfr_number(libc_result).str()
+       << '\n';
 }
 
 template void explain_ternary_operation_one_output_error(
-    Operation, const TernaryInput<float> &, float, double, RoundingMode,
-    MatchResultListener *);
+    Operation, const TernaryInput<float> &, float, double, RoundingMode);
 template void explain_ternary_operation_one_output_error(
-    Operation, const TernaryInput<double> &, float, double, RoundingMode,
-    MatchResultListener *);
+    Operation, const TernaryInput<double> &, float, double, RoundingMode);
 template void explain_ternary_operation_one_output_error(
-    Operation, const TernaryInput<double> &, double, double, RoundingMode,
-    MatchResultListener *);
+    Operation, const TernaryInput<double> &, double, double, RoundingMode);
 template void explain_ternary_operation_one_output_error(
-    Operation, const TernaryInput<long double> &, float, double, RoundingMode,
-    MatchResultListener *);
-template void explain_ternary_operation_one_output_error(
-    Operation, const TernaryInput<long double> &, double, double, RoundingMode,
-    MatchResultListener *);
+    Operation, const TernaryInput<long double> &, float, double, RoundingMode);
 template void explain_ternary_operation_one_output_error(
-    Operation, const TernaryInput<long double> &, long double, double,
-    RoundingMode, MatchResultListener *);
+    Operation, const TernaryInput<long double> &, double, double, RoundingMode);
+template void
+explain_ternary_operation_one_output_error(Operation,
+                                           const TernaryInput<long double> &,
+                                           long double, double, RoundingMode);
 
 #ifdef LIBC_TYPES_HAS_FLOAT16
 template void explain_ternary_operation_one_output_error(
-    Operation, const TernaryInput<float16> &, float16, double, RoundingMode,
-    MatchResultListener *);
+    Operation, const TernaryInput<float16> &, float16, double, RoundingMode);
 template void explain_ternary_operation_one_output_error(
-    Operation, const TernaryInput<float> &, float16, double, RoundingMode,
-    MatchResultListener *);
+    Operation, const TernaryInput<float> &, float16, double, RoundingMode);
 template void explain_ternary_operation_one_output_error(
-    Operation, const TernaryInput<double> &, float16, double, RoundingMode,
-    MatchResultListener *);
-template void explain_ternary_operation_one_output_error(
-    Operation, const TernaryInput<long double> &, float16, double, RoundingMode,
-    MatchResultListener *);
+    Operation, const TernaryInput<double> &, float16, double, RoundingMode);
+template void
+explain_ternary_operation_one_output_error(Operation,
+                                           const TernaryInput<long double> &,
+                                           float16, double, RoundingMode);
 #endif
 
 template void explain_ternary_operation_one_output_error(
-    Operation, const TernaryInput<bfloat16> &, bfloat16, double, RoundingMode,
-    MatchResultListener *);
+    Operation, const TernaryInput<bfloat16> &, bfloat16, double, RoundingMode);
 template void explain_ternary_operation_one_output_error(
-    Operation, const TernaryInput<float> &, bfloat16, double, RoundingMode,
-    MatchResultListener *);
+    Operation, const TernaryInput<float> &, bfloat16, double, RoundingMode);
 template void explain_ternary_operation_one_output_error(
-    Operation, const TernaryInput<double> &, bfloat16, double, RoundingMode,
-    MatchResultListener *);
-template void explain_ternary_operation_one_output_error(
-    Operation, const TernaryInput<long double> &, bfloat16, double,
-    RoundingMode, MatchResultListener *);
+    Operation, const TernaryInput<double> &, bfloat16, double, RoundingMode);
+template void
+explain_ternary_operation_one_output_error(Operation,
+                                           const TernaryInput<long double> &,
+                                           bfloat16, double, RoundingMode);
 #if defined(LIBC_TYPES_HAS_NATIVE_FLOAT128) &&                                 \
     defined(LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE)
 template void explain_ternary_operation_one_output_error(
-    Operation, const TernaryInput<float128> &, bfloat16, double, RoundingMode,
-    MatchResultListener *);
+    Operation, const TernaryInput<float128> &, bfloat16, double, RoundingMode);
 #endif // defined(LIBC_TYPES_HAS_NATIVE_FLOAT128) &&
        // defined(LIBC_TYPES_FLOAT128_IS_NOT_LONG_DOUBLE)
 

diff  --git a/libc/utils/MPFRWrapper/MPFRUtils.h b/libc/utils/MPFRWrapper/MPFRUtils.h
index b40cf66981c851..84e59674295f57 100644
--- a/libc/utils/MPFRWrapper/MPFRUtils.h
+++ b/libc/utils/MPFRWrapper/MPFRUtils.h
@@ -205,31 +205,31 @@ template <typename InputType, typename OutputType>
 void explain_unary_operation_single_output_error(Operation op, InputType input,
                                                  OutputType match_value,
                                                  double ulp_tolerance,
-                                                 RoundingMode rounding,
-                                                 MatchResultListener *listener);
+                                                 RoundingMode rounding);
 template <typename T>
 void explain_unary_operation_two_outputs_error(
     Operation op, T input, const BinaryOutput<T> &match_value,
-    double ulp_tolerance, RoundingMode rounding, MatchResultListener *listener);
+    double ulp_tolerance, RoundingMode rounding);
 template <typename T>
 void explain_binary_operation_two_outputs_error(
     Operation op, const BinaryInput<T> &input,
     const BinaryOutput<T> &match_value, double ulp_tolerance,
-    RoundingMode rounding, MatchResultListener *listener);
+    RoundingMode rounding);
 
 template <typename InputType, typename OutputType>
 void explain_binary_operation_one_output_error(
     Operation op, const BinaryInput<InputType> &input, OutputType match_value,
-    double ulp_tolerance, RoundingMode rounding, MatchResultListener *listener);
+    double ulp_tolerance, RoundingMode rounding);
 
 template <typename InputType, typename OutputType>
 void explain_ternary_operation_one_output_error(
     Operation op, const TernaryInput<InputType> &input, OutputType match_value,
-    double ulp_tolerance, RoundingMode rounding, MatchResultListener *listener);
+    double ulp_tolerance, RoundingMode rounding);
 
 template <Operation op, bool silent, typename InputType, typename OutputType>
 class MPFRMatcher : public testing::Matcher<OutputType> {
   InputType input;
+  OutputType match_value;
   double ulp_tolerance;
   RoundingMode rounding;
 
@@ -237,82 +237,77 @@ class MPFRMatcher : public testing::Matcher<OutputType> {
   MPFRMatcher(InputType testInput, double ulp_tolerance, RoundingMode rounding)
       : input(testInput), ulp_tolerance(ulp_tolerance), rounding(rounding) {}
 
-  bool match(OutputType libcResult) const { return match(input, libcResult); }
-
-  bool MatchAndExplain(OutputType libcResult,
-                       MatchResultListener *listener) const {
-    if (match(libcResult))
-      return true;
-    if constexpr (!silent) {
-      if (listener->IsInterested())
-        explain_error(input, libcResult, listener);
-    }
-    return false;
+  bool match(OutputType libcResult) {
+    match_value = libcResult;
+    return match(input, match_value);
   }
 
+  // This method is marked with NOLINT because the name `explainError` does not
+  // conform to the coding style.
+  void explainError() override { // NOLINT
+    explain_error(input, match_value);
+  }
+
+  // Whether the `explainError` step is skipped or not.
+  bool is_silent() const override { return silent; }
+
 private:
   template <typename InType, typename OutType>
-  bool match(InType in, OutType out) const {
+  bool match(InType in, OutType out) {
     return compare_unary_operation_single_output(op, in, out, ulp_tolerance,
                                                  rounding);
   }
 
-  template <typename T> bool match(T in, const BinaryOutput<T> &out) const {
+  template <typename T> bool match(T in, const BinaryOutput<T> &out) {
     return compare_unary_operation_two_outputs(op, in, out, ulp_tolerance,
                                                rounding);
   }
 
   template <typename T, typename U>
-  bool match(const BinaryInput<T> &in, U out) const {
+  bool match(const BinaryInput<T> &in, U out) {
     return compare_binary_operation_one_output(op, in, out, ulp_tolerance,
                                                rounding);
   }
 
   template <typename T>
-  bool match(BinaryInput<T> in, const BinaryOutput<T> &out) const {
+  bool match(BinaryInput<T> in, const BinaryOutput<T> &out) {
     return compare_binary_operation_two_outputs(op, in, out, ulp_tolerance,
                                                 rounding);
   }
 
   template <typename InType, typename OutType>
-  bool match(const TernaryInput<InType> &in, OutType out) const {
+  bool match(const TernaryInput<InType> &in, OutType out) {
     return compare_ternary_operation_one_output(op, in, out, ulp_tolerance,
                                                 rounding);
   }
 
   template <typename InType, typename OutType>
-  void explain_error(InType in, OutType out,
-                     MatchResultListener *listener) const {
+  void explain_error(InType in, OutType out) {
     explain_unary_operation_single_output_error(op, in, out, ulp_tolerance,
-                                                rounding, listener);
+                                                rounding);
   }
 
-  template <typename T>
-  void explain_error(T in, const BinaryOutput<T> &out,
-                     MatchResultListener *listener) const {
+  template <typename T> void explain_error(T in, const BinaryOutput<T> &out) {
     explain_unary_operation_two_outputs_error(op, in, out, ulp_tolerance,
-                                              rounding, listener);
+                                              rounding);
   }
 
   template <typename T>
-  void explain_error(const BinaryInput<T> &in, const BinaryOutput<T> &out,
-                     MatchResultListener *listener) const {
+  void explain_error(const BinaryInput<T> &in, const BinaryOutput<T> &out) {
     explain_binary_operation_two_outputs_error(op, in, out, ulp_tolerance,
-                                               rounding, listener);
+                                               rounding);
   }
 
   template <typename T, typename U>
-  void explain_error(const BinaryInput<T> &in, U out,
-                     MatchResultListener *listener) const {
+  void explain_error(const BinaryInput<T> &in, U out) {
     explain_binary_operation_one_output_error(op, in, out, ulp_tolerance,
-                                              rounding, listener);
+                                              rounding);
   }
 
   template <typename InType, typename OutType>
-  void explain_error(const TernaryInput<InType> &in, OutType out,
-                     MatchResultListener *listener) const {
+  void explain_error(const TernaryInput<InType> &in, OutType out) {
     explain_ternary_operation_one_output_error(op, in, out, ulp_tolerance,
-                                               rounding, listener);
+                                               rounding);
   }
 };
 


        


More information about the libc-commits mailing list