summaryrefslogtreecommitdiffstats
path: root/clang/unittests
diff options
context:
space:
mode:
Diffstat (limited to 'clang/unittests')
-rw-r--r--clang/unittests/AST/ASTImporterTest.cpp10
-rw-r--r--clang/unittests/AST/CommentTextTest.cpp2
-rw-r--r--clang/unittests/Basic/CMakeLists.txt1
-rw-r--r--clang/unittests/Basic/FileManagerTest.cpp10
-rw-r--r--clang/unittests/Basic/VirtualFileSystemTest.cpp1592
-rw-r--r--clang/unittests/Driver/DistroTest.cpp24
-rw-r--r--clang/unittests/Driver/ToolChainTest.cpp14
-rw-r--r--clang/unittests/Format/FormatTest.cpp4
-rw-r--r--clang/unittests/Index/IndexTests.cpp2
-rw-r--r--clang/unittests/Lex/HeaderSearchTest.cpp4
-rw-r--r--clang/unittests/Lex/PPCallbacksTest.cpp42
-rw-r--r--clang/unittests/Rename/ClangRenameTest.h2
-rw-r--r--clang/unittests/Tooling/RefactoringTest.cpp16
-rw-r--r--clang/unittests/Tooling/RewriterTestContext.h16
-rw-r--r--clang/unittests/Tooling/ToolingTest.cpp24
15 files changed, 85 insertions, 1678 deletions
diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp
index 366ff7f0e08..ecfdeb08661 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -37,10 +37,10 @@ createVirtualFileIfNeeded(ASTUnit *ToAST, StringRef FileName,
std::unique_ptr<llvm::MemoryBuffer> &&Buffer) {
assert(ToAST);
ASTContext &ToCtx = ToAST->getASTContext();
- auto *OFS = static_cast<vfs::OverlayFileSystem *>(
+ auto *OFS = static_cast<llvm::vfs::OverlayFileSystem *>(
ToCtx.getSourceManager().getFileManager().getVirtualFileSystem().get());
- auto *MFS =
- static_cast<vfs::InMemoryFileSystem *>(OFS->overlays_begin()->get());
+ auto *MFS = static_cast<llvm::vfs::InMemoryFileSystem *>(
+ OFS->overlays_begin()->get());
MFS->addFile(FileName, 0, std::move(Buffer));
}
@@ -2482,7 +2482,7 @@ TEST_P(ImportFriendFunctions, ImportFriendChangesLookup) {
LookupRes = ToTU->noload_lookup(ToName);
EXPECT_EQ(LookupRes.size(), 1u);
EXPECT_EQ(DeclCounter<FunctionDecl>().match(ToTU, Pattern), 1u);
-
+
auto *ToFriendF = cast<FunctionDecl>(Import(FromFriendF, Lang_CXX));
LookupRes = ToTU->noload_lookup(ToName);
EXPECT_EQ(LookupRes.size(), 1u);
@@ -2758,7 +2758,7 @@ TEST_P(ASTImporterTestBase, ImportOfEquivalentRecord) {
ToR2 = Import(FromR, Lang_CXX);
}
-
+
EXPECT_EQ(ToR1, ToR2);
}
diff --git a/clang/unittests/AST/CommentTextTest.cpp b/clang/unittests/AST/CommentTextTest.cpp
index 04475f1c106..5fb779535f5 100644
--- a/clang/unittests/AST/CommentTextTest.cpp
+++ b/clang/unittests/AST/CommentTextTest.cpp
@@ -20,8 +20,8 @@
#include "clang/Basic/FileSystemOptions.h"
#include "clang/Basic/SourceLocation.h"
#include "clang/Basic/SourceManager.h"
-#include "clang/Basic/VirtualFileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/VirtualFileSystem.h"
#include <gtest/gtest.h>
namespace clang {
diff --git a/clang/unittests/Basic/CMakeLists.txt b/clang/unittests/Basic/CMakeLists.txt
index f5c96bb9b91..537f3ba5fcc 100644
--- a/clang/unittests/Basic/CMakeLists.txt
+++ b/clang/unittests/Basic/CMakeLists.txt
@@ -9,7 +9,6 @@ add_clang_unittest(BasicTests
FixedPointTest.cpp
MemoryBufferCacheTest.cpp
SourceManagerTest.cpp
- VirtualFileSystemTest.cpp
)
target_link_libraries(BasicTests
diff --git a/clang/unittests/Basic/FileManagerTest.cpp b/clang/unittests/Basic/FileManagerTest.cpp
index 52cb5b2f0d6..309de479499 100644
--- a/clang/unittests/Basic/FileManagerTest.cpp
+++ b/clang/unittests/Basic/FileManagerTest.cpp
@@ -10,9 +10,9 @@
#include "clang/Basic/FileManager.h"
#include "clang/Basic/FileSystemOptions.h"
#include "clang/Basic/FileSystemStatCache.h"
-#include "clang/Basic/VirtualFileSystem.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Path.h"
+#include "llvm/Support/VirtualFileSystem.h"
#include "gtest/gtest.h"
using namespace llvm;
@@ -60,8 +60,8 @@ public:
// Implement FileSystemStatCache::getStat().
LookupResult getStat(StringRef Path, FileData &Data, bool isFile,
- std::unique_ptr<vfs::File> *F,
- vfs::FileSystem &FS) override {
+ std::unique_ptr<llvm::vfs::File> *F,
+ llvm::vfs::FileSystem &FS) override {
#ifndef _WIN32
SmallString<128> NormalizedPath(Path);
llvm::sys::path::native(NormalizedPath);
@@ -305,8 +305,8 @@ TEST_F(FileManagerTest, makeAbsoluteUsesVFS) {
#endif
llvm::sys::path::append(CustomWorkingDir, "some", "weird", "path");
- auto FS =
- IntrusiveRefCntPtr<vfs::InMemoryFileSystem>(new vfs::InMemoryFileSystem);
+ auto FS = IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem>(
+ new llvm::vfs::InMemoryFileSystem);
// setCurrentworkingdirectory must finish without error.
ASSERT_TRUE(!FS->setCurrentWorkingDirectory(CustomWorkingDir));
diff --git a/clang/unittests/Basic/VirtualFileSystemTest.cpp b/clang/unittests/Basic/VirtualFileSystemTest.cpp
deleted file mode 100644
index 8bc8736a0c8..00000000000
--- a/clang/unittests/Basic/VirtualFileSystemTest.cpp
+++ /dev/null
@@ -1,1592 +0,0 @@
-//===- unittests/Basic/VirtualFileSystem.cpp ---------------- VFS tests ---===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "clang/Basic/VirtualFileSystem.h"
-#include "llvm/ADT/Triple.h"
-#include "llvm/Config/llvm-config.h"
-#include "llvm/Support/Errc.h"
-#include "llvm/Support/Host.h"
-#include "llvm/Support/MemoryBuffer.h"
-#include "llvm/Support/Path.h"
-#include "llvm/Support/SourceMgr.h"
-#include "gmock/gmock.h"
-#include "gtest/gtest.h"
-#include <map>
-#include <string>
-
-using namespace clang;
-using namespace llvm;
-using llvm::sys::fs::UniqueID;
-using testing::ElementsAre;
-using testing::Pair;
-using testing::UnorderedElementsAre;
-
-namespace {
-struct DummyFile : public vfs::File {
- vfs::Status S;
- explicit DummyFile(vfs::Status S) : S(S) {}
- llvm::ErrorOr<vfs::Status> status() override { return S; }
- llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
- getBuffer(const Twine &Name, int64_t FileSize, bool RequiresNullTerminator,
- bool IsVolatile) override {
- llvm_unreachable("unimplemented");
- }
- std::error_code close() override { return std::error_code(); }
-};
-
-class DummyFileSystem : public vfs::FileSystem {
- int FSID; // used to produce UniqueIDs
- int FileID; // used to produce UniqueIDs
- std::map<std::string, vfs::Status> FilesAndDirs;
-
- static int getNextFSID() {
- static int Count = 0;
- return Count++;
- }
-
-public:
- DummyFileSystem() : FSID(getNextFSID()), FileID(0) {}
-
- ErrorOr<vfs::Status> status(const Twine &Path) override {
- std::map<std::string, vfs::Status>::iterator I =
- FilesAndDirs.find(Path.str());
- if (I == FilesAndDirs.end())
- return make_error_code(llvm::errc::no_such_file_or_directory);
- return I->second;
- }
- ErrorOr<std::unique_ptr<vfs::File>>
- openFileForRead(const Twine &Path) override {
- auto S = status(Path);
- if (S)
- return std::unique_ptr<vfs::File>(new DummyFile{*S});
- return S.getError();
- }
- llvm::ErrorOr<std::string> getCurrentWorkingDirectory() const override {
- return std::string();
- }
- std::error_code setCurrentWorkingDirectory(const Twine &Path) override {
- return std::error_code();
- }
- // Map any symlink to "/symlink".
- std::error_code getRealPath(const Twine &Path,
- SmallVectorImpl<char> &Output) const override {
- auto I = FilesAndDirs.find(Path.str());
- if (I == FilesAndDirs.end())
- return make_error_code(llvm::errc::no_such_file_or_directory);
- if (I->second.isSymlink()) {
- Output.clear();
- Twine("/symlink").toVector(Output);
- return std::error_code();
- }
- Output.clear();
- Path.toVector(Output);
- return std::error_code();
- }
-
- struct DirIterImpl : public clang::vfs::detail::DirIterImpl {
- std::map<std::string, vfs::Status> &FilesAndDirs;
- std::map<std::string, vfs::Status>::iterator I;
- std::string Path;
- bool isInPath(StringRef S) {
- if (Path.size() < S.size() && S.find(Path) == 0) {
- auto LastSep = S.find_last_of('/');
- if (LastSep == Path.size() || LastSep == Path.size()-1)
- return true;
- }
- return false;
- }
- DirIterImpl(std::map<std::string, vfs::Status> &FilesAndDirs,
- const Twine &_Path)
- : FilesAndDirs(FilesAndDirs), I(FilesAndDirs.begin()),
- Path(_Path.str()) {
- for ( ; I != FilesAndDirs.end(); ++I) {
- if (isInPath(I->first)) {
- CurrentEntry =
- vfs::directory_entry(I->second.getName(), I->second.getType());
- break;
- }
- }
- }
- std::error_code increment() override {
- ++I;
- for ( ; I != FilesAndDirs.end(); ++I) {
- if (isInPath(I->first)) {
- CurrentEntry =
- vfs::directory_entry(I->second.getName(), I->second.getType());
- break;
- }
- }
- if (I == FilesAndDirs.end())
- CurrentEntry = vfs::directory_entry();
- return std::error_code();
- }
- };
-
- vfs::directory_iterator dir_begin(const Twine &Dir,
- std::error_code &EC) override {
- return vfs::directory_iterator(
- std::make_shared<DirIterImpl>(FilesAndDirs, Dir));
- }
-
- void addEntry(StringRef Path, const vfs::Status &Status) {
- FilesAndDirs[Path] = Status;
- }
-
- void addRegularFile(StringRef Path, sys::fs::perms Perms = sys::fs::all_all) {
- vfs::Status S(Path, UniqueID(FSID, FileID++),
- std::chrono::system_clock::now(), 0, 0, 1024,
- sys::fs::file_type::regular_file, Perms);
- addEntry(Path, S);
- }
-
- void addDirectory(StringRef Path, sys::fs::perms Perms = sys::fs::all_all) {
- vfs::Status S(Path, UniqueID(FSID, FileID++),
- std::chrono::system_clock::now(), 0, 0, 0,
- sys::fs::file_type::directory_file, Perms);
- addEntry(Path, S);
- }
-
- void addSymlink(StringRef Path) {
- vfs::Status S(Path, UniqueID(FSID, FileID++),
- std::chrono::system_clock::now(), 0, 0, 0,
- sys::fs::file_type::symlink_file, sys::fs::all_all);
- addEntry(Path, S);
- }
-};
-
-/// Replace back-slashes by front-slashes.
-std::string getPosixPath(std::string S) {
- SmallString<128> Result;
- llvm::sys::path::native(S, Result, llvm::sys::path::Style::posix);
- return Result.str();
-}
-} // end anonymous namespace
-
-TEST(VirtualFileSystemTest, StatusQueries) {
- IntrusiveRefCntPtr<DummyFileSystem> D(new DummyFileSystem());
- ErrorOr<vfs::Status> Status((std::error_code()));
-
- D->addRegularFile("/foo");
- Status = D->status("/foo");
- ASSERT_FALSE(Status.getError());
- EXPECT_TRUE(Status->isStatusKnown());
- EXPECT_FALSE(Status->isDirectory());
- EXPECT_TRUE(Status->isRegularFile());
- EXPECT_FALSE(Status->isSymlink());
- EXPECT_FALSE(Status->isOther());
- EXPECT_TRUE(Status->exists());
-
- D->addDirectory("/bar");
- Status = D->status("/bar");
- ASSERT_FALSE(Status.getError());
- EXPECT_TRUE(Status->isStatusKnown());
- EXPECT_TRUE(Status->isDirectory());
- EXPECT_FALSE(Status->isRegularFile());
- EXPECT_FALSE(Status->isSymlink());
- EXPECT_FALSE(Status->isOther());
- EXPECT_TRUE(Status->exists());
-
- D->addSymlink("/baz");
- Status = D->status("/baz");
- ASSERT_FALSE(Status.getError());
- EXPECT_TRUE(Status->isStatusKnown());
- EXPECT_FALSE(Status->isDirectory());
- EXPECT_FALSE(Status->isRegularFile());
- EXPECT_TRUE(Status->isSymlink());
- EXPECT_FALSE(Status->isOther());
- EXPECT_TRUE(Status->exists());
-
- EXPECT_TRUE(Status->equivalent(*Status));
- ErrorOr<vfs::Status> Status2 = D->status("/foo");
- ASSERT_FALSE(Status2.getError());
- EXPECT_FALSE(Status->equivalent(*Status2));
-}
-
-TEST(VirtualFileSystemTest, BaseOnlyOverlay) {
- IntrusiveRefCntPtr<DummyFileSystem> D(new DummyFileSystem());
- ErrorOr<vfs::Status> Status((std::error_code()));
- EXPECT_FALSE(Status = D->status("/foo"));
-
- IntrusiveRefCntPtr<vfs::OverlayFileSystem> O(new vfs::OverlayFileSystem(D));
- EXPECT_FALSE(Status = O->status("/foo"));
-
- D->addRegularFile("/foo");
- Status = D->status("/foo");
- EXPECT_FALSE(Status.getError());
-
- ErrorOr<vfs::Status> Status2((std::error_code()));
- Status2 = O->status("/foo");
- EXPECT_FALSE(Status2.getError());
- EXPECT_TRUE(Status->equivalent(*Status2));
-}
-
-TEST(VirtualFileSystemTest, GetRealPathInOverlay) {
- IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
- Lower->addRegularFile("/foo");
- Lower->addSymlink("/lower_link");
- IntrusiveRefCntPtr<DummyFileSystem> Upper(new DummyFileSystem());
-
- IntrusiveRefCntPtr<vfs::OverlayFileSystem> O(
- new vfs::OverlayFileSystem(Lower));
- O->pushOverlay(Upper);
-
- // Regular file.
- SmallString<16> RealPath;
- EXPECT_FALSE(O->getRealPath("/foo", RealPath));
- EXPECT_EQ(RealPath.str(), "/foo");
-
- // Expect no error getting real path for symlink in lower overlay.
- EXPECT_FALSE(O->getRealPath("/lower_link", RealPath));
- EXPECT_EQ(RealPath.str(), "/symlink");
-
- // Try a non-existing link.
- EXPECT_EQ(O->getRealPath("/upper_link", RealPath),
- errc::no_such_file_or_directory);
-
- // Add a new symlink in upper.
- Upper->addSymlink("/upper_link");
- EXPECT_FALSE(O->getRealPath("/upper_link", RealPath));
- EXPECT_EQ(RealPath.str(), "/symlink");
-}
-
-TEST(VirtualFileSystemTest, OverlayFiles) {
- IntrusiveRefCntPtr<DummyFileSystem> Base(new DummyFileSystem());
- IntrusiveRefCntPtr<DummyFileSystem> Middle(new DummyFileSystem());
- IntrusiveRefCntPtr<DummyFileSystem> Top(new DummyFileSystem());
- IntrusiveRefCntPtr<vfs::OverlayFileSystem> O(
- new vfs::OverlayFileSystem(Base));
- O->pushOverlay(Middle);
- O->pushOverlay(Top);
-
- ErrorOr<vfs::Status> Status1((std::error_code())),
- Status2((std::error_code())), Status3((std::error_code())),
- StatusB((std::error_code())), StatusM((std::error_code())),
- StatusT((std::error_code()));
-
- Base->addRegularFile("/foo");
- StatusB = Base->status("/foo");
- ASSERT_FALSE(StatusB.getError());
- Status1 = O->status("/foo");
- ASSERT_FALSE(Status1.getError());
- Middle->addRegularFile("/foo");
- StatusM = Middle->status("/foo");
- ASSERT_FALSE(StatusM.getError());
- Status2 = O->status("/foo");
- ASSERT_FALSE(Status2.getError());
- Top->addRegularFile("/foo");
- StatusT = Top->status("/foo");
- ASSERT_FALSE(StatusT.getError());
- Status3 = O->status("/foo");
- ASSERT_FALSE(Status3.getError());
-
- EXPECT_TRUE(Status1->equivalent(*StatusB));
- EXPECT_TRUE(Status2->equivalent(*StatusM));
- EXPECT_TRUE(Status3->equivalent(*StatusT));
-
- EXPECT_FALSE(Status1->equivalent(*Status2));
- EXPECT_FALSE(Status2->equivalent(*Status3));
- EXPECT_FALSE(Status1->equivalent(*Status3));
-}
-
-TEST(VirtualFileSystemTest, OverlayDirsNonMerged) {
- IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
- IntrusiveRefCntPtr<DummyFileSystem> Upper(new DummyFileSystem());
- IntrusiveRefCntPtr<vfs::OverlayFileSystem> O(
- new vfs::OverlayFileSystem(Lower));
- O->pushOverlay(Upper);
-
- Lower->addDirectory("/lower-only");
- Upper->addDirectory("/upper-only");
-
- // non-merged paths should be the same
- ErrorOr<vfs::Status> Status1 = Lower->status("/lower-only");
- ASSERT_FALSE(Status1.getError());
- ErrorOr<vfs::Status> Status2 = O->status("/lower-only");
- ASSERT_FALSE(Status2.getError());
- EXPECT_TRUE(Status1->equivalent(*Status2));
-
- Status1 = Upper->status("/upper-only");
- ASSERT_FALSE(Status1.getError());
- Status2 = O->status("/upper-only");
- ASSERT_FALSE(Status2.getError());
- EXPECT_TRUE(Status1->equivalent(*Status2));
-}
-
-TEST(VirtualFileSystemTest, MergedDirPermissions) {
- // merged directories get the permissions of the upper dir
- IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
- IntrusiveRefCntPtr<DummyFileSystem> Upper(new DummyFileSystem());
- IntrusiveRefCntPtr<vfs::OverlayFileSystem> O(
- new vfs::OverlayFileSystem(Lower));
- O->pushOverlay(Upper);
-
- ErrorOr<vfs::Status> Status((std::error_code()));
- Lower->addDirectory("/both", sys::fs::owner_read);
- Upper->addDirectory("/both", sys::fs::owner_all | sys::fs::group_read);
- Status = O->status("/both");
- ASSERT_FALSE(Status.getError());
- EXPECT_EQ(0740, Status->getPermissions());
-
- // permissions (as usual) are not recursively applied
- Lower->addRegularFile("/both/foo", sys::fs::owner_read);
- Upper->addRegularFile("/both/bar", sys::fs::owner_write);
- Status = O->status("/both/foo");
- ASSERT_FALSE( Status.getError());
- EXPECT_EQ(0400, Status->getPermissions());
- Status = O->status("/both/bar");
- ASSERT_FALSE(Status.getError());
- EXPECT_EQ(0200, Status->getPermissions());
-}
-
-namespace {
-struct ScopedDir {
- SmallString<128> Path;
- ScopedDir(const Twine &Name, bool Unique=false) {
- std::error_code EC;
- if (Unique) {
- EC = llvm::sys::fs::createUniqueDirectory(Name, Path);
- } else {
- Path = Name.str();
- EC = llvm::sys::fs::create_directory(Twine(Path));
- }
- if (EC)
- Path = "";
- EXPECT_FALSE(EC);
- }
- ~ScopedDir() {
- if (Path != "") {
- EXPECT_FALSE(llvm::sys::fs::remove(Path.str()));
- }
- }
- operator StringRef() { return Path.str(); }
-};
-
-struct ScopedLink {
- SmallString<128> Path;
- ScopedLink(const Twine &To, const Twine &From) {
- Path = From.str();
- std::error_code EC = sys::fs::create_link(To, From);
- if (EC)
- Path = "";
- EXPECT_FALSE(EC);
- }
- ~ScopedLink() {
- if (Path != "") {
- EXPECT_FALSE(llvm::sys::fs::remove(Path.str()));
- }
- }
- operator StringRef() { return Path.str(); }
-};
-} // end anonymous namespace
-
-TEST(VirtualFileSystemTest, BasicRealFSIteration) {
- ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/true);
- IntrusiveRefCntPtr<vfs::FileSystem> FS = vfs::getRealFileSystem();
-
- std::error_code EC;
- vfs::directory_iterator I = FS->dir_begin(Twine(TestDirectory), EC);
- ASSERT_FALSE(EC);
- EXPECT_EQ(vfs::directory_iterator(), I); // empty directory is empty
-
- ScopedDir _a(TestDirectory+"/a");
- ScopedDir _ab(TestDirectory+"/a/b");
- ScopedDir _c(TestDirectory+"/c");
- ScopedDir _cd(TestDirectory+"/c/d");
-
- I = FS->dir_begin(Twine(TestDirectory), EC);
- ASSERT_FALSE(EC);
- ASSERT_NE(vfs::directory_iterator(), I);
- // Check either a or c, since we can't rely on the iteration order.
- EXPECT_TRUE(I->path().endswith("a") || I->path().endswith("c"));
- I.increment(EC);
- ASSERT_FALSE(EC);
- ASSERT_NE(vfs::directory_iterator(), I);
- EXPECT_TRUE(I->path().endswith("a") || I->path().endswith("c"));
- I.increment(EC);
- EXPECT_EQ(vfs::directory_iterator(), I);
-}
-
-#ifdef LLVM_ON_UNIX
-TEST(VirtualFileSystemTest, BrokenSymlinkRealFSIteration) {
- ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/ true);
- IntrusiveRefCntPtr<vfs::FileSystem> FS = vfs::getRealFileSystem();
-
- ScopedLink _a("no_such_file", TestDirectory + "/a");
- ScopedDir _b(TestDirectory + "/b");
- ScopedLink _c("no_such_file", TestDirectory + "/c");
-
- // Should get no iteration error, but a stat error for the broken symlinks.
- std::map<std::string, std::error_code> StatResults;
- std::error_code EC;
- for (vfs::directory_iterator I = FS->dir_begin(Twine(TestDirectory), EC), E;
- I != E; I.increment(EC)) {
- EXPECT_FALSE(EC);
- StatResults[sys::path::filename(I->path())] =
- FS->status(I->path()).getError();
- }
- EXPECT_THAT(
- StatResults,
- ElementsAre(
- Pair("a", std::make_error_code(std::errc::no_such_file_or_directory)),
- Pair("b", std::error_code()),
- Pair("c",
- std::make_error_code(std::errc::no_such_file_or_directory))));
-}
-#endif
-
-TEST(VirtualFileSystemTest, BasicRealFSRecursiveIteration) {
- ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/true);
- IntrusiveRefCntPtr<vfs::FileSystem> FS = vfs::getRealFileSystem();
-
- std::error_code EC;
- auto I = vfs::recursive_directory_iterator(*FS, Twine(TestDirectory), EC);
- ASSERT_FALSE(EC);
- EXPECT_EQ(vfs::recursive_directory_iterator(), I); // empty directory is empty
-
- ScopedDir _a(TestDirectory+"/a");
- ScopedDir _ab(TestDirectory+"/a/b");
- ScopedDir _c(TestDirectory+"/c");
- ScopedDir _cd(TestDirectory+"/c/d");
-
- I = vfs::recursive_directory_iterator(*FS, Twine(TestDirectory), EC);
- ASSERT_FALSE(EC);
- ASSERT_NE(vfs::recursive_directory_iterator(), I);
-
- std::vector<std::string> Contents;
- for (auto E = vfs::recursive_directory_iterator(); !EC && I != E;
- I.increment(EC)) {
- Contents.push_back(I->path());
- }
-
- // Check contents, which may be in any order
- EXPECT_EQ(4U, Contents.size());
- int Counts[4] = { 0, 0, 0, 0 };
- for (const std::string &Name : Contents) {
- ASSERT_FALSE(Name.empty());
- int Index = Name[Name.size()-1] - 'a';
- ASSERT_TRUE(Index >= 0 && Index < 4);
- Counts[Index]++;
- }
- EXPECT_EQ(1, Counts[0]); // a
- EXPECT_EQ(1, Counts[1]); // b
- EXPECT_EQ(1, Counts[2]); // c
- EXPECT_EQ(1, Counts[3]); // d
-}
-
-#ifdef LLVM_ON_UNIX
-TEST(VirtualFileSystemTest, BrokenSymlinkRealFSRecursiveIteration) {
- ScopedDir TestDirectory("virtual-file-system-test", /*Unique*/ true);
- IntrusiveRefCntPtr<vfs::FileSystem> FS = vfs::getRealFileSystem();
-
- ScopedLink _a("no_such_file", TestDirectory + "/a");
- ScopedDir _b(TestDirectory + "/b");
- ScopedLink _ba("no_such_file", TestDirectory + "/b/a");
- ScopedDir _bb(TestDirectory + "/b/b");
- ScopedLink _bc("no_such_file", TestDirectory + "/b/c");
- ScopedLink _c("no_such_file", TestDirectory + "/c");
- ScopedDir _d(TestDirectory + "/d");
- ScopedDir _dd(TestDirectory + "/d/d");
- ScopedDir _ddd(TestDirectory + "/d/d/d");
- ScopedLink _e("no_such_file", TestDirectory + "/e");
-
- std::vector<std::string> VisitedBrokenSymlinks;
- std::vector<std::string> VisitedNonBrokenSymlinks;
- std::error_code EC;
- for (vfs::recursive_directory_iterator I(*FS, Twine(TestDirectory), EC), E;
- I != E; I.increment(EC)) {
- EXPECT_FALSE(EC);
- (FS->status(I->path()) ? VisitedNonBrokenSymlinks : VisitedBrokenSymlinks)
- .push_back(I->path());
- }
-
- // Check visited file names.
- EXPECT_THAT(VisitedBrokenSymlinks,
- UnorderedElementsAre(StringRef(_a), StringRef(_ba),
- StringRef(_bc), StringRef(_c),
- StringRef(_e)));
- EXPECT_THAT(VisitedNonBrokenSymlinks,
- UnorderedElementsAre(StringRef(_b), StringRef(_bb), StringRef(_d),
- StringRef(_dd), StringRef(_ddd)));
-}
-#endif
-
-template <typename DirIter>
-static void checkContents(DirIter I, ArrayRef<StringRef> ExpectedOut) {
- std::error_code EC;
- SmallVector<StringRef, 4> Expected(ExpectedOut.begin(), ExpectedOut.end());
- SmallVector<std::string, 4> InputToCheck;
-
- // Do not rely on iteration order to check for contents, sort both
- // content vectors before comparison.
- for (DirIter E; !EC && I != E; I.increment(EC))
- InputToCheck.push_back(I->path());
-
- llvm::sort(InputToCheck);
- llvm::sort(Expected);
- EXPECT_EQ(InputToCheck.size(), Expected.size());
-
- unsigned LastElt = std::min(InputToCheck.size(), Expected.size());
- for (unsigned Idx = 0; Idx != LastElt; ++Idx)
- EXPECT_EQ(StringRef(InputToCheck[Idx]), Expected[Idx]);
-}
-
-TEST(VirtualFileSystemTest, OverlayIteration) {
- IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
- IntrusiveRefCntPtr<DummyFileSystem> Upper(new DummyFileSystem());
- IntrusiveRefCntPtr<vfs::OverlayFileSystem> O(
- new vfs::OverlayFileSystem(Lower));
- O->pushOverlay(Upper);
-
- std::error_code EC;
- checkContents(O->dir_begin("/", EC), ArrayRef<StringRef>());
-
- Lower->addRegularFile("/file1");
- checkContents(O->dir_begin("/", EC), ArrayRef<StringRef>("/file1"));
-
- Upper->addRegularFile("/file2");
- checkContents(O->dir_begin("/", EC), {"/file2", "/file1"});
-
- Lower->addDirectory("/dir1");
- Lower->addRegularFile("/dir1/foo");
- Upper->addDirectory("/dir2");
- Upper->addRegularFile("/dir2/foo");
- checkContents(O->dir_begin("/dir2", EC), ArrayRef<StringRef>("/dir2/foo"));
- checkContents(O->dir_begin("/", EC), {"/dir2", "/file2", "/dir1", "/file1"});
-}
-
-TEST(VirtualFileSystemTest, OverlayRecursiveIteration) {
- IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
- IntrusiveRefCntPtr<DummyFileSystem> Middle(new DummyFileSystem());
- IntrusiveRefCntPtr<DummyFileSystem> Upper(new DummyFileSystem());
- IntrusiveRefCntPtr<vfs::OverlayFileSystem> O(
- new vfs::OverlayFileSystem(Lower));
- O->pushOverlay(Middle);
- O->pushOverlay(Upper);
-
- std::error_code EC;
- checkContents(vfs::recursive_directory_iterator(*O, "/", EC),
- ArrayRef<StringRef>());
-
- Lower->addRegularFile("/file1");
- checkContents(vfs::recursive_directory_iterator(*O, "/", EC),
- ArrayRef<StringRef>("/file1"));
-
- Upper->addDirectory("/dir");
- Upper->addRegularFile("/dir/file2");
- checkContents(vfs::recursive_directory_iterator(*O, "/", EC),
- {"/dir", "/dir/file2", "/file1"});
-
- Lower->addDirectory("/dir1");
- Lower->addRegularFile("/dir1/foo");
- Lower->addDirectory("/dir1/a");
- Lower->addRegularFile("/dir1/a/b");
- Middle->addDirectory("/a");
- Middle->addDirectory("/a/b");
- Middle->addDirectory("/a/b/c");
- Middle->addRegularFile("/a/b/c/d");
- Middle->addRegularFile("/hiddenByUp");
- Upper->addDirectory("/dir2");
- Upper->addRegularFile("/dir2/foo");
- Upper->addRegularFile("/hiddenByUp");
- checkContents(vfs::recursive_directory_iterator(*O, "/dir2", EC),
- ArrayRef<StringRef>("/dir2/foo"));
- checkContents(vfs::recursive_directory_iterator(*O, "/", EC),
- {"/dir", "/dir/file2", "/dir2", "/dir2/foo", "/hiddenByUp",
- "/a", "/a/b", "/a/b/c", "/a/b/c/d", "/dir1", "/dir1/a",
- "/dir1/a/b", "/dir1/foo", "/file1"});
-}
-
-TEST(VirtualFileSystemTest, ThreeLevelIteration) {
- IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
- IntrusiveRefCntPtr<DummyFileSystem> Middle(new DummyFileSystem());
- IntrusiveRefCntPtr<DummyFileSystem> Upper(new DummyFileSystem());
- IntrusiveRefCntPtr<vfs::OverlayFileSystem> O(
- new vfs::OverlayFileSystem(Lower));
- O->pushOverlay(Middle);
- O->pushOverlay(Upper);
-
- std::error_code EC;
- checkContents(O->dir_begin("/", EC), ArrayRef<StringRef>());
-
- Middle->addRegularFile("/file2");
- checkContents(O->dir_begin("/", EC), ArrayRef<StringRef>("/file2"));
-
- Lower->addRegularFile("/file1");
- Upper->addRegularFile("/file3");
- checkContents(O->dir_begin("/", EC), {"/file3", "/file2", "/file1"});
-}
-
-TEST(VirtualFileSystemTest, HiddenInIteration) {
- IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
- IntrusiveRefCntPtr<DummyFileSystem> Middle(new DummyFileSystem());
- IntrusiveRefCntPtr<DummyFileSystem> Upper(new DummyFileSystem());
- IntrusiveRefCntPtr<vfs::OverlayFileSystem> O(
- new vfs::OverlayFileSystem(Lower));
- O->pushOverlay(Middle);
- O->pushOverlay(Upper);
-
- std::error_code EC;
- Lower->addRegularFile("/onlyInLow");
- Lower->addDirectory("/hiddenByMid");
- Lower->addDirectory("/hiddenByUp");
- Middle->addRegularFile("/onlyInMid");
- Middle->addRegularFile("/hiddenByMid");
- Middle->addDirectory("/hiddenByUp");
- Upper->addRegularFile("/onlyInUp");
- Upper->addRegularFile("/hiddenByUp");
- checkContents(
- O->dir_begin("/", EC),
- {"/hiddenByUp", "/onlyInUp", "/hiddenByMid", "/onlyInMid", "/onlyInLow"});
-
- // Make sure we get the top-most entry
- {
- std::error_code EC;
- vfs::directory_iterator I = O->dir_begin("/", EC), E;
- for ( ; !EC && I != E; I.increment(EC))
- if (I->path() == "/hiddenByUp")
- break;
- ASSERT_NE(E, I);
- EXPECT_EQ(sys::fs::file_type::regular_file, I->type());
- }
- {
- std::error_code EC;
- vfs::directory_iterator I = O->dir_begin("/", EC), E;
- for ( ; !EC && I != E; I.increment(EC))
- if (I->path() == "/hiddenByMid")
- break;
- ASSERT_NE(E, I);
- EXPECT_EQ(sys::fs::file_type::regular_file, I->type());
- }
-}
-
-class InMemoryFileSystemTest : public ::testing::Test {
-protected:
- clang::vfs::InMemoryFileSystem FS;
- clang::vfs::InMemoryFileSystem NormalizedFS;
-
- InMemoryFileSystemTest()
- : FS(/*UseNormalizedPaths=*/false),
- NormalizedFS(/*UseNormalizedPaths=*/true) {}
-};
-
-MATCHER_P2(IsHardLinkTo, FS, Target, "") {
- StringRef From = arg;
- StringRef To = Target;
- auto OpenedFrom = FS->openFileForRead(From);
- auto OpenedTo = FS->openFileForRead(To);
- return !OpenedFrom.getError() && !OpenedTo.getError() &&
- (*OpenedFrom)->status()->getUniqueID() ==
- (*OpenedTo)->status()->getUniqueID();
-}
-
-TEST_F(InMemoryFileSystemTest, IsEmpty) {
- auto Stat = FS.status("/a");
- ASSERT_EQ(Stat.getError(),errc::no_such_file_or_directory) << FS.toString();
- Stat = FS.status("/");
- ASSERT_EQ(Stat.getError(), errc::no_such_file_or_directory) << FS.toString();
-}
-
-TEST_F(InMemoryFileSystemTest, WindowsPath) {
- FS.addFile("c:/windows/system128/foo.cpp", 0, MemoryBuffer::getMemBuffer(""));
- auto Stat = FS.status("c:");
-#if !defined(_WIN32)
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << FS.toString();
-#endif
- Stat = FS.status("c:/windows/system128/foo.cpp");
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << FS.toString();
- FS.addFile("d:/windows/foo.cpp", 0, MemoryBuffer::getMemBuffer(""));
- Stat = FS.status("d:/windows/foo.cpp");
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << FS.toString();
-}
-
-TEST_F(InMemoryFileSystemTest, OverlayFile) {
- FS.addFile("/a", 0, MemoryBuffer::getMemBuffer("a"));
- NormalizedFS.addFile("/a", 0, MemoryBuffer::getMemBuffer("a"));
- auto Stat = FS.status("/");
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << FS.toString();
- Stat = FS.status("/.");
- ASSERT_FALSE(Stat);
- Stat = NormalizedFS.status("/.");
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << FS.toString();
- Stat = FS.status("/a");
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
- ASSERT_EQ("/a", Stat->getName());
-}
-
-TEST_F(InMemoryFileSystemTest, OverlayFileNoOwn) {
- auto Buf = MemoryBuffer::getMemBuffer("a");
- FS.addFileNoOwn("/a", 0, Buf.get());
- auto Stat = FS.status("/a");
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
- ASSERT_EQ("/a", Stat->getName());
-}
-
-TEST_F(InMemoryFileSystemTest, OpenFileForRead) {
- FS.addFile("/a", 0, MemoryBuffer::getMemBuffer("a"));
- FS.addFile("././c", 0, MemoryBuffer::getMemBuffer("c"));
- FS.addFile("./d/../d", 0, MemoryBuffer::getMemBuffer("d"));
- NormalizedFS.addFile("/a", 0, MemoryBuffer::getMemBuffer("a"));
- NormalizedFS.addFile("././c", 0, MemoryBuffer::getMemBuffer("c"));
- NormalizedFS.addFile("./d/../d", 0, MemoryBuffer::getMemBuffer("d"));
- auto File = FS.openFileForRead("/a");
- ASSERT_EQ("a", (*(*File)->getBuffer("ignored"))->getBuffer());
- File = FS.openFileForRead("/a"); // Open again.
- ASSERT_EQ("a", (*(*File)->getBuffer("ignored"))->getBuffer());
- File = NormalizedFS.openFileForRead("/././a"); // Open again.
- ASSERT_EQ("a", (*(*File)->getBuffer("ignored"))->getBuffer());
- File = FS.openFileForRead("/");
- ASSERT_EQ(File.getError(), errc::invalid_argument) << FS.toString();
- File = FS.openFileForRead("/b");
- ASSERT_EQ(File.getError(), errc::no_such_file_or_directory) << FS.toString();
- File = FS.openFileForRead("./c");
- ASSERT_FALSE(File);
- File = FS.openFileForRead("e/../d");
- ASSERT_FALSE(File);
- File = NormalizedFS.openFileForRead("./c");
- ASSERT_EQ("c", (*(*File)->getBuffer("ignored"))->getBuffer());
- File = NormalizedFS.openFileForRead("e/../d");
- ASSERT_EQ("d", (*(*File)->getBuffer("ignored"))->getBuffer());
-}
-
-TEST_F(InMemoryFileSystemTest, DuplicatedFile) {
- ASSERT_TRUE(FS.addFile("/a", 0, MemoryBuffer::getMemBuffer("a")));
- ASSERT_FALSE(FS.addFile("/a/b", 0, MemoryBuffer::getMemBuffer("a")));
- ASSERT_TRUE(FS.addFile("/a", 0, MemoryBuffer::getMemBuffer("a")));
- ASSERT_FALSE(FS.addFile("/a", 0, MemoryBuffer::getMemBuffer("b")));
-}
-
-TEST_F(InMemoryFileSystemTest, DirectoryIteration) {
- FS.addFile("/a", 0, MemoryBuffer::getMemBuffer(""));
- FS.addFile("/b/c", 0, MemoryBuffer::getMemBuffer(""));
-
- std::error_code EC;
- vfs::directory_iterator I = FS.dir_begin("/", EC);
- ASSERT_FALSE(EC);
- ASSERT_EQ("/a", I->path());
- I.increment(EC);
- ASSERT_FALSE(EC);
- ASSERT_EQ("/b", I->path());
- I.increment(EC);
- ASSERT_FALSE(EC);
- ASSERT_EQ(vfs::directory_iterator(), I);
-
- I = FS.dir_begin("/b", EC);
- ASSERT_FALSE(EC);
- // When on Windows, we end up with "/b\\c" as the name. Convert to Posix
- // path for the sake of the comparison.
- ASSERT_EQ("/b/c", getPosixPath(I->path()));
- I.increment(EC);
- ASSERT_FALSE(EC);
- ASSERT_EQ(vfs::directory_iterator(), I);
-}
-
-TEST_F(InMemoryFileSystemTest, WorkingDirectory) {
- FS.setCurrentWorkingDirectory("/b");
- FS.addFile("c", 0, MemoryBuffer::getMemBuffer(""));
-
- auto Stat = FS.status("/b/c");
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
- ASSERT_EQ("/b/c", Stat->getName());
- ASSERT_EQ("/b", *FS.getCurrentWorkingDirectory());
-
- Stat = FS.status("c");
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
-
- NormalizedFS.setCurrentWorkingDirectory("/b/c");
- NormalizedFS.setCurrentWorkingDirectory(".");
- ASSERT_EQ("/b/c",
- getPosixPath(NormalizedFS.getCurrentWorkingDirectory().get()));
- NormalizedFS.setCurrentWorkingDirectory("..");
- ASSERT_EQ("/b",
- getPosixPath(NormalizedFS.getCurrentWorkingDirectory().get()));
-}
-
-#if !defined(_WIN32)
-TEST_F(InMemoryFileSystemTest, GetRealPath) {
- SmallString<16> Path;
- EXPECT_EQ(FS.getRealPath("b", Path), errc::operation_not_permitted);
-
- auto GetRealPath = [this](StringRef P) {
- SmallString<16> Output;
- auto EC = FS.getRealPath(P, Output);
- EXPECT_FALSE(EC);
- return Output.str().str();
- };
-
- FS.setCurrentWorkingDirectory("a");
- EXPECT_EQ(GetRealPath("b"), "a/b");
- EXPECT_EQ(GetRealPath("../b"), "b");
- EXPECT_EQ(GetRealPath("b/./c"), "a/b/c");
-
- FS.setCurrentWorkingDirectory("/a");
- EXPECT_EQ(GetRealPath("b"), "/a/b");
- EXPECT_EQ(GetRealPath("../b"), "/b");
- EXPECT_EQ(GetRealPath("b/./c"), "/a/b/c");
-}
-#endif // _WIN32
-
-TEST_F(InMemoryFileSystemTest, AddFileWithUser) {
- FS.addFile("/a/b/c", 0, MemoryBuffer::getMemBuffer("abc"), 0xFEEDFACE);
- auto Stat = FS.status("/a");
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
- ASSERT_TRUE(Stat->isDirectory());
- ASSERT_EQ(0xFEEDFACE, Stat->getUser());
- Stat = FS.status("/a/b");
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
- ASSERT_TRUE(Stat->isDirectory());
- ASSERT_EQ(0xFEEDFACE, Stat->getUser());
- Stat = FS.status("/a/b/c");
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
- ASSERT_TRUE(Stat->isRegularFile());
- ASSERT_EQ(sys::fs::perms::all_all, Stat->getPermissions());
- ASSERT_EQ(0xFEEDFACE, Stat->getUser());
-}
-
-TEST_F(InMemoryFileSystemTest, AddFileWithGroup) {
- FS.addFile("/a/b/c", 0, MemoryBuffer::getMemBuffer("abc"), None, 0xDABBAD00);
- auto Stat = FS.status("/a");
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
- ASSERT_TRUE(Stat->isDirectory());
- ASSERT_EQ(0xDABBAD00, Stat->getGroup());
- Stat = FS.status("/a/b");
- ASSERT_TRUE(Stat->isDirectory());
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
- ASSERT_EQ(0xDABBAD00, Stat->getGroup());
- Stat = FS.status("/a/b/c");
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
- ASSERT_TRUE(Stat->isRegularFile());
- ASSERT_EQ(sys::fs::perms::all_all, Stat->getPermissions());
- ASSERT_EQ(0xDABBAD00, Stat->getGroup());
-}
-
-TEST_F(InMemoryFileSystemTest, AddFileWithFileType) {
- FS.addFile("/a/b/c", 0, MemoryBuffer::getMemBuffer("abc"), None, None,
- sys::fs::file_type::socket_file);
- auto Stat = FS.status("/a");
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
- ASSERT_TRUE(Stat->isDirectory());
- Stat = FS.status("/a/b");
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
- ASSERT_TRUE(Stat->isDirectory());
- Stat = FS.status("/a/b/c");
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
- ASSERT_EQ(sys::fs::file_type::socket_file, Stat->getType());
- ASSERT_EQ(sys::fs::perms::all_all, Stat->getPermissions());
-}
-
-TEST_F(InMemoryFileSystemTest, AddFileWithPerms) {
- FS.addFile("/a/b/c", 0, MemoryBuffer::getMemBuffer("abc"), None, None,
- None, sys::fs::perms::owner_read | sys::fs::perms::owner_write);
- auto Stat = FS.status("/a");
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
- ASSERT_TRUE(Stat->isDirectory());
- ASSERT_EQ(sys::fs::perms::owner_read | sys::fs::perms::owner_write |
- sys::fs::perms::owner_exe, Stat->getPermissions());
- Stat = FS.status("/a/b");
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
- ASSERT_TRUE(Stat->isDirectory());
- ASSERT_EQ(sys::fs::perms::owner_read | sys::fs::perms::owner_write |
- sys::fs::perms::owner_exe, Stat->getPermissions());
- Stat = FS.status("/a/b/c");
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
- ASSERT_TRUE(Stat->isRegularFile());
- ASSERT_EQ(sys::fs::perms::owner_read | sys::fs::perms::owner_write,
- Stat->getPermissions());
-}
-
-TEST_F(InMemoryFileSystemTest, AddDirectoryThenAddChild) {
- FS.addFile("/a", 0, MemoryBuffer::getMemBuffer(""), /*User=*/None,
- /*Group=*/None, sys::fs::file_type::directory_file);
- FS.addFile("/a/b", 0, MemoryBuffer::getMemBuffer("abc"), /*User=*/None,
- /*Group=*/None, sys::fs::file_type::regular_file);
- auto Stat = FS.status("/a");
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
- ASSERT_TRUE(Stat->isDirectory());
- Stat = FS.status("/a/b");
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n" << FS.toString();
- ASSERT_TRUE(Stat->isRegularFile());
-}
-
-// Test that the name returned by status() is in the same form as the path that
-// was requested (to match the behavior of RealFileSystem).
-TEST_F(InMemoryFileSystemTest, StatusName) {
- NormalizedFS.addFile("/a/b/c", 0, MemoryBuffer::getMemBuffer("abc"),
- /*User=*/None,
- /*Group=*/None, sys::fs::file_type::regular_file);
- NormalizedFS.setCurrentWorkingDirectory("/a/b");
-
- // Access using InMemoryFileSystem::status.
- auto Stat = NormalizedFS.status("../b/c");
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n"
- << NormalizedFS.toString();
- ASSERT_TRUE(Stat->isRegularFile());
- ASSERT_EQ("../b/c", Stat->getName());
-
- // Access using InMemoryFileAdaptor::status.
- auto File = NormalizedFS.openFileForRead("../b/c");
- ASSERT_FALSE(File.getError()) << File.getError() << "\n"
- << NormalizedFS.toString();
- Stat = (*File)->status();
- ASSERT_FALSE(Stat.getError()) << Stat.getError() << "\n"
- << NormalizedFS.toString();
- ASSERT_TRUE(Stat->isRegularFile());
- ASSERT_EQ("../b/c", Stat->getName());
-
- // Access using a directory iterator.
- std::error_code EC;
- clang::vfs::directory_iterator It = NormalizedFS.dir_begin("../b", EC);
- // When on Windows, we end up with "../b\\c" as the name. Convert to Posix
- // path for the sake of the comparison.
- ASSERT_EQ("../b/c", getPosixPath(It->path()));
-}
-
-TEST_F(InMemoryFileSystemTest, AddHardLinkToFile) {
- StringRef FromLink = "/path/to/FROM/link";
- StringRef Target = "/path/to/TO/file";
- FS.addFile(Target, 0, MemoryBuffer::getMemBuffer("content of target"));
- EXPECT_TRUE(FS.addHardLink(FromLink, Target));
- EXPECT_THAT(FromLink, IsHardLinkTo(&FS, Target));
- EXPECT_TRUE(FS.status(FromLink)->getSize() == FS.status(Target)->getSize());
- EXPECT_TRUE(FS.getBufferForFile(FromLink)->get()->getBuffer() ==
- FS.getBufferForFile(Target)->get()->getBuffer());
-}
-
-TEST_F(InMemoryFileSystemTest, AddHardLinkInChainPattern) {
- StringRef Link0 = "/path/to/0/link";
- StringRef Link1 = "/path/to/1/link";
- StringRef Link2 = "/path/to/2/link";
- StringRef Target = "/path/to/target";
- FS.addFile(Target, 0, MemoryBuffer::getMemBuffer("content of target file"));
- EXPECT_TRUE(FS.addHardLink(Link2, Target));
- EXPECT_TRUE(FS.addHardLink(Link1, Link2));
- EXPECT_TRUE(FS.addHardLink(Link0, Link1));
- EXPECT_THAT(Link0, IsHardLinkTo(&FS, Target));
- EXPECT_THAT(Link1, IsHardLinkTo(&FS, Target));
- EXPECT_THAT(Link2, IsHardLinkTo(&FS, Target));
-}
-
-TEST_F(InMemoryFileSystemTest, AddHardLinkToAFileThatWasNotAddedBefore) {
- EXPECT_FALSE(FS.addHardLink("/path/to/link", "/path/to/target"));
-}
-
-TEST_F(InMemoryFileSystemTest, AddHardLinkFromAFileThatWasAddedBefore) {
- StringRef Link = "/path/to/link";
- StringRef Target = "/path/to/target";
- FS.addFile(Target, 0, MemoryBuffer::getMemBuffer("content of target"));
- FS.addFile(Link, 0, MemoryBuffer::getMemBuffer("content of link"));
- EXPECT_FALSE(FS.addHardLink(Link, Target));
-}
-
-TEST_F(InMemoryFileSystemTest, AddSameHardLinkMoreThanOnce) {
- StringRef Link = "/path/to/link";
- StringRef Target = "/path/to/target";
- FS.addFile(Target, 0, MemoryBuffer::getMemBuffer("content of target"));
- EXPECT_TRUE(FS.addHardLink(Link, Target));
- EXPECT_FALSE(FS.addHardLink(Link, Target));
-}
-
-TEST_F(InMemoryFileSystemTest, AddFileInPlaceOfAHardLinkWithSameContent) {
- StringRef Link = "/path/to/link";
- StringRef Target = "/path/to/target";
- StringRef Content = "content of target";
- EXPECT_TRUE(FS.addFile(Target, 0, MemoryBuffer::getMemBuffer(Content)));
- EXPECT_TRUE(FS.addHardLink(Link, Target));
- EXPECT_TRUE(FS.addFile(Link, 0, MemoryBuffer::getMemBuffer(Content)));
-}
-
-TEST_F(InMemoryFileSystemTest, AddFileInPlaceOfAHardLinkWithDifferentContent) {
- StringRef Link = "/path/to/link";
- StringRef Target = "/path/to/target";
- StringRef Content = "content of target";
- StringRef LinkContent = "different content of link";
- EXPECT_TRUE(FS.addFile(Target, 0, MemoryBuffer::getMemBuffer(Content)));
- EXPECT_TRUE(FS.addHardLink(Link, Target));
- EXPECT_FALSE(FS.addFile(Link, 0, MemoryBuffer::getMemBuffer(LinkContent)));
-}
-
-TEST_F(InMemoryFileSystemTest, AddHardLinkToADirectory) {
- StringRef Dir = "path/to/dummy/dir";
- StringRef Link = "/path/to/link";
- StringRef File = "path/to/dummy/dir/target";
- StringRef Content = "content of target";
- EXPECT_TRUE(FS.addFile(File, 0, MemoryBuffer::getMemBuffer(Content)));
- EXPECT_FALSE(FS.addHardLink(Link, Dir));
-}
-
-TEST_F(InMemoryFileSystemTest, AddHardLinkFromADirectory) {
- StringRef Dir = "path/to/dummy/dir";
- StringRef Target = "path/to/dummy/dir/target";
- StringRef Content = "content of target";
- EXPECT_TRUE(FS.addFile(Target, 0, MemoryBuffer::getMemBuffer(Content)));
- EXPECT_FALSE(FS.addHardLink(Dir, Target));
-}
-
-TEST_F(InMemoryFileSystemTest, AddHardLinkUnderAFile) {
- StringRef CommonContent = "content string";
- FS.addFile("/a/b", 0, MemoryBuffer::getMemBuffer(CommonContent));
- FS.addFile("/c/d", 0, MemoryBuffer::getMemBuffer(CommonContent));
- EXPECT_FALSE(FS.addHardLink("/c/d/e", "/a/b"));
-}
-
-TEST_F(InMemoryFileSystemTest, RecursiveIterationWithHardLink) {
- std::error_code EC;
- FS.addFile("/a/b", 0, MemoryBuffer::getMemBuffer("content string"));
- EXPECT_TRUE(FS.addHardLink("/c/d", "/a/b"));
- auto I = vfs::recursive_directory_iterator(FS, "/", EC);
- ASSERT_FALSE(EC);
- std::vector<std::string> Nodes;
- for (auto E = vfs::recursive_directory_iterator(); !EC && I != E;
- I.increment(EC)) {
- Nodes.push_back(getPosixPath(I->path()));
- }
- EXPECT_THAT(Nodes, testing::UnorderedElementsAre("/a", "/a/b", "/c", "/c/d"));
-}
-
-// NOTE: in the tests below, we use '//root/' as our root directory, since it is
-// a legal *absolute* path on Windows as well as *nix.
-class VFSFromYAMLTest : public ::testing::Test {
-public:
- int NumDiagnostics;
-
- void SetUp() override { NumDiagnostics = 0; }
-
- static void CountingDiagHandler(const SMDiagnostic &, void *Context) {
- VFSFromYAMLTest *Test = static_cast<VFSFromYAMLTest *>(Context);
- ++Test->NumDiagnostics;
- }
-
- IntrusiveRefCntPtr<vfs::FileSystem>
- getFromYAMLRawString(StringRef Content,
- IntrusiveRefCntPtr<vfs::FileSystem> ExternalFS) {
- std::unique_ptr<MemoryBuffer> Buffer = MemoryBuffer::getMemBuffer(Content);
- return getVFSFromYAML(std::move(Buffer), CountingDiagHandler, "", this,
- ExternalFS);
- }
-
- IntrusiveRefCntPtr<vfs::FileSystem> getFromYAMLString(
- StringRef Content,
- IntrusiveRefCntPtr<vfs::FileSystem> ExternalFS = new DummyFileSystem()) {
- std::string VersionPlusContent("{\n 'version':0,\n");
- VersionPlusContent += Content.slice(Content.find('{') + 1, StringRef::npos);
- return getFromYAMLRawString(VersionPlusContent, ExternalFS);
- }
-
- // This is intended as a "XFAIL" for windows hosts.
- bool supportsSameDirMultipleYAMLEntries() {
- Triple Host(Triple::normalize(sys::getProcessTriple()));
- return !Host.isOSWindows();
- }
-};
-
-TEST_F(VFSFromYAMLTest, BasicVFSFromYAML) {
- IntrusiveRefCntPtr<vfs::FileSystem> FS;
- FS = getFromYAMLString("");
- EXPECT_EQ(nullptr, FS.get());
- FS = getFromYAMLString("[]");
- EXPECT_EQ(nullptr, FS.get());
- FS = getFromYAMLString("'string'");
- EXPECT_EQ(nullptr, FS.get());
- EXPECT_EQ(3, NumDiagnostics);
-}
-
-TEST_F(VFSFromYAMLTest, MappedFiles) {
- IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
- Lower->addRegularFile("//root/foo/bar/a");
- IntrusiveRefCntPtr<vfs::FileSystem> FS =
- getFromYAMLString("{ 'roots': [\n"
- "{\n"
- " 'type': 'directory',\n"
- " 'name': '//root/',\n"
- " 'contents': [ {\n"
- " 'type': 'file',\n"
- " 'name': 'file1',\n"
- " 'external-contents': '//root/foo/bar/a'\n"
- " },\n"
- " {\n"
- " 'type': 'file',\n"
- " 'name': 'file2',\n"
- " 'external-contents': '//root/foo/b'\n"
- " }\n"
- " ]\n"
- "}\n"
- "]\n"
- "}",
- Lower);
- ASSERT_TRUE(FS.get() != nullptr);
-
- IntrusiveRefCntPtr<vfs::OverlayFileSystem> O(
- new vfs::OverlayFileSystem(Lower));
- O->pushOverlay(FS);
-
- // file
- ErrorOr<vfs::Status> S = O->status("//root/file1");
- ASSERT_FALSE(S.getError());
- EXPECT_EQ("//root/foo/bar/a", S->getName());
- EXPECT_TRUE(S->IsVFSMapped);
-
- ErrorOr<vfs::Status> SLower = O->status("//root/foo/bar/a");
- EXPECT_EQ("//root/foo/bar/a", SLower->getName());
- EXPECT_TRUE(S->equivalent(*SLower));
- EXPECT_FALSE(SLower->IsVFSMapped);
-
- // file after opening
- auto OpenedF = O->openFileForRead("//root/file1");
- ASSERT_FALSE(OpenedF.getError());
- auto OpenedS = (*OpenedF)->status();
- ASSERT_FALSE(OpenedS.getError());
- EXPECT_EQ("//root/foo/bar/a", OpenedS->getName());
- EXPECT_TRUE(OpenedS->IsVFSMapped);
-
- // directory
- S = O->status("//root/");
- ASSERT_FALSE(S.getError());
- EXPECT_TRUE(S->isDirectory());
- EXPECT_TRUE(S->equivalent(*O->status("//root/"))); // non-volatile UniqueID
-
- // broken mapping
- EXPECT_EQ(O->status("//root/file2").getError(),
- llvm::errc::no_such_file_or_directory);
- EXPECT_EQ(0, NumDiagnostics);
-}
-
-TEST_F(VFSFromYAMLTest, CaseInsensitive) {
- IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
- Lower->addRegularFile("//root/foo/bar/a");
- IntrusiveRefCntPtr<vfs::FileSystem> FS =
- getFromYAMLString("{ 'case-sensitive': 'false',\n"
- " 'roots': [\n"
- "{\n"
- " 'type': 'directory',\n"
- " 'name': '//root/',\n"
- " 'contents': [ {\n"
- " 'type': 'file',\n"
- " 'name': 'XX',\n"
- " 'external-contents': '//root/foo/bar/a'\n"
- " }\n"
- " ]\n"
- "}]}",
- Lower);
- ASSERT_TRUE(FS.get() != nullptr);
-
- IntrusiveRefCntPtr<vfs::OverlayFileSystem> O(
- new vfs::OverlayFileSystem(Lower));
- O->pushOverlay(FS);
-
- ErrorOr<vfs::Status> S = O->status("//root/XX");
- ASSERT_FALSE(S.getError());
-
- ErrorOr<vfs::Status> SS = O->status("//root/xx");
- ASSERT_FALSE(SS.getError());
- EXPECT_TRUE(S->equivalent(*SS));
- SS = O->status("//root/xX");
- EXPECT_TRUE(S->equivalent(*SS));
- SS = O->status("//root/Xx");
- EXPECT_TRUE(S->equivalent(*SS));
- EXPECT_EQ(0, NumDiagnostics);
-}
-
-TEST_F(VFSFromYAMLTest, CaseSensitive) {
- IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
- Lower->addRegularFile("//root/foo/bar/a");
- IntrusiveRefCntPtr<vfs::FileSystem> FS =
- getFromYAMLString("{ 'case-sensitive': 'true',\n"
- " 'roots': [\n"
- "{\n"
- " 'type': 'directory',\n"
- " 'name': '//root/',\n"
- " 'contents': [ {\n"
- " 'type': 'file',\n"
- " 'name': 'XX',\n"
- " 'external-contents': '//root/foo/bar/a'\n"
- " }\n"
- " ]\n"
- "}]}",
- Lower);
- ASSERT_TRUE(FS.get() != nullptr);
-
- IntrusiveRefCntPtr<vfs::OverlayFileSystem> O(
- new vfs::OverlayFileSystem(Lower));
- O->pushOverlay(FS);
-
- ErrorOr<vfs::Status> SS = O->status("//root/xx");
- EXPECT_EQ(SS.getError(), llvm::errc::no_such_file_or_directory);
- SS = O->status("//root/xX");
- EXPECT_EQ(SS.getError(), llvm::errc::no_such_file_or_directory);
- SS = O->status("//root/Xx");
- EXPECT_EQ(SS.getError(), llvm::errc::no_such_file_or_directory);
- EXPECT_EQ(0, NumDiagnostics);
-}
-
-TEST_F(VFSFromYAMLTest, IllegalVFSFile) {
- IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
-
- // invalid YAML at top-level
- IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLString("{]", Lower);
- EXPECT_EQ(nullptr, FS.get());
- // invalid YAML in roots
- FS = getFromYAMLString("{ 'roots':[}", Lower);
- // invalid YAML in directory
- FS = getFromYAMLString(
- "{ 'roots':[ { 'name': 'foo', 'type': 'directory', 'contents': [}",
- Lower);
- EXPECT_EQ(nullptr, FS.get());
-
- // invalid configuration
- FS = getFromYAMLString("{ 'knobular': 'true', 'roots':[] }", Lower);
- EXPECT_EQ(nullptr, FS.get());
- FS = getFromYAMLString("{ 'case-sensitive': 'maybe', 'roots':[] }", Lower);
- EXPECT_EQ(nullptr, FS.get());
-
- // invalid roots
- FS = getFromYAMLString("{ 'roots':'' }", Lower);
- EXPECT_EQ(nullptr, FS.get());
- FS = getFromYAMLString("{ 'roots':{} }", Lower);
- EXPECT_EQ(nullptr, FS.get());
-
- // invalid entries
- FS = getFromYAMLString(
- "{ 'roots':[ { 'type': 'other', 'name': 'me', 'contents': '' }", Lower);
- EXPECT_EQ(nullptr, FS.get());
- FS = getFromYAMLString("{ 'roots':[ { 'type': 'file', 'name': [], "
- "'external-contents': 'other' }",
- Lower);
- EXPECT_EQ(nullptr, FS.get());
- FS = getFromYAMLString(
- "{ 'roots':[ { 'type': 'file', 'name': 'me', 'external-contents': [] }",
- Lower);
- EXPECT_EQ(nullptr, FS.get());
- FS = getFromYAMLString(
- "{ 'roots':[ { 'type': 'file', 'name': 'me', 'external-contents': {} }",
- Lower);
- EXPECT_EQ(nullptr, FS.get());
- FS = getFromYAMLString(
- "{ 'roots':[ { 'type': 'directory', 'name': 'me', 'contents': {} }",
- Lower);
- EXPECT_EQ(nullptr, FS.get());
- FS = getFromYAMLString(
- "{ 'roots':[ { 'type': 'directory', 'name': 'me', 'contents': '' }",
- Lower);
- EXPECT_EQ(nullptr, FS.get());
- FS = getFromYAMLString(
- "{ 'roots':[ { 'thingy': 'directory', 'name': 'me', 'contents': [] }",
- Lower);
- EXPECT_EQ(nullptr, FS.get());
-
- // missing mandatory fields
- FS = getFromYAMLString("{ 'roots':[ { 'type': 'file', 'name': 'me' }", Lower);
- EXPECT_EQ(nullptr, FS.get());
- FS = getFromYAMLString(
- "{ 'roots':[ { 'type': 'file', 'external-contents': 'other' }", Lower);
- EXPECT_EQ(nullptr, FS.get());
- FS = getFromYAMLString("{ 'roots':[ { 'name': 'me', 'contents': [] }", Lower);
- EXPECT_EQ(nullptr, FS.get());
-
- // duplicate keys
- FS = getFromYAMLString("{ 'roots':[], 'roots':[] }", Lower);
- EXPECT_EQ(nullptr, FS.get());
- FS = getFromYAMLString(
- "{ 'case-sensitive':'true', 'case-sensitive':'true', 'roots':[] }",
- Lower);
- EXPECT_EQ(nullptr, FS.get());
- FS =
- getFromYAMLString("{ 'roots':[{'name':'me', 'name':'you', 'type':'file', "
- "'external-contents':'blah' } ] }",
- Lower);
- EXPECT_EQ(nullptr, FS.get());
-
- // missing version
- FS = getFromYAMLRawString("{ 'roots':[] }", Lower);
- EXPECT_EQ(nullptr, FS.get());
-
- // bad version number
- FS = getFromYAMLRawString("{ 'version':'foo', 'roots':[] }", Lower);
- EXPECT_EQ(nullptr, FS.get());
- FS = getFromYAMLRawString("{ 'version':-1, 'roots':[] }", Lower);
- EXPECT_EQ(nullptr, FS.get());
- FS = getFromYAMLRawString("{ 'version':100000, 'roots':[] }", Lower);
- EXPECT_EQ(nullptr, FS.get());
- EXPECT_EQ(24, NumDiagnostics);
-}
-
-TEST_F(VFSFromYAMLTest, UseExternalName) {
- IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
- Lower->addRegularFile("//root/external/file");
-
- IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLString(
- "{ 'roots': [\n"
- " { 'type': 'file', 'name': '//root/A',\n"
- " 'external-contents': '//root/external/file'\n"
- " },\n"
- " { 'type': 'file', 'name': '//root/B',\n"
- " 'use-external-name': true,\n"
- " 'external-contents': '//root/external/file'\n"
- " },\n"
- " { 'type': 'file', 'name': '//root/C',\n"
- " 'use-external-name': false,\n"
- " 'external-contents': '//root/external/file'\n"
- " }\n"
- "] }", Lower);
- ASSERT_TRUE(nullptr != FS.get());
-
- // default true
- EXPECT_EQ("//root/external/file", FS->status("//root/A")->getName());
- // explicit
- EXPECT_EQ("//root/external/file", FS->status("//root/B")->getName());
- EXPECT_EQ("//root/C", FS->status("//root/C")->getName());
-
- // global configuration
- FS = getFromYAMLString(
- "{ 'use-external-names': false,\n"
- " 'roots': [\n"
- " { 'type': 'file', 'name': '//root/A',\n"
- " 'external-contents': '//root/external/file'\n"
- " },\n"
- " { 'type': 'file', 'name': '//root/B',\n"
- " 'use-external-name': true,\n"
- " 'external-contents': '//root/external/file'\n"
- " },\n"
- " { 'type': 'file', 'name': '//root/C',\n"
- " 'use-external-name': false,\n"
- " 'external-contents': '//root/external/file'\n"
- " }\n"
- "] }", Lower);
- ASSERT_TRUE(nullptr != FS.get());
-
- // default
- EXPECT_EQ("//root/A", FS->status("//root/A")->getName());
- // explicit
- EXPECT_EQ("//root/external/file", FS->status("//root/B")->getName());
- EXPECT_EQ("//root/C", FS->status("//root/C")->getName());
-}
-
-TEST_F(VFSFromYAMLTest, MultiComponentPath) {
- IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
- Lower->addRegularFile("//root/other");
-
- // file in roots
- IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLString(
- "{ 'roots': [\n"
- " { 'type': 'file', 'name': '//root/path/to/file',\n"
- " 'external-contents': '//root/other' }]\n"
- "}", Lower);
- ASSERT_TRUE(nullptr != FS.get());
- EXPECT_FALSE(FS->status("//root/path/to/file").getError());
- EXPECT_FALSE(FS->status("//root/path/to").getError());
- EXPECT_FALSE(FS->status("//root/path").getError());
- EXPECT_FALSE(FS->status("//root/").getError());
-
- // at the start
- FS = getFromYAMLString(
- "{ 'roots': [\n"
- " { 'type': 'directory', 'name': '//root/path/to',\n"
- " 'contents': [ { 'type': 'file', 'name': 'file',\n"
- " 'external-contents': '//root/other' }]}]\n"
- "}", Lower);
- ASSERT_TRUE(nullptr != FS.get());
- EXPECT_FALSE(FS->status("//root/path/to/file").getError());
- EXPECT_FALSE(FS->status("//root/path/to").getError());
- EXPECT_FALSE(FS->status("//root/path").getError());
- EXPECT_FALSE(FS->status("//root/").getError());
-
- // at the end
- FS = getFromYAMLString(
- "{ 'roots': [\n"
- " { 'type': 'directory', 'name': '//root/',\n"
- " 'contents': [ { 'type': 'file', 'name': 'path/to/file',\n"
- " 'external-contents': '//root/other' }]}]\n"
- "}", Lower);
- ASSERT_TRUE(nullptr != FS.get());
- EXPECT_FALSE(FS->status("//root/path/to/file").getError());
- EXPECT_FALSE(FS->status("//root/path/to").getError());
- EXPECT_FALSE(FS->status("//root/path").getError());
- EXPECT_FALSE(FS->status("//root/").getError());
-}
-
-TEST_F(VFSFromYAMLTest, TrailingSlashes) {
- IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
- Lower->addRegularFile("//root/other");
-
- // file in roots
- IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLString(
- "{ 'roots': [\n"
- " { 'type': 'directory', 'name': '//root/path/to////',\n"
- " 'contents': [ { 'type': 'file', 'name': 'file',\n"
- " 'external-contents': '//root/other' }]}]\n"
- "}", Lower);
- ASSERT_TRUE(nullptr != FS.get());
- EXPECT_FALSE(FS->status("//root/path/to/file").getError());
- EXPECT_FALSE(FS->status("//root/path/to").getError());
- EXPECT_FALSE(FS->status("//root/path").getError());
- EXPECT_FALSE(FS->status("//root/").getError());
-}
-
-TEST_F(VFSFromYAMLTest, DirectoryIteration) {
- IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
- Lower->addDirectory("//root/");
- Lower->addDirectory("//root/foo");
- Lower->addDirectory("//root/foo/bar");
- Lower->addRegularFile("//root/foo/bar/a");
- Lower->addRegularFile("//root/foo/bar/b");
- Lower->addRegularFile("//root/file3");
- IntrusiveRefCntPtr<vfs::FileSystem> FS =
- getFromYAMLString("{ 'use-external-names': false,\n"
- " 'roots': [\n"
- "{\n"
- " 'type': 'directory',\n"
- " 'name': '//root/',\n"
- " 'contents': [ {\n"
- " 'type': 'file',\n"
- " 'name': 'file1',\n"
- " 'external-contents': '//root/foo/bar/a'\n"
- " },\n"
- " {\n"
- " 'type': 'file',\n"
- " 'name': 'file2',\n"
- " 'external-contents': '//root/foo/bar/b'\n"
- " }\n"
- " ]\n"
- "}\n"
- "]\n"
- "}",
- Lower);
- ASSERT_TRUE(FS.get() != nullptr);
-
- IntrusiveRefCntPtr<vfs::OverlayFileSystem> O(
- new vfs::OverlayFileSystem(Lower));
- O->pushOverlay(FS);
-
- std::error_code EC;
- checkContents(O->dir_begin("//root/", EC),
- {"//root/file1", "//root/file2", "//root/file3", "//root/foo"});
-
- checkContents(O->dir_begin("//root/foo/bar", EC),
- {"//root/foo/bar/a", "//root/foo/bar/b"});
-}
-
-TEST_F(VFSFromYAMLTest, DirectoryIterationSameDirMultipleEntries) {
- // https://llvm.org/bugs/show_bug.cgi?id=27725
- if (!supportsSameDirMultipleYAMLEntries())
- return;
-
- IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
- Lower->addDirectory("//root/zab");
- Lower->addDirectory("//root/baz");
- Lower->addRegularFile("//root/zab/a");
- Lower->addRegularFile("//root/zab/b");
- IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLString(
- "{ 'use-external-names': false,\n"
- " 'roots': [\n"
- "{\n"
- " 'type': 'directory',\n"
- " 'name': '//root/baz/',\n"
- " 'contents': [ {\n"
- " 'type': 'file',\n"
- " 'name': 'x',\n"
- " 'external-contents': '//root/zab/a'\n"
- " }\n"
- " ]\n"
- "},\n"
- "{\n"
- " 'type': 'directory',\n"
- " 'name': '//root/baz/',\n"
- " 'contents': [ {\n"
- " 'type': 'file',\n"
- " 'name': 'y',\n"
- " 'external-contents': '//root/zab/b'\n"
- " }\n"
- " ]\n"
- "}\n"
- "]\n"
- "}",
- Lower);
- ASSERT_TRUE(FS.get() != nullptr);
-
- IntrusiveRefCntPtr<vfs::OverlayFileSystem> O(
- new vfs::OverlayFileSystem(Lower));
- O->pushOverlay(FS);
-
- std::error_code EC;
-
- checkContents(O->dir_begin("//root/baz/", EC),
- {"//root/baz/x", "//root/baz/y"});
-}
-
-TEST_F(VFSFromYAMLTest, RecursiveDirectoryIterationLevel) {
-
- IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
- Lower->addDirectory("//root/a");
- Lower->addDirectory("//root/a/b");
- Lower->addDirectory("//root/a/b/c");
- Lower->addRegularFile("//root/a/b/c/file");
- IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLString(
- "{ 'use-external-names': false,\n"
- " 'roots': [\n"
- "{\n"
- " 'type': 'directory',\n"
- " 'name': '//root/a/b/c/',\n"
- " 'contents': [ {\n"
- " 'type': 'file',\n"
- " 'name': 'file',\n"
- " 'external-contents': '//root/a/b/c/file'\n"
- " }\n"
- " ]\n"
- "},\n"
- "]\n"
- "}",
- Lower);
- ASSERT_TRUE(FS.get() != nullptr);
-
- IntrusiveRefCntPtr<vfs::OverlayFileSystem> O(
- new vfs::OverlayFileSystem(Lower));
- O->pushOverlay(FS);
-
- std::error_code EC;
-
- // Test recursive_directory_iterator level()
- vfs::recursive_directory_iterator I = vfs::recursive_directory_iterator(
- *O, "//root", EC), E;
- ASSERT_FALSE(EC);
- for (int l = 0; I != E; I.increment(EC), ++l) {
- ASSERT_FALSE(EC);
- EXPECT_EQ(I.level(), l);
- }
- EXPECT_EQ(I, E);
-}
-
-TEST_F(VFSFromYAMLTest, RelativePaths) {
- IntrusiveRefCntPtr<DummyFileSystem> Lower(new DummyFileSystem());
- // Filename at root level without a parent directory.
- IntrusiveRefCntPtr<vfs::FileSystem> FS = getFromYAMLString(
- "{ 'roots': [\n"
- " { 'type': 'file', 'name': 'file-not-in-directory.h',\n"
- " 'external-contents': '//root/external/file'\n"
- " }\n"
- "] }", Lower);
- EXPECT_EQ(nullptr, FS.get());
-
- // Relative file path.
- FS = getFromYAMLString(
- "{ 'roots': [\n"
- " { 'type': 'file', 'name': 'relative/file/path.h',\n"
- " 'external-contents': '//root/external/file'\n"
- " }\n"
- "] }", Lower);
- EXPECT_EQ(nullptr, FS.get());
-
- // Relative directory path.
- FS = getFromYAMLString(
- "{ 'roots': [\n"
- " { 'type': 'directory', 'name': 'relative/directory/path.h',\n"
- " 'contents': []\n"
- " }\n"
- "] }", Lower);
- EXPECT_EQ(nullptr, FS.get());
-
- EXPECT_EQ(3, NumDiagnostics);
-}
diff --git a/clang/unittests/Driver/DistroTest.cpp b/clang/unittests/Driver/DistroTest.cpp
index e3686e49806..5a23392e8cd 100644
--- a/clang/unittests/Driver/DistroTest.cpp
+++ b/clang/unittests/Driver/DistroTest.cpp
@@ -12,7 +12,7 @@
//===----------------------------------------------------------------------===//
#include "clang/Driver/Distro.h"
-#include "clang/Basic/VirtualFileSystem.h"
+#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
using namespace clang;
@@ -25,7 +25,7 @@ namespace {
// accidentally result in incorrect distribution guess.
TEST(DistroTest, DetectUbuntu) {
- vfs::InMemoryFileSystem UbuntuTrustyFileSystem;
+ llvm::vfs::InMemoryFileSystem UbuntuTrustyFileSystem;
// Ubuntu uses Debian Sid version.
UbuntuTrustyFileSystem.addFile("/etc/debian_version", 0,
llvm::MemoryBuffer::getMemBuffer("jessie/sid\n"));
@@ -52,7 +52,7 @@ TEST(DistroTest, DetectUbuntu) {
ASSERT_FALSE(UbuntuTrusty.IsOpenSUSE());
ASSERT_FALSE(UbuntuTrusty.IsDebian());
- vfs::InMemoryFileSystem UbuntuYakketyFileSystem;
+ llvm::vfs::InMemoryFileSystem UbuntuYakketyFileSystem;
UbuntuYakketyFileSystem.addFile("/etc/debian_version", 0,
llvm::MemoryBuffer::getMemBuffer("stretch/sid\n"));
UbuntuYakketyFileSystem.addFile("/etc/lsb-release", 0,
@@ -83,7 +83,7 @@ TEST(DistroTest, DetectUbuntu) {
}
TEST(DistroTest, DetectRedhat) {
- vfs::InMemoryFileSystem Fedora25FileSystem;
+ llvm::vfs::InMemoryFileSystem Fedora25FileSystem;
Fedora25FileSystem.addFile("/etc/system-release-cpe", 0,
llvm::MemoryBuffer::getMemBuffer("cpe:/o:fedoraproject:fedora:25\n"));
// Both files are symlinks to fedora-release.
@@ -115,7 +115,7 @@ TEST(DistroTest, DetectRedhat) {
ASSERT_FALSE(Fedora25.IsOpenSUSE());
ASSERT_FALSE(Fedora25.IsDebian());
- vfs::InMemoryFileSystem CentOS7FileSystem;
+ llvm::vfs::InMemoryFileSystem CentOS7FileSystem;
CentOS7FileSystem.addFile("/etc/system-release-cpe", 0,
llvm::MemoryBuffer::getMemBuffer("cpe:/o:centos:centos:7\n"));
// Both files are symlinks to centos-release.
@@ -153,7 +153,7 @@ TEST(DistroTest, DetectRedhat) {
}
TEST(DistroTest, DetectOpenSUSE) {
- vfs::InMemoryFileSystem OpenSUSELeap421FileSystem;
+ llvm::vfs::InMemoryFileSystem OpenSUSELeap421FileSystem;
OpenSUSELeap421FileSystem.addFile("/etc/SuSE-release", 0,
llvm::MemoryBuffer::getMemBuffer("openSUSE 42.1 (x86_64)\n"
"VERSION = 42.1\n"
@@ -178,7 +178,7 @@ TEST(DistroTest, DetectOpenSUSE) {
ASSERT_TRUE(OpenSUSELeap421.IsOpenSUSE());
ASSERT_FALSE(OpenSUSELeap421.IsDebian());
- vfs::InMemoryFileSystem OpenSUSE132FileSystem;
+ llvm::vfs::InMemoryFileSystem OpenSUSE132FileSystem;
OpenSUSE132FileSystem.addFile("/etc/SuSE-release", 0,
llvm::MemoryBuffer::getMemBuffer("openSUSE 13.2 (x86_64)\n"
"VERSION = 13.2\n"
@@ -203,7 +203,7 @@ TEST(DistroTest, DetectOpenSUSE) {
ASSERT_TRUE(OpenSUSE132.IsOpenSUSE());
ASSERT_FALSE(OpenSUSE132.IsDebian());
- vfs::InMemoryFileSystem SLES10FileSystem;
+ llvm::vfs::InMemoryFileSystem SLES10FileSystem;
SLES10FileSystem.addFile("/etc/SuSE-release", 0,
llvm::MemoryBuffer::getMemBuffer("SUSE Linux Enterprise Server 10 (x86_64)\n"
"VERSION = 10\n"
@@ -221,7 +221,7 @@ TEST(DistroTest, DetectOpenSUSE) {
}
TEST(DistroTest, DetectDebian) {
- vfs::InMemoryFileSystem DebianJessieFileSystem;
+ llvm::vfs::InMemoryFileSystem DebianJessieFileSystem;
DebianJessieFileSystem.addFile("/etc/debian_version", 0,
llvm::MemoryBuffer::getMemBuffer("8.6\n"));
DebianJessieFileSystem.addFile("/etc/os-release", 0,
@@ -241,7 +241,7 @@ TEST(DistroTest, DetectDebian) {
ASSERT_FALSE(DebianJessie.IsOpenSUSE());
ASSERT_TRUE(DebianJessie.IsDebian());
- vfs::InMemoryFileSystem DebianStretchSidFileSystem;
+ llvm::vfs::InMemoryFileSystem DebianStretchSidFileSystem;
DebianStretchSidFileSystem.addFile("/etc/debian_version", 0,
llvm::MemoryBuffer::getMemBuffer("stretch/sid\n"));
DebianStretchSidFileSystem.addFile("/etc/os-release", 0,
@@ -261,7 +261,7 @@ TEST(DistroTest, DetectDebian) {
}
TEST(DistroTest, DetectExherbo) {
- vfs::InMemoryFileSystem ExherboFileSystem;
+ llvm::vfs::InMemoryFileSystem ExherboFileSystem;
ExherboFileSystem.addFile("/etc/exherbo-release", 0, // (ASCII art)
llvm::MemoryBuffer::getMemBuffer(""));
ExherboFileSystem.addFile("/etc/os-release", 0,
@@ -282,7 +282,7 @@ TEST(DistroTest, DetectExherbo) {
}
TEST(DistroTest, DetectArchLinux) {
- vfs::InMemoryFileSystem ArchLinuxFileSystem;
+ llvm::vfs::InMemoryFileSystem ArchLinuxFileSystem;
ArchLinuxFileSystem.addFile("/etc/arch-release", 0, // (empty)
llvm::MemoryBuffer::getMemBuffer(""));
ArchLinuxFileSystem.addFile("/etc/os-release", 0,
diff --git a/clang/unittests/Driver/ToolChainTest.cpp b/clang/unittests/Driver/ToolChainTest.cpp
index 0d4c545bd79..f1181072a7e 100644
--- a/clang/unittests/Driver/ToolChainTest.cpp
+++ b/clang/unittests/Driver/ToolChainTest.cpp
@@ -15,11 +15,11 @@
#include "clang/Basic/DiagnosticIDs.h"
#include "clang/Basic/DiagnosticOptions.h"
#include "clang/Basic/LLVM.h"
-#include "clang/Basic/VirtualFileSystem.h"
#include "clang/Driver/Compilation.h"
#include "clang/Driver/Driver.h"
#include "llvm/Support/TargetRegistry.h"
#include "llvm/Support/TargetSelect.h"
+#include "llvm/Support/VirtualFileSystem.h"
#include "llvm/Support/raw_ostream.h"
#include "gtest/gtest.h"
using namespace clang;
@@ -33,8 +33,8 @@ TEST(ToolChainTest, VFSGCCInstallation) {
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
struct TestDiagnosticConsumer : public DiagnosticConsumer {};
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
- IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem(
- new vfs::InMemoryFileSystem);
+ IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
+ new llvm::vfs::InMemoryFileSystem);
Driver TheDriver("/bin/clang", "arm-linux-gnueabihf", Diags,
InMemoryFileSystem);
@@ -87,8 +87,8 @@ TEST(ToolChainTest, VFSGCCInstallationRelativeDir) {
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
struct TestDiagnosticConsumer : public DiagnosticConsumer {};
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
- IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem(
- new vfs::InMemoryFileSystem);
+ IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
+ new llvm::vfs::InMemoryFileSystem);
Driver TheDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags,
InMemoryFileSystem);
@@ -127,8 +127,8 @@ TEST(ToolChainTest, DefaultDriverMode) {
IntrusiveRefCntPtr<DiagnosticIDs> DiagID(new DiagnosticIDs());
struct TestDiagnosticConsumer : public DiagnosticConsumer {};
DiagnosticsEngine Diags(DiagID, &*DiagOpts, new TestDiagnosticConsumer);
- IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem(
- new vfs::InMemoryFileSystem);
+ IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
+ new llvm::vfs::InMemoryFileSystem);
Driver CCDriver("/home/test/bin/clang", "arm-linux-gnueabi", Diags,
InMemoryFileSystem);
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index b29f67addf8..86b1ca2f17d 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -12375,14 +12375,14 @@ TEST_F(FormatTest, NoSpaceAfterSuper) {
}
TEST(FormatStyle, GetStyleWithEmptyFileName) {
- vfs::InMemoryFileSystem FS;
+ llvm::vfs::InMemoryFileSystem FS;
auto Style1 = getStyle("file", "", "Google", "", &FS);
ASSERT_TRUE((bool)Style1);
ASSERT_EQ(*Style1, getGoogleStyle());
}
TEST(FormatStyle, GetStyleOfFile) {
- vfs::InMemoryFileSystem FS;
+ llvm::vfs::InMemoryFileSystem FS;
// Test 1: format file in the same directory.
ASSERT_TRUE(
FS.addFile("/a/.clang-format", 0,
diff --git a/clang/unittests/Index/IndexTests.cpp b/clang/unittests/Index/IndexTests.cpp
index e438537b43a..2d4463d833c 100644
--- a/clang/unittests/Index/IndexTests.cpp
+++ b/clang/unittests/Index/IndexTests.cpp
@@ -9,7 +9,6 @@
#include "clang/AST/ASTConsumer.h"
#include "clang/AST/Decl.h"
-#include "clang/Basic/VirtualFileSystem.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Index/IndexDataConsumer.h"
@@ -18,6 +17,7 @@
#include "clang/Lex/Preprocessor.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/VirtualFileSystem.h"
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include <memory>
diff --git a/clang/unittests/Lex/HeaderSearchTest.cpp b/clang/unittests/Lex/HeaderSearchTest.cpp
index c2794f5e959..060135bc731 100644
--- a/clang/unittests/Lex/HeaderSearchTest.cpp
+++ b/clang/unittests/Lex/HeaderSearchTest.cpp
@@ -27,7 +27,7 @@ namespace {
class HeaderSearchTest : public ::testing::Test {
protected:
HeaderSearchTest()
- : VFS(new vfs::InMemoryFileSystem), FileMgr(FileMgrOpts, VFS),
+ : VFS(new llvm::vfs::InMemoryFileSystem), FileMgr(FileMgrOpts, VFS),
DiagID(new DiagnosticIDs()),
Diags(DiagID, new DiagnosticOptions, new IgnoringDiagConsumer()),
SourceMgr(Diags, FileMgr), TargetOpts(new TargetOptions),
@@ -46,7 +46,7 @@ protected:
Search.AddSearchPath(DL, /*isAngled=*/false);
}
- IntrusiveRefCntPtr<vfs::InMemoryFileSystem> VFS;
+ IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS;
FileSystemOptions FileMgrOpts;
FileManager FileMgr;
IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
diff --git a/clang/unittests/Lex/PPCallbacksTest.cpp b/clang/unittests/Lex/PPCallbacksTest.cpp
index 0fa6286cc04..d0ff45ec7cc 100644
--- a/clang/unittests/Lex/PPCallbacksTest.cpp
+++ b/clang/unittests/Lex/PPCallbacksTest.cpp
@@ -95,7 +95,7 @@ public:
class PPCallbacksTest : public ::testing::Test {
protected:
PPCallbacksTest()
- : InMemoryFileSystem(new vfs::InMemoryFileSystem),
+ : InMemoryFileSystem(new llvm::vfs::InMemoryFileSystem),
FileMgr(FileSystemOptions(), InMemoryFileSystem),
DiagID(new DiagnosticIDs()), DiagOpts(new DiagnosticOptions()),
Diags(DiagID, DiagOpts.get(), new IgnoringDiagConsumer()),
@@ -104,7 +104,7 @@ protected:
Target = TargetInfo::CreateTargetInfo(Diags, TargetOpts);
}
- IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem;
+ IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem;
FileManager FileMgr;
IntrusiveRefCntPtr<DiagnosticIDs> DiagID;
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
@@ -116,17 +116,17 @@ protected:
// Register a header path as a known file and add its location
// to search path.
- void AddFakeHeader(HeaderSearch& HeaderInfo, const char* HeaderPath,
- bool IsSystemHeader) {
- // Tell FileMgr about header.
- InMemoryFileSystem->addFile(HeaderPath, 0,
- llvm::MemoryBuffer::getMemBuffer("\n"));
-
- // Add header's parent path to search path.
- StringRef SearchPath = llvm::sys::path::parent_path(HeaderPath);
- const DirectoryEntry *DE = FileMgr.getDirectory(SearchPath);
- DirectoryLookup DL(DE, SrcMgr::C_User, false);
- HeaderInfo.AddSearchPath(DL, IsSystemHeader);
+ void AddFakeHeader(HeaderSearch &HeaderInfo, const char *HeaderPath,
+ bool IsSystemHeader) {
+ // Tell FileMgr about header.
+ InMemoryFileSystem->addFile(HeaderPath, 0,
+ llvm::MemoryBuffer::getMemBuffer("\n"));
+
+ // Add header's parent path to search path.
+ StringRef SearchPath = llvm::sys::path::parent_path(HeaderPath);
+ const DirectoryEntry *DE = FileMgr.getDirectory(SearchPath);
+ DirectoryLookup DL(DE, SrcMgr::C_User, false);
+ HeaderInfo.AddSearchPath(DL, IsSystemHeader);
}
// Get the raw source string of the range.
@@ -139,8 +139,9 @@ protected:
// Run lexer over SourceText and collect FilenameRange from
// the InclusionDirective callback.
- CharSourceRange InclusionDirectiveFilenameRange(const char* SourceText,
- const char* HeaderPath, bool SystemHeader) {
+ CharSourceRange InclusionDirectiveFilenameRange(const char *SourceText,
+ const char *HeaderPath,
+ bool SystemHeader) {
std::unique_ptr<llvm::MemoryBuffer> Buf =
llvm::MemoryBuffer::getMemBuffer(SourceText);
SourceMgr.setMainFileID(SourceMgr.createFileID(std::move(Buf)));
@@ -198,8 +199,8 @@ protected:
return Callbacks;
}
- PragmaOpenCLExtensionCallbacks::CallbackParameters
- PragmaOpenCLExtensionCall(const char* SourceText) {
+ PragmaOpenCLExtensionCallbacks::CallbackParameters
+ PragmaOpenCLExtensionCall(const char *SourceText) {
LangOptions OpenCLLangOpts;
OpenCLLangOpts.OpenCL = 1;
@@ -221,9 +222,8 @@ protected:
// parser actually sets correct pragma handlers for preprocessor
// according to LangOptions, so we init Parser to register opencl
// pragma handlers
- ASTContext Context(OpenCLLangOpts, SourceMgr,
- PP.getIdentifierTable(), PP.getSelectorTable(),
- PP.getBuiltinInfo());
+ ASTContext Context(OpenCLLangOpts, SourceMgr, PP.getIdentifierTable(),
+ PP.getSelectorTable(), PP.getBuiltinInfo());
Context.InitBuiltinTypes(*Target);
ASTConsumer Consumer;
@@ -245,7 +245,7 @@ protected:
Callbacks->Name,
Callbacks->State
};
- return RetVal;
+ return RetVal;
}
};
diff --git a/clang/unittests/Rename/ClangRenameTest.h b/clang/unittests/Rename/ClangRenameTest.h
index e0f33674cfe..13906d15bca 100644
--- a/clang/unittests/Rename/ClangRenameTest.h
+++ b/clang/unittests/Rename/ClangRenameTest.h
@@ -14,7 +14,6 @@
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/FileSystemOptions.h"
-#include "clang/Basic/VirtualFileSystem.h"
#include "clang/Format/Format.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/PCHContainerOperations.h"
@@ -26,6 +25,7 @@
#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Format.h"
#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/VirtualFileSystem.h"
#include "gtest/gtest.h"
#include <memory>
#include <string>
diff --git a/clang/unittests/Tooling/RefactoringTest.cpp b/clang/unittests/Tooling/RefactoringTest.cpp
index fcd2aa59373..d618c0fb07f 100644
--- a/clang/unittests/Tooling/RefactoringTest.cpp
+++ b/clang/unittests/Tooling/RefactoringTest.cpp
@@ -7,6 +7,7 @@
//
//===----------------------------------------------------------------------===//
+#include "clang/Tooling/Refactoring.h"
#include "ReplacementTest.h"
#include "RewriterTestContext.h"
#include "clang/AST/ASTConsumer.h"
@@ -19,16 +20,15 @@
#include "clang/Basic/FileManager.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceManager.h"
-#include "clang/Basic/VirtualFileSystem.h"
#include "clang/Format/Format.h"
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/FrontendAction.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Rewrite/Core/Rewriter.h"
-#include "clang/Tooling/Refactoring.h"
#include "clang/Tooling/Refactoring/AtomicChange.h"
#include "clang/Tooling/Tooling.h"
#include "llvm/ADT/SmallString.h"
+#include "llvm/Support/VirtualFileSystem.h"
#include "gtest/gtest.h"
namespace clang {
@@ -1032,8 +1032,8 @@ TEST_F(MergeReplacementsTest, OverlappingRanges) {
TEST(DeduplicateByFileTest, PathsWithDots) {
std::map<std::string, Replacements> FileToReplaces;
- llvm::IntrusiveRefCntPtr<vfs::InMemoryFileSystem> VFS(
- new vfs::InMemoryFileSystem());
+ llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS(
+ new llvm::vfs::InMemoryFileSystem());
FileManager FileMgr(FileSystemOptions(), VFS);
#if !defined(_WIN32)
StringRef Path1 = "a/b/.././c.h";
@@ -1053,8 +1053,8 @@ TEST(DeduplicateByFileTest, PathsWithDots) {
TEST(DeduplicateByFileTest, PathWithDotSlash) {
std::map<std::string, Replacements> FileToReplaces;
- llvm::IntrusiveRefCntPtr<vfs::InMemoryFileSystem> VFS(
- new vfs::InMemoryFileSystem());
+ llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS(
+ new llvm::vfs::InMemoryFileSystem());
FileManager FileMgr(FileSystemOptions(), VFS);
#if !defined(_WIN32)
StringRef Path1 = "./a/b/c.h";
@@ -1074,8 +1074,8 @@ TEST(DeduplicateByFileTest, PathWithDotSlash) {
TEST(DeduplicateByFileTest, NonExistingFilePath) {
std::map<std::string, Replacements> FileToReplaces;
- llvm::IntrusiveRefCntPtr<vfs::InMemoryFileSystem> VFS(
- new vfs::InMemoryFileSystem());
+ llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> VFS(
+ new llvm::vfs::InMemoryFileSystem());
FileManager FileMgr(FileSystemOptions(), VFS);
#if !defined(_WIN32)
StringRef Path1 = "./a/b/c.h";
diff --git a/clang/unittests/Tooling/RewriterTestContext.h b/clang/unittests/Tooling/RewriterTestContext.h
index eee7ea1873b..9e66484158f 100644
--- a/clang/unittests/Tooling/RewriterTestContext.h
+++ b/clang/unittests/Tooling/RewriterTestContext.h
@@ -39,15 +39,15 @@ class RewriterTestContext {
Diagnostics(IntrusiveRefCntPtr<DiagnosticIDs>(new DiagnosticIDs),
&*DiagOpts),
DiagnosticPrinter(llvm::outs(), &*DiagOpts),
- InMemoryFileSystem(new vfs::InMemoryFileSystem),
+ InMemoryFileSystem(new llvm::vfs::InMemoryFileSystem),
OverlayFileSystem(
- new vfs::OverlayFileSystem(vfs::getRealFileSystem())),
+ new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem())),
Files(FileSystemOptions(), OverlayFileSystem),
Sources(Diagnostics, Files), Rewrite(Sources, Options) {
- Diagnostics.setClient(&DiagnosticPrinter, false);
- // FIXME: To make these tests truly in-memory, we need to overlay the
- // builtin headers.
- OverlayFileSystem->pushOverlay(InMemoryFileSystem);
+ Diagnostics.setClient(&DiagnosticPrinter, false);
+ // FIXME: To make these tests truly in-memory, we need to overlay the
+ // builtin headers.
+ OverlayFileSystem->pushOverlay(InMemoryFileSystem);
}
~RewriterTestContext() {}
@@ -114,8 +114,8 @@ class RewriterTestContext {
IntrusiveRefCntPtr<DiagnosticOptions> DiagOpts;
DiagnosticsEngine Diagnostics;
TextDiagnosticPrinter DiagnosticPrinter;
- IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem;
- IntrusiveRefCntPtr<vfs::OverlayFileSystem> OverlayFileSystem;
+ IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem;
+ IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem;
FileManager Files;
SourceManager Sources;
LangOptions Options;
diff --git a/clang/unittests/Tooling/ToolingTest.cpp b/clang/unittests/Tooling/ToolingTest.cpp
index 0a5150a31b7..186463f80af 100644
--- a/clang/unittests/Tooling/ToolingTest.cpp
+++ b/clang/unittests/Tooling/ToolingTest.cpp
@@ -149,10 +149,10 @@ TEST(newFrontendActionFactory, CreatesFrontendActionFactoryFromFactoryType) {
}
TEST(ToolInvocation, TestMapVirtualFile) {
- llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> OverlayFileSystem(
- new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
- llvm::IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem(
- new vfs::InMemoryFileSystem);
+ llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem(
+ new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+ llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
+ new llvm::vfs::InMemoryFileSystem);
OverlayFileSystem->pushOverlay(InMemoryFileSystem);
llvm::IntrusiveRefCntPtr<FileManager> Files(
new FileManager(FileSystemOptions(), OverlayFileSystem));
@@ -175,10 +175,10 @@ TEST(ToolInvocation, TestVirtualModulesCompilation) {
// mapped module.map is found on the include path. In the future, expand this
// test to run a full modules enabled compilation, so we make sure we can
// rerun modules compilations with a virtual file system.
- llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> OverlayFileSystem(
- new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
- llvm::IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem(
- new vfs::InMemoryFileSystem);
+ llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem(
+ new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+ llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
+ new llvm::vfs::InMemoryFileSystem);
OverlayFileSystem->pushOverlay(InMemoryFileSystem);
llvm::IntrusiveRefCntPtr<FileManager> Files(
new FileManager(FileSystemOptions(), OverlayFileSystem));
@@ -403,10 +403,10 @@ TEST(ClangToolTest, ArgumentAdjusters) {
TEST(ClangToolTest, BaseVirtualFileSystemUsage) {
FixedCompilationDatabase Compilations("/", std::vector<std::string>());
- llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> OverlayFileSystem(
- new vfs::OverlayFileSystem(vfs::getRealFileSystem()));
- llvm::IntrusiveRefCntPtr<vfs::InMemoryFileSystem> InMemoryFileSystem(
- new vfs::InMemoryFileSystem);
+ llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem(
+ new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()));
+ llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> InMemoryFileSystem(
+ new llvm::vfs::InMemoryFileSystem);
OverlayFileSystem->pushOverlay(InMemoryFileSystem);
InMemoryFileSystem->addFile(
OpenPOWER on IntegriCloud