Skip to content

Commit

Permalink
[include-cleaner] Add regression tests for outliving File&Source Manager
Browse files Browse the repository at this point in the history
  • Loading branch information
kadircet committed Nov 17, 2023
1 parent 0b04406 commit 7aaa86b
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions clang-tools-extra/include-cleaner/unittests/RecordTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -558,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

0 comments on commit 7aaa86b

Please sign in to comment.