================ @@ -379,6 +379,54 @@ TEST_F(PragmaIncludeTest, IWYUKeep) { EXPECT_TRUE(PI.shouldKeep(FM.getFile("std/set").get())); } +TEST_F(PragmaIncludeTest, AssociatedHeader) { + createEmptyFiles({"foo/main.h", "bar/main.h", "bar/other.h", "std/vector"}); + auto IsKeep = [&](llvm::StringRef Name, TestAST &AST) { + return PI.shouldKeep(AST.fileManager().getFile(Name).get()); + }; + + Inputs.FileName = "main.cc"; + Inputs.ExtraArgs.push_back("-isystemstd"); + { + Inputs.Code = R"cpp( + #include "foo/main.h" + #include "bar/main.h" + )cpp"; + auto AST = build(); + EXPECT_TRUE(IsKeep("foo/main.h", AST)); + EXPECT_FALSE(IsKeep("bar/main.h", AST)) << "not first include"; + } + + { + Inputs.Code = R"cpp( + #include "bar/other.h" + #include "bar/main.h" + )cpp"; + auto AST = build(); + EXPECT_FALSE(IsKeep("bar/other.h", AST)); + EXPECT_FALSE(IsKeep("bar/main.h", AST)) << "not first include"; + } + + { + Inputs.Code = R"cpp( + #include "foo/main.h" + #include "bar/other.h" // IWYU pragma: associated ---------------- sam-mccall wrote:
Sure. Combined this with a test that associated on stdlib headers is honored. (As a bonus, I found that we were reusing PragmaIncludes across testcases, fixed that too!) https://github.com/llvm/llvm-project/pull/67228 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits