12 #include "llvm/ADT/None.h"
13 #include "llvm/ADT/Optional.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/Support/Errc.h"
16 #include "llvm/Support/Path.h"
21 llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>
23 llvm::StringMap<time_t>
const &Timestamps) {
24 llvm::IntrusiveRefCntPtr<llvm::vfs::InMemoryFileSystem> MemFS(
26 MemFS->setCurrentWorkingDirectory(
testRoot());
27 for (
auto &FileAndContents : Files) {
28 llvm::StringRef File = FileAndContents.first();
30 File, Timestamps.lookup(File),
31 llvm::MemoryBuffer::getMemBufferCopy(FileAndContents.second, File));
37 llvm::StringRef RelPathPrefix)
39 RelPathPrefix(RelPathPrefix) {
43 llvm::Optional<ProjectInfo>
48 llvm::Optional<tooling::CompileCommand>
58 if (RelPathPrefix.empty()) {
63 llvm::SmallString<32> RelativeFilePath(RelPathPrefix);
64 llvm::sys::path::append(RelativeFilePath,
FileName);
65 CommandLine.push_back(std::string(RelativeFilePath.str()));
68 return {tooling::CompileCommand(Directory != llvm::StringRef()
70 : llvm::sys::path::parent_path(
File),
76 return "C:\\clangd-test";
78 return "/clangd-test";
83 assert(llvm::sys::path::is_relative(File) &&
"FileName should be relative");
85 llvm::SmallString<32> NativeFile = File;
86 llvm::sys::path::native(NativeFile, Style);
87 llvm::SmallString<32>
Path;
88 llvm::sys::path::append(
Path, Style,
testRoot(), NativeFile);
89 return std::string(
Path.str());
99 llvm::Expected<std::string>
101 llvm::StringRef HintPath)
const override {
102 if (!HintPath.startswith(
testRoot()))
103 return llvm::make_error<llvm::StringError>(
104 "Hint path doesn't start with test root: " + HintPath,
105 llvm::inconvertibleErrorCode());
106 if (!Body.consume_front(
"/"))
107 return llvm::make_error<llvm::StringError>(
108 "Body of an unittest: URI must start with '/'",
109 llvm::inconvertibleErrorCode());
110 llvm::SmallString<16>
Path(Body.begin(), Body.end());
111 llvm::sys::path::native(
Path);
117 llvm::StringRef Body = AbsolutePath;
118 if (!Body.consume_front(
testRoot()))
119 return llvm::make_error<llvm::StringError>(
120 AbsolutePath +
"does not start with " +
testRoot(),
121 llvm::inconvertibleErrorCode());
123 return URI(Scheme,
"",
124 llvm::sys::path::convert_to_slash(Body));
128 const char *TestScheme::Scheme =
"unittest";
130 static URISchemeRegistry::Add<TestScheme>
X(TestScheme::Scheme,
"Test schema");