[libc-commits] [libc] 2012a84 - [libc][test] Guard custom matchers with LIBC_TEST_HAS_MATCHERS() (#241062)
via libc-commits
libc-commits at lists.llvm.org
Tue Nov 10 16:59:38 PST 2026
Author: Roland McGrath
Date: 2026-11-10T16:59:33-08:00
New Revision: 2012a847c99ca4e68c0f931a9a09fe4cb8e2ebbd
URL: https://github.com/llvm/llvm-project/commit/2012a847c99ca4e68c0f931a9a09fe4cb8e2ebbd
DIFF: https://github.com/llvm/llvm-project/commit/2012a847c99ca4e68c0f931a9a09fe4cb8e2ebbd.diff
LOG: [libc][test] Guard custom matchers with LIBC_TEST_HAS_MATCHERS() (#241062)
Commit 528affb94ef8 (#240616) updated ErrnoSetterMatcher and FPMatcher
to
inherit from Matcher<T> and accept MatchResultListener * without
guarding
the matcher definitions on LIBC_TEST_HAS_MATCHERS(). Downstream test
frameworks that do not support matchers (such as Fuchsia's zxtest and
Pigweed's light pw_unit_test) fail to compile headers that transitively
include FPMatcher.h for FPTest or DECLARE_SPECIAL_CONSTANTS (e.g.
stdfix/ExpTest.h) or include ErrnoSetterMatcher.h.
Guard the matcher classes, factory helpers, and EXPECT_THAT/ASSERT_THAT
macros in ErrnoSetterMatcher.h and FPMatcher.h with
LIBC_TEST_HAS_MATCHERS(), keeping FPTest, DECLARE_SPECIAL_CONSTANTS, and
non-matcher rounding helpers unconditionally available, and replace the
unused ErrnoSetterMatcher.h include in snprintf_test.cpp with direct
CPP/limits.h.
Part of #91630
Assisted-by: Gemini
Added:
Modified:
libc/test/UnitTest/ErrnoSetterMatcher.h
libc/test/UnitTest/FPMatcher.h
libc/test/src/stdio/CMakeLists.txt
libc/test/src/stdio/snprintf_test.cpp
utils/bazel/llvm-project-overlay/libc/test/src/stdio/BUILD.bazel
Removed:
################################################################################
diff --git a/libc/test/UnitTest/ErrnoSetterMatcher.h b/libc/test/UnitTest/ErrnoSetterMatcher.h
index 310ae9af8220c2..6d490824073396 100644
--- a/libc/test/UnitTest/ErrnoSetterMatcher.h
+++ b/libc/test/UnitTest/ErrnoSetterMatcher.h
@@ -43,6 +43,8 @@
#include "src/__support/macros/properties/architectures.h"
#include "test/UnitTest/Test.h"
+#if LIBC_TEST_HAS_MATCHERS()
+
namespace LIBC_NAMESPACE_DECL {
namespace testing {
@@ -306,4 +308,6 @@ ErrnoSetterMatcherBuilder<RetT> returns(internal::Comparator<RetT> cmp) {
} // namespace testing
} // namespace LIBC_NAMESPACE_DECL
+#endif // LIBC_TEST_HAS_MATCHERS()
+
#endif // LLVM_LIBC_TEST_ERRNOSETTERMATCHER_H
diff --git a/libc/test/UnitTest/FPMatcher.h b/libc/test/UnitTest/FPMatcher.h
index 4eeb50b061445e..00b368fb80b698 100644
--- a/libc/test/UnitTest/FPMatcher.h
+++ b/libc/test/UnitTest/FPMatcher.h
@@ -30,6 +30,8 @@ using LIBC_NAMESPACE::Sign;
namespace LIBC_NAMESPACE_DECL {
namespace testing {
+#if LIBC_TEST_HAS_MATCHERS()
+
template <typename T, TestCond Condition> class FPMatcher : public Matcher<T> {
static_assert(cpp::is_floating_point_v<T>,
"FPMatcher can only be used with floating point values.");
@@ -183,6 +185,8 @@ CFPMatcher<T, C> getMatcherComplex(T expectedValue) {
return CFPMatcher<T, C>(expectedValue);
}
+#endif // LIBC_TEST_HAS_MATCHERS()
+
// Optimization barrier to prevent constant folding.
template <typename T> LIBC_INLINE T opaque(T value) {
// The pointer is volatile rather than the value, which keeps this usable for
@@ -291,6 +295,10 @@ struct ModifyMXCSR {
FP_INT_TONEAREST, UNKNOWN_MATH_ROUNDING_DIRECTION, \
};
+#define EXPECT_FP_IS_NAN(actual) EXPECT_TRUE((actual) != (actual))
+
+#if LIBC_TEST_HAS_MATCHERS()
+
#define EXPECT_FP_EQ(expected, actual) \
EXPECT_THAT(actual, LIBC_NAMESPACE::testing::getMatcher< \
LIBC_NAMESPACE::testing::TestCond::EQ>(expected))
@@ -304,8 +312,6 @@ struct ModifyMXCSR {
expected) \
.match(actual)
-#define EXPECT_FP_IS_NAN(actual) EXPECT_TRUE((actual) != (actual))
-
#define ASSERT_FP_EQ(expected, actual) \
ASSERT_THAT(actual, LIBC_NAMESPACE::testing::getMatcher< \
LIBC_NAMESPACE::testing::TestCond::EQ>(expected))
@@ -681,6 +687,8 @@ struct ModifyMXCSR {
(expected_except)); \
} while (0)
+#endif // LIBC_TEST_HAS_MATCHERS()
+
#define ASSERT_EQ_ROUNDING_MODE(expected, actual, rounding_mode) \
do { \
using namespace LIBC_NAMESPACE::fputil::testing; \
diff --git a/libc/test/src/stdio/CMakeLists.txt b/libc/test/src/stdio/CMakeLists.txt
index e20395737b2d1e..3dee3e3456069e 100644
--- a/libc/test/src/stdio/CMakeLists.txt
+++ b/libc/test/src/stdio/CMakeLists.txt
@@ -248,6 +248,7 @@ add_libc_test(
SRCS
snprintf_test.cpp
DEPENDS
+ libc.src.__support.CPP.limits
libc.src.stdio.snprintf
)
diff --git a/libc/test/src/stdio/snprintf_test.cpp b/libc/test/src/stdio/snprintf_test.cpp
index 95507e0885dbfb..701e0615506e7b 100644
--- a/libc/test/src/stdio/snprintf_test.cpp
+++ b/libc/test/src/stdio/snprintf_test.cpp
@@ -8,8 +8,8 @@
#include "src/stdio/snprintf.h"
+#include "src/__support/CPP/limits.h"
#include "test/UnitTest/ErrnoCheckingTest.h"
-#include "test/UnitTest/ErrnoSetterMatcher.h"
#include "test/UnitTest/Test.h"
using LlvmLibcSNPrintfTest = LIBC_NAMESPACE::testing::ErrnoCheckingTest;
diff --git a/utils/bazel/llvm-project-overlay/libc/test/src/stdio/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/src/stdio/BUILD.bazel
index fa58ac8da2ac46..30812189f0ae63 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/src/stdio/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/src/stdio/BUILD.bazel
@@ -37,6 +37,7 @@ libc_test(
name = "snprintf_test",
srcs = ["snprintf_test.cpp"],
deps = [
+ "//libc:__support_cpp_limits",
"//libc:snprintf",
],
)
More information about the libc-commits
mailing list