13 #include "llvm/ADT/None.h"
14 #include "llvm/ADT/Optional.h"
15 #include "llvm/ADT/StringRef.h"
16 #include "llvm/Support/Path.h"
28 Path =
Path.drop_front(Prefix.size());
33 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
35 llvm::StringMap<time_t>
const &Timestamps) {
36 llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> MemFS(
38 MemFS->setCurrentWorkingDirectory(
testRoot());
39 for (
auto &FileAndContents :
Files) {
40 llvm::StringRef File = FileAndContents.first();
42 File, Timestamps.lookup(File),
43 llvm::MemoryBuffer::getMemBufferCopy(FileAndContents.second, File));
49 llvm::StringRef RelPathPrefix)
51 RelPathPrefix(RelPathPrefix) {
55 llvm::Optional<ProjectInfo>
60 llvm::Optional<tooling::CompileCommand>
65 auto FileName = llvm::sys::path::filename(File);
70 if (RelPathPrefix.empty()) {
75 llvm::SmallString<32> RelativeFilePath(RelPathPrefix);
76 llvm::sys::path::append(RelativeFilePath,
FileName);
77 CommandLine.push_back(std::string(RelativeFilePath.str()));
80 return {tooling::CompileCommand(Directory != llvm::StringRef()
82 : llvm::sys::path::parent_path(File),
88 return "C:\\clangd-test";
90 return "/clangd-test";
95 assert(llvm::sys::path::is_relative(File) &&
"FileName should be relative");
97 llvm::SmallString<32> NativeFile = File;
98 llvm::sys::path::native(NativeFile, Style);
99 llvm::SmallString<32>
Path;
100 llvm::sys::path::append(
Path, Style,
testRoot(), NativeFile);
101 return std::string(
Path.str());
111 llvm::Expected<std::string>
113 llvm::StringRef HintPath)
const override {
115 return error(
"Hint path is not empty and doesn't start with {0}: {1}",
117 if (!Body.consume_front(
"/"))
118 return error(
"Body of an unittest: URI must start with '/'");
119 llvm::SmallString<16>
Path(Body.begin(), Body.end());
120 llvm::sys::path::native(
Path);
126 if (!pathConsumeFront(AbsolutePath,
testRoot()))
127 return error(
"{0} does not start with {1}", AbsolutePath,
testRoot());
129 return URI(Scheme,
"",
130 llvm::sys::path::convert_to_slash(AbsolutePath));
134 const char *TestScheme::Scheme =
"unittest";
136 static URISchemeRegistry::Add<TestScheme>
X(TestScheme::Scheme,
"Test schema");