[libc-commits] [libc] ebf1239 - [libc][test] Split PigweedTest.h out of GTest.h (#247278)

via libc-commits libc-commits at lists.llvm.org
Mon Nov 30 13:57:15 PST 2026


Author: Roland McGrath
Date: 2026-11-30T13:57:09-08:00
New Revision: ebf12390bf29e63e61baafe9255df8aca2980ca7

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

LOG: [libc][test] Split PigweedTest.h out of GTest.h (#247278)

Test.h previously routed LIBC_COPT_TEST_USE_PIGWEED to GTest.h with a
TODO to migrate Pigweed onto LIBC_COPT_TEST_USE_GTEST. However,
Pigweed's pw_unit_test:light backend does not provide ::testing::Matcher
or gmock-style matchers, so sharing GTest.h fails to compile against
pw_unit_test:light and leaves LIBC_TEST_HAS_MATCHERS() enabled when
matchers are unavailable.

Give LIBC_COPT_TEST_USE_PIGWEED its own minimal PigweedTest.h adapter
that exports LIBC_NAMESPACE::testing::Test from <gtest/gtest.h> and
defines LIBC_TEST_HAS_MATCHERS() as (0), matching ZxTest.h. This keeps
Pigweed builds working against pw_unit_test:light while allowing GTest.h
to rely on real GoogleTest and GoogleMock facilities.

Part of #91630

Assisted-by: Gemini

Added: 
    libc/test/UnitTest/PigweedTest.h

Modified: 
    libc/test/UnitTest/Test.h

Removed: 
    


################################################################################
diff  --git a/libc/test/UnitTest/PigweedTest.h b/libc/test/UnitTest/PigweedTest.h
new file mode 100644
index 0000000000000..20d9f4d30f86e
--- /dev/null
+++ b/libc/test/UnitTest/PigweedTest.h
@@ -0,0 +1,31 @@
+//===----------------------------------------------------------------------===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+///
+/// \file
+/// Adapter header for running llvm-libc unit tests with Pigweed's pw_unit_test.
+///
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TEST_UNITTEST_PIGWEEDTEST_H
+#define LLVM_LIBC_TEST_UNITTEST_PIGWEEDTEST_H
+
+#include "src/__support/macros/config.h"
+#include <gtest/gtest.h>
+
+namespace LIBC_NAMESPACE_DECL {
+namespace testing {
+
+using ::testing::Test;
+
+} // namespace testing
+} // namespace LIBC_NAMESPACE_DECL
+
+// pw_unit_test's light backend does not provide gmock-style matchers.
+#define LIBC_TEST_HAS_MATCHERS() (0)
+
+#endif // LLVM_LIBC_TEST_UNITTEST_PIGWEEDTEST_H

diff  --git a/libc/test/UnitTest/Test.h b/libc/test/UnitTest/Test.h
index 6f6c186e0ca93..f740039a86e31 100644
--- a/libc/test/UnitTest/Test.h
+++ b/libc/test/UnitTest/Test.h
@@ -16,22 +16,24 @@
 // redefine it as necessary.
 #define libc_make_test_file_path(file_name) (file_name)
 
-// The LIBC_COPT_TEST_USE_* macros can select either of two alternate test
+// The LIBC_COPT_TEST_USE_* macros can select any of three alternate test
 // frameworks:
 //  * gtest, the well-known model for them all
 //  * zxtest, the gtest workalike subset sometimes used in the Fuchsia build
+//  * pw_unit_test, Pigweed's lightweight gtest-compatible embedded framework
 // The default is to use llvm-libc's own gtest workalike framework.
 //
 // All the frameworks provide the basic EXPECT_* and ASSERT_* macros that gtest
 // does.  The wrapper headers below define LIBC_NAMESPACE::testing::Test as the
 // base class for test fixture classes.  Each also provides a definition of the
 // macro LIBC_TEST_HAS_MATCHERS() for use in `#if` conditionals to guard use of
-// gmock-style matchers, which zxtest does not support.
+// gmock-style matchers, which zxtest and pw_unit_test do not support.
 
 #if defined(LIBC_COPT_TEST_USE_ZXTEST)
 #include "ZxTest.h"
-// TODO: Migrate Pigweed to setting LIBC_COPT_TEST_USE_GTEST instead.
-#elif defined(LIBC_COPT_TEST_USE_GTEST) || defined(LIBC_COPT_TEST_USE_PIGWEED)
+#elif defined(LIBC_COPT_TEST_USE_PIGWEED)
+#include "PigweedTest.h"
+#elif defined(LIBC_COPT_TEST_USE_GTEST)
 #include "GTest.h"
 #else
 #include "LibcTest.h"


        


More information about the libc-commits mailing list