| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTFS_H |
| 13 |
#define LLVM_CLANG_TOOLS_EXTRA_CLANGD_UNITTESTS_TESTFS_H |
| 14 |
#include "GlobalCompilationDatabase.h" |
| 15 |
#include "support/Path.h" |
| 16 |
#include "support/ThreadsafeFS.h" |
| 17 |
#include "llvm/ADT/IntrusiveRefCntPtr.h" |
| 18 |
#include "llvm/Support/Path.h" |
| 19 |
#include "llvm/Support/VirtualFileSystem.h" |
| 20 |
#include <optional> |
| 21 |
|
| 22 |
namespace clang { |
| 23 |
namespace clangd { |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem> |
| 28 |
buildTestFS(llvm::StringMap<std::string> const &Files, |
| 29 |
llvm::StringMap<time_t> const &Timestamps = {}); |
| 30 |
|
| 31 |
|
| 32 |
class MockFS : public ThreadsafeFS { |
| 33 |
public: |
| 34 |
IntrusiveRefCntPtr<llvm::vfs::FileSystem> viewImpl() const override { |
| 35 |
auto MemFS = buildTestFS(Files, Timestamps); |
| 36 |
if (!OverlayRealFileSystemForModules) |
| 37 |
return MemFS; |
| 38 |
llvm::IntrusiveRefCntPtr<llvm::vfs::OverlayFileSystem> OverlayFileSystem = |
| 39 |
new llvm::vfs::OverlayFileSystem(llvm::vfs::getRealFileSystem()); |
| 40 |
OverlayFileSystem->pushOverlay(MemFS); |
| 41 |
return OverlayFileSystem; |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
llvm::StringMap<std::string> Files; |
| 46 |
llvm::StringMap<time_t> Timestamps; |
| 47 |
|
| 48 |
|
| 49 |
bool OverlayRealFileSystemForModules = false; |
| 50 |
}; |
| 51 |
|
| 52 |
|
| 53 |
class MockCompilationDatabase : public GlobalCompilationDatabase { |
| 54 |
public: |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
MockCompilationDatabase(StringRef Directory = StringRef(), |
| 61 |
StringRef RelPathPrefix = StringRef()); |
| 62 |
|
| 63 |
std::optional<tooling::CompileCommand> |
| 64 |
getCompileCommand(PathRef File) const override; |
| 65 |
|
| 66 |
std::optional<ProjectInfo> getProjectInfo(PathRef File) const override; |
| 67 |
|
| 68 |
std::vector<std::string> ExtraClangFlags; |
| 69 |
|
| 70 |
private: |
| 71 |
StringRef Directory; |
| 72 |
StringRef RelPathPrefix; |
| 73 |
}; |
| 74 |
|
| 75 |
|
| 76 |
const char *testRoot(); |
| 77 |
|
| 78 |
|
| 79 |
std::string testPath(PathRef File, |
| 80 |
llvm::sys::path::Style = llvm::sys::path::Style::native); |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
extern volatile int UnittestSchemeAnchorSource; |
| 86 |
|
| 87 |
} |
| 88 |
} |
| 89 |
#endif |