mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2025-02-02 07:06:33 +00:00
[include-cleaner] Always keep non-self-contained files (#65499)
This commit is contained in:
parent
1f15155d5e
commit
d3cfc7126c
@ -88,10 +88,10 @@ TEST(IncludeCleaner, StdlibUnused) {
|
||||
template <typename> class vector {};
|
||||
}
|
||||
)cpp";
|
||||
TU.AdditionalFiles["list"] = "#include <bits>";
|
||||
TU.AdditionalFiles["queue"] = "#include <bits>";
|
||||
TU.AdditionalFiles["vector"] = "#include <bits>";
|
||||
TU.AdditionalFiles["string"] = "#include <bits>";
|
||||
TU.AdditionalFiles["list"] = guard("#include <bits>");
|
||||
TU.AdditionalFiles["queue"] = guard("#include <bits>");
|
||||
TU.AdditionalFiles["vector"] = guard("#include <bits>");
|
||||
TU.AdditionalFiles["string"] = guard("#include <bits>");
|
||||
TU.ExtraArgs = {"-isystem", testRoot()};
|
||||
auto AST = TU.build();
|
||||
IncludeCleanerFindings Findings = computeIncludeCleanerFindings(AST);
|
||||
|
@ -430,7 +430,8 @@ bool PragmaIncludes::isPrivate(const FileEntry *FE) const {
|
||||
}
|
||||
|
||||
bool PragmaIncludes::shouldKeep(const FileEntry *FE) const {
|
||||
return ShouldKeep.contains(FE->getUniqueID());
|
||||
return ShouldKeep.contains(FE->getUniqueID()) ||
|
||||
NonSelfContainedFiles.contains(FE->getUniqueID());
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
@ -320,7 +320,7 @@ protected:
|
||||
|
||||
void createEmptyFiles(llvm::ArrayRef<StringRef> FileNames) {
|
||||
for (llvm::StringRef File : FileNames)
|
||||
Inputs.ExtraFiles[File] = "";
|
||||
Inputs.ExtraFiles[File] = "#pragma once";
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -47,9 +47,10 @@ TEST(IncludeCleanerCheckTest, BasicUnusedIncludes) {
|
||||
const char *PostCode = "\n";
|
||||
|
||||
std::vector<ClangTidyError> Errors;
|
||||
EXPECT_EQ(PostCode, runCheckOnCode<IncludeCleanerCheck>(
|
||||
PreCode, &Errors, "file.cpp", std::nullopt,
|
||||
ClangTidyOptions(), {{"bar.h", ""}, {"vector", ""}}));
|
||||
EXPECT_EQ(PostCode,
|
||||
runCheckOnCode<IncludeCleanerCheck>(
|
||||
PreCode, &Errors, "file.cpp", std::nullopt, ClangTidyOptions(),
|
||||
{{"bar.h", "#pragma once"}, {"vector", "#pragma once"}}));
|
||||
}
|
||||
|
||||
TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
|
||||
@ -76,10 +77,11 @@ TEST(IncludeCleanerCheckTest, SuppressUnusedIncludes) {
|
||||
PostCode,
|
||||
runCheckOnCode<IncludeCleanerCheck>(
|
||||
PreCode, &Errors, "file.cpp", std::nullopt, Opts,
|
||||
{{"bar.h", ""},
|
||||
{"vector", ""},
|
||||
{appendPathFileSystemIndependent({"foo", "qux.h"}), ""},
|
||||
{appendPathFileSystemIndependent({"baz", "qux", "qux.h"}), ""}}));
|
||||
{{"bar.h", "#pragma once"},
|
||||
{"vector", "#pragma once"},
|
||||
{appendPathFileSystemIndependent({"foo", "qux.h"}), "#pragma once"},
|
||||
{appendPathFileSystemIndependent({"baz", "qux", "qux.h"}),
|
||||
"#pragma once"}}));
|
||||
}
|
||||
|
||||
TEST(IncludeCleanerCheckTest, BasicMissingIncludes) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user