|
10 | 10 | #include "clang-include-cleaner/Types.h"
|
11 | 11 | #include "clang/AST/Decl.h"
|
12 | 12 | #include "clang/Basic/Diagnostic.h"
|
| 13 | +#include "clang/Basic/FileEntry.h" |
13 | 14 | #include "clang/Basic/LLVM.h"
|
14 | 15 | #include "clang/Basic/SourceLocation.h"
|
15 | 16 | #include "clang/Frontend/CompilerInvocation.h"
|
|
24 | 25 | #include "llvm/ADT/StringRef.h"
|
25 | 26 | #include "llvm/Support/Error.h"
|
26 | 27 | #include "llvm/Support/MemoryBuffer.h"
|
| 28 | +#include "llvm/Support/Path.h" |
27 | 29 | #include "llvm/Support/VirtualFileSystem.h"
|
28 | 30 | #include "llvm/Support/raw_ostream.h"
|
29 | 31 | #include "llvm/Testing/Annotations/Annotations.h"
|
@@ -53,8 +55,8 @@ MATCHER_P(named, N, "") {
|
53 | 55 | }
|
54 | 56 |
|
55 | 57 | MATCHER_P(FileNamed, N, "") {
|
56 |
| - llvm::StringRef ActualName = arg.getName(); |
57 |
| - ActualName.consume_front("./"); |
| 58 | + llvm::StringRef ActualName = |
| 59 | + llvm::sys::path::remove_leading_dotslash(arg.getName()); |
58 | 60 | if (ActualName == N)
|
59 | 61 | return true;
|
60 | 62 | *result_listener << ActualName.str();
|
@@ -319,7 +321,8 @@ class PragmaIncludeTest : public ::testing::Test {
|
319 | 321 | }
|
320 | 322 |
|
321 | 323 | TestAST build(bool ResetPragmaIncludes = true) {
|
322 |
| - if (ResetPragmaIncludes) PI = PragmaIncludes(); |
| 324 | + if (ResetPragmaIncludes) |
| 325 | + PI = PragmaIncludes(); |
323 | 326 | return TestAST(Inputs);
|
324 | 327 | }
|
325 | 328 |
|
@@ -537,16 +540,33 @@ TEST_F(PragmaIncludeTest, IWYUExportBlock) {
|
537 | 540 | TestAST Processed = build();
|
538 | 541 | auto &FM = Processed.fileManager();
|
539 | 542 |
|
540 |
| - EXPECT_THAT(PI.getExporters(FM.getFile("private1.h").get(), FM), |
541 |
| - testing::UnorderedElementsAre(FileNamed("export1.h"), |
542 |
| - FileNamed("normal.h"))); |
543 |
| - EXPECT_THAT(PI.getExporters(FM.getFile("private2.h").get(), FM), |
544 |
| - testing::UnorderedElementsAre(FileNamed("export1.h"))); |
545 |
| - EXPECT_THAT(PI.getExporters(FM.getFile("private3.h").get(), FM), |
546 |
| - testing::UnorderedElementsAre(FileNamed("export1.h"))); |
547 |
| - |
548 |
| - EXPECT_TRUE(PI.getExporters(FM.getFile("foo.h").get(), FM).empty()); |
549 |
| - EXPECT_TRUE(PI.getExporters(FM.getFile("bar.h").get(), FM).empty()); |
| 543 | + auto GetNames = [](llvm::ArrayRef<FileEntryRef> FEs) { |
| 544 | + std::string Result; |
| 545 | + llvm::raw_string_ostream OS(Result); |
| 546 | + for (auto &FE : FEs) { |
| 547 | + OS << FE.getName() << " "; |
| 548 | + } |
| 549 | + OS.flush(); |
| 550 | + return Result; |
| 551 | + }; |
| 552 | + auto Exporters = PI.getExporters(FM.getFile("private1.h").get(), FM); |
| 553 | + EXPECT_THAT(Exporters, testing::UnorderedElementsAre(FileNamed("export1.h"), |
| 554 | + FileNamed("normal.h"))) |
| 555 | + << GetNames(Exporters); |
| 556 | + |
| 557 | + Exporters = PI.getExporters(FM.getFile("private2.h").get(), FM); |
| 558 | + EXPECT_THAT(Exporters, testing::UnorderedElementsAre(FileNamed("export1.h"))) |
| 559 | + << GetNames(Exporters); |
| 560 | + |
| 561 | + Exporters = PI.getExporters(FM.getFile("private3.h").get(), FM); |
| 562 | + EXPECT_THAT(Exporters, testing::UnorderedElementsAre(FileNamed("export1.h"))) |
| 563 | + << GetNames(Exporters); |
| 564 | + |
| 565 | + Exporters = PI.getExporters(FM.getFile("foo.h").get(), FM); |
| 566 | + EXPECT_TRUE(Exporters.empty()) << GetNames(Exporters); |
| 567 | + |
| 568 | + Exporters = PI.getExporters(FM.getFile("bar.h").get(), FM); |
| 569 | + EXPECT_TRUE(Exporters.empty()) << GetNames(Exporters); |
550 | 570 | }
|
551 | 571 |
|
552 | 572 | TEST_F(PragmaIncludeTest, SelfContained) {
|
|
0 commit comments