[clang] [clang-tools-extra] [clang-format][clang-tools-extra] Fix leaking of host-level config into test environment (PR #206358)
Damian Höster via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 21 13:53:11 PDT 2026
================
@@ -63,10 +63,10 @@ class ChangeNamespaceTest : public ::testing::Test {
}
protected:
- std::string FileName = "input.cc";
+ std::string FileName = "/test/input.cc";
----------------
damster101 wrote:
> Do tests create new files in source tree?
No
> In other words, how it previously failed due to .clang-format? clang-change-namespaces seems a complete separate tool to me
Generally, failures when running tests happened because `clang-change-namespace` calls `formatAndApplyAllReplacements()` to reformat rewritten code. And since `formatAndApplyAllReplacements()` defaults to `Style = "file"`, `clang::format::getStyle()` looks for the first .clang-format it can find as it walks up ancestry directories, which then can be a user-specified .clang-format outside the llvm project in case of out-of-source build directory.
By setting `FileName` to `"/test/input.cc"`, that search is anchored to /test/ so it never inspects the build directory and its ancestors.
But hold on, I think I found a much simpler fix for this... More consistent, more explicit...
https://github.com/llvm/llvm-project/pull/206358
More information about the cfe-commits
mailing list