aboutsummaryrefslogtreecommitdiff
path: root/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang-tools-extra/include-cleaner/unittests/RecordTest.cpp')
-rw-r--r--clang-tools-extra/include-cleaner/unittests/RecordTest.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp b/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
index 3685073..0f2ded5 100644
--- a/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
+++ b/clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
@@ -452,6 +452,8 @@ TEST_F(PragmaIncludeTest, IWYUExportForStandardHeaders) {
auto &FM = Processed.fileManager();
EXPECT_THAT(PI.getExporters(*tooling::stdlib::Header::named("<string>"), FM),
testing::UnorderedElementsAre(FileNamed("export.h")));
+ EXPECT_THAT(PI.getExporters(llvm::cantFail(FM.getFileRef("string")), FM),
+ testing::UnorderedElementsAre(FileNamed("export.h")));
}
TEST_F(PragmaIncludeTest, IWYUExportBlock) {
@@ -556,5 +558,35 @@ TEST_F(PragmaIncludeTest, ExportInUnnamedBuffer) {
PI.getExporters(llvm::cantFail(FM->getFileRef("foo.h")), *FM),
testing::ElementsAre(llvm::cantFail(FM->getFileRef("exporter.h"))));
}
+
+TEST_F(PragmaIncludeTest, OutlivesFMAndSM) {
+ Inputs.Code = R"cpp(
+ #include "public.h"
+ )cpp";
+ Inputs.ExtraFiles["public.h"] = R"cpp(
+ #include "private.h"
+ #include "private2.h" // IWYU pragma: export
+ )cpp";
+ Inputs.ExtraFiles["private.h"] = R"cpp(
+ // IWYU pragma: private, include "public.h"
+ )cpp";
+ Inputs.ExtraFiles["private2.h"] = R"cpp(
+ // IWYU pragma: private
+ )cpp";
+ build(); // Fills up PI, file/source manager used is destroyed afterwards.
+ Inputs.MakeAction = nullptr; // Don't populate PI anymore.
+
+ // Now this build gives us a new File&Source Manager.
+ TestAST Processed = build();
+ auto &FM = Processed.fileManager();
+ auto PrivateFE = FM.getFile("private.h");
+ assert(PrivateFE);
+ EXPECT_EQ(PI.getPublic(PrivateFE.get()), "\"public.h\"");
+
+ auto Private2FE = FM.getFile("private2.h");
+ assert(Private2FE);
+ EXPECT_THAT(PI.getExporters(Private2FE.get(), FM),
+ testing::ElementsAre(llvm::cantFail(FM.getFileRef("public.h"))));
+}
} // namespace
} // namespace clang::include_cleaner