Skip to content

Commit 7aaa86b

Browse files
committed
[include-cleaner] Add regression tests for outliving File&Source Manager
1 parent 0b04406 commit 7aaa86b

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

clang-tools-extra/include-cleaner/unittests/RecordTest.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,5 +558,35 @@ TEST_F(PragmaIncludeTest, ExportInUnnamedBuffer) {
558558
PI.getExporters(llvm::cantFail(FM->getFileRef("foo.h")), *FM),
559559
testing::ElementsAre(llvm::cantFail(FM->getFileRef("exporter.h"))));
560560
}
561+
562+
TEST_F(PragmaIncludeTest, OutlivesFMAndSM) {
563+
Inputs.Code = R"cpp(
564+
#include "public.h"
565+
)cpp";
566+
Inputs.ExtraFiles["public.h"] = R"cpp(
567+
#include "private.h"
568+
#include "private2.h" // IWYU pragma: export
569+
)cpp";
570+
Inputs.ExtraFiles["private.h"] = R"cpp(
571+
// IWYU pragma: private, include "public.h"
572+
)cpp";
573+
Inputs.ExtraFiles["private2.h"] = R"cpp(
574+
// IWYU pragma: private
575+
)cpp";
576+
build(); // Fills up PI, file/source manager used is destroyed afterwards.
577+
Inputs.MakeAction = nullptr; // Don't populate PI anymore.
578+
579+
// Now this build gives us a new File&Source Manager.
580+
TestAST Processed = build();
581+
auto &FM = Processed.fileManager();
582+
auto PrivateFE = FM.getFile("private.h");
583+
assert(PrivateFE);
584+
EXPECT_EQ(PI.getPublic(PrivateFE.get()), "\"public.h\"");
585+
586+
auto Private2FE = FM.getFile("private2.h");
587+
assert(Private2FE);
588+
EXPECT_THAT(PI.getExporters(Private2FE.get(), FM),
589+
testing::ElementsAre(llvm::cantFail(FM.getFileRef("public.h"))));
590+
}
561591
} // namespace
562592
} // namespace clang::include_cleaner

0 commit comments

Comments
 (0)