[libc-commits] [libc] [llvm] [libc][test] Factor TestFilePath.h out of LibcTest.h (PR #247018)

Roland McGrath via libc-commits libc-commits at lists.llvm.org
Sun Nov 29 14:25:22 PST 2026


https://github.com/frobtech updated https://github.com/llvm/llvm-project/pull/247018

>From c00ccb9909983aefa45baeb9eba6c7f224d4b17f Mon Sep 17 00:00:00 2001
From: Roland McGrath <mcgrathr at google.com>
Date: Sun, 29 Nov 2026 14:04:44 -0800
Subject: [PATCH 1/2] [libc][test] Factor TestFilePath.h out of LibcTest.h

BazelFilePath.cpp and CmakeFilePath.cpp only included LibcTest.h for
the libc_make_test_file_path_func declaration. Moving the
libc_make_test_file_path macro and libc_make_test_file_path_func
prototype into a small framework-independent TestFilePath.h header lets
both file-path helpers build without depending on LibcTest.h and avoids
duplicating the declaration in alternate test framework headers such as
GTest.h.

Part of #91630

Assisted-by: Gemini
---
 libc/test/UnitTest/BazelFilePath.cpp          |  2 +-
 libc/test/UnitTest/CMakeLists.txt             |  1 +
 libc/test/UnitTest/CmakeFilePath.cpp          |  2 +-
 libc/test/UnitTest/LibcTest.h                 | 17 ++--------
 libc/test/UnitTest/TestFilePath.h             | 34 +++++++++++++++++++
 .../libc/test/UnitTest/BUILD.bazel            |  1 +
 6 files changed, 40 insertions(+), 17 deletions(-)
 create mode 100644 libc/test/UnitTest/TestFilePath.h

diff --git a/libc/test/UnitTest/BazelFilePath.cpp b/libc/test/UnitTest/BazelFilePath.cpp
index a2ae6b4f915579..c77b248b9de05b 100644
--- a/libc/test/UnitTest/BazelFilePath.cpp
+++ b/libc/test/UnitTest/BazelFilePath.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "LibcTest.h"
+#include "test/UnitTest/TestFilePath.h"
 
 #include "src/__support/CPP/string.h"
 #include "src/__support/c_string.h"
diff --git a/libc/test/UnitTest/CMakeLists.txt b/libc/test/UnitTest/CMakeLists.txt
index 2a135457400061..99ec43236c5a64 100644
--- a/libc/test/UnitTest/CMakeLists.txt
+++ b/libc/test/UnitTest/CMakeLists.txt
@@ -94,6 +94,7 @@ add_unittest_framework_library(
   HDRS
     LibcTest.h
     Test.h
+    TestFilePath.h
     TestLogger.h
   COMPILE_OPTIONS
     ${test_logger_compile_options}
diff --git a/libc/test/UnitTest/CmakeFilePath.cpp b/libc/test/UnitTest/CmakeFilePath.cpp
index b7bc5a8573dc8b..8add98a360d816 100644
--- a/libc/test/UnitTest/CmakeFilePath.cpp
+++ b/libc/test/UnitTest/CmakeFilePath.cpp
@@ -6,7 +6,7 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "LibcTest.h"
+#include "test/UnitTest/TestFilePath.h"
 
 #include "src/__support/CPP/string.h"
 #include "src/__support/c_string.h"
diff --git a/libc/test/UnitTest/LibcTest.h b/libc/test/UnitTest/LibcTest.h
index 42c15fa4decf45..502b658599d2cb 100644
--- a/libc/test/UnitTest/LibcTest.h
+++ b/libc/test/UnitTest/LibcTest.h
@@ -9,18 +9,6 @@
 #ifndef LLVM_LIBC_TEST_UNITTEST_LIBCTEST_H
 #define LLVM_LIBC_TEST_UNITTEST_LIBCTEST_H
 
-// This is defined as a simple macro in test.h so that it exists for platforms
-// that don't use our test infrastructure. It's defined as a proper function
-// below.
-#include "src/__support/macros/config.h"
-#ifdef libc_make_test_file_path
-#undef libc_make_test_file_path
-#endif // libc_make_test_file_path
-
-// This is defined as a macro here to avoid namespace issues.
-#define libc_make_test_file_path(file_name)                                    \
-  (LIBC_NAMESPACE::testing::libc_make_test_file_path_func(file_name))
-
 // This file can only include headers from src/__support/ or test/UnitTest. No
 // other headers should be included.
 
@@ -29,9 +17,10 @@
 #include "src/__support/CPP/string.h"
 #include "src/__support/CPP/string_view.h"
 #include "src/__support/CPP/type_traits.h"
-#include "src/__support/c_string.h"
+#include "src/__support/macros/config.h"
 #include "src/__support/macros/properties/compiler.h"
 #include "test/UnitTest/ExecuteFunction.h"
+#include "test/UnitTest/TestFilePath.h"
 #include "test/UnitTest/TestLogger.h"
 
 namespace LIBC_NAMESPACE_DECL {
@@ -326,8 +315,6 @@ template <typename... Ts> struct Types {
 // Make Types visible in LIBC_NAMESPACE::testing.
 using internal::Types;
 
-CString libc_make_test_file_path_func(const char *file_name);
-
 } // namespace testing
 } // namespace LIBC_NAMESPACE_DECL
 
diff --git a/libc/test/UnitTest/TestFilePath.h b/libc/test/UnitTest/TestFilePath.h
new file mode 100644
index 00000000000000..1334eb27e95bbf
--- /dev/null
+++ b/libc/test/UnitTest/TestFilePath.h
@@ -0,0 +1,34 @@
+//===-- Test file path helper declaration -----------------------*- C++ -*-===//
+//
+// 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_LIBC_TEST_UNITTEST_TESTFILEPATH_H
+#define LLVM_LIBC_TEST_UNITTEST_TESTFILEPATH_H
+
+#include "src/__support/c_string.h"
+#include "src/__support/macros/config.h"
+
+// This is defined as a simple macro in Test.h so that it exists for platforms
+// that don't use our test infrastructure. It's redefined here to call the
+// build-system-specific helper function below.
+#ifdef libc_make_test_file_path
+#undef libc_make_test_file_path
+#endif // libc_make_test_file_path
+
+// This is defined as a macro here to avoid namespace issues.
+#define libc_make_test_file_path(file_name)                                    \
+  (LIBC_NAMESPACE::testing::libc_make_test_file_path_func(file_name))
+
+namespace LIBC_NAMESPACE_DECL {
+namespace testing {
+
+CString libc_make_test_file_path_func(const char *file_name);
+
+} // namespace testing
+} // namespace LIBC_NAMESPACE_DECL
+
+#endif // LLVM_LIBC_TEST_UNITTEST_TESTFILEPATH_H
diff --git a/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel b/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel
index 00e41c8c274818..231a2d1a594af6 100644
--- a/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel
+++ b/utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel
@@ -53,6 +53,7 @@ libc_test_library(
         "ExecuteFunction.h",
         "LibcTest.h",
         "Test.h",
+        "TestFilePath.h",
     ],
     deps = [
         ":string_utils",

>From ffee01a001965502c4e2ab5a03d1643ec84bbd96 Mon Sep 17 00:00:00 2001
From: Roland McGrath <mcgrathr at google.com>
Date: Sun, 29 Nov 2026 14:25:11 -0800
Subject: [PATCH 2/2] [libc][test] Drop redundant #ifdef around #undef in
 TestFilePath.h

Assisted-by: Gemini
---
 libc/test/UnitTest/TestFilePath.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/libc/test/UnitTest/TestFilePath.h b/libc/test/UnitTest/TestFilePath.h
index 1334eb27e95bbf..2f1cfba7280cae 100644
--- a/libc/test/UnitTest/TestFilePath.h
+++ b/libc/test/UnitTest/TestFilePath.h
@@ -15,9 +15,7 @@
 // This is defined as a simple macro in Test.h so that it exists for platforms
 // that don't use our test infrastructure. It's redefined here to call the
 // build-system-specific helper function below.
-#ifdef libc_make_test_file_path
 #undef libc_make_test_file_path
-#endif // libc_make_test_file_path
 
 // This is defined as a macro here to avoid namespace issues.
 #define libc_make_test_file_path(file_name)                                    \



More information about the libc-commits mailing list