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

via libc-commits libc-commits at lists.llvm.org
Sun Nov 29 20:24:57 PST 2026


llvmorg-github-actions[bot] wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-libc

Author: Roland McGrath (frobtech)

<details>
<summary>Changes</summary>

`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 lets alternate test framework headers such as `GTest.h` reuse it without duplicating the declaration.

Part of #<!-- -->91630

Assisted-by: Gemini

---
Full diff: https://github.com/llvm/llvm-project/pull/247018.diff


6 Files Affected:

- (modified) libc/test/UnitTest/BazelFilePath.cpp (+1-1) 
- (modified) libc/test/UnitTest/CMakeLists.txt (+1) 
- (modified) libc/test/UnitTest/CmakeFilePath.cpp (+1-1) 
- (modified) libc/test/UnitTest/LibcTest.h (+2-15) 
- (added) libc/test/UnitTest/TestFilePath.h (+32) 
- (modified) utils/bazel/llvm-project-overlay/libc/test/UnitTest/BUILD.bazel (+1) 


``````````diff
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..2f1cfba7280cae
--- /dev/null
+++ b/libc/test/UnitTest/TestFilePath.h
@@ -0,0 +1,32 @@
+//===-- 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.
+#undef 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",

``````````

</details>


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


More information about the libc-commits mailing list