Skip to content

Commit 778a1f2

Browse files
committed
[include-cleaner] Fix windows buildbots after 64d9713
1 parent 103cdd4 commit 778a1f2

File tree

1 file changed

+33
-13
lines changed

1 file changed

+33
-13
lines changed

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

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "clang-include-cleaner/Types.h"
1111
#include "clang/AST/Decl.h"
1212
#include "clang/Basic/Diagnostic.h"
13+
#include "clang/Basic/FileEntry.h"
1314
#include "clang/Basic/LLVM.h"
1415
#include "clang/Basic/SourceLocation.h"
1516
#include "clang/Frontend/CompilerInvocation.h"
@@ -24,6 +25,7 @@
2425
#include "llvm/ADT/StringRef.h"
2526
#include "llvm/Support/Error.h"
2627
#include "llvm/Support/MemoryBuffer.h"
28+
#include "llvm/Support/Path.h"
2729
#include "llvm/Support/VirtualFileSystem.h"
2830
#include "llvm/Support/raw_ostream.h"
2931
#include "llvm/Testing/Annotations/Annotations.h"
@@ -53,8 +55,8 @@ MATCHER_P(named, N, "") {
5355
}
5456

5557
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());
5860
if (ActualName == N)
5961
return true;
6062
*result_listener << ActualName.str();
@@ -319,7 +321,8 @@ class PragmaIncludeTest : public ::testing::Test {
319321
}
320322

321323
TestAST build(bool ResetPragmaIncludes = true) {
322-
if (ResetPragmaIncludes) PI = PragmaIncludes();
324+
if (ResetPragmaIncludes)
325+
PI = PragmaIncludes();
323326
return TestAST(Inputs);
324327
}
325328

@@ -537,16 +540,33 @@ TEST_F(PragmaIncludeTest, IWYUExportBlock) {
537540
TestAST Processed = build();
538541
auto &FM = Processed.fileManager();
539542

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);
550570
}
551571

552572
TEST_F(PragmaIncludeTest, SelfContained) {

0 commit comments

Comments
 (0)