Switches the RewriterTestContext away from PathV1.
Now the ToolingTests all work on Windows, and they also clean up their temporary directory if they don't crash. llvm-svn: 158112
This commit is contained in:
parent
91c25eadea
commit
0a8b9cd1e7
|
@ -21,6 +21,7 @@
|
||||||
#include "clang/Frontend/DiagnosticOptions.h"
|
#include "clang/Frontend/DiagnosticOptions.h"
|
||||||
#include "clang/Frontend/TextDiagnosticPrinter.h"
|
#include "clang/Frontend/TextDiagnosticPrinter.h"
|
||||||
#include "clang/Rewrite/Rewriter.h"
|
#include "clang/Rewrite/Rewriter.h"
|
||||||
|
#include "llvm/Support/FileSystem.h"
|
||||||
#include "llvm/Support/Path.h"
|
#include "llvm/Support/Path.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
|
|
||||||
|
@ -43,6 +44,10 @@ class RewriterTestContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
~RewriterTestContext() {
|
~RewriterTestContext() {
|
||||||
|
if (!TemporaryDirectory.empty()) {
|
||||||
|
uint32_t RemovedCount = 0;
|
||||||
|
llvm::sys::fs::remove_all(TemporaryDirectory.str(), RemovedCount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
FileID createInMemoryFile(StringRef Name, StringRef Content) {
|
FileID createInMemoryFile(StringRef Name, StringRef Content) {
|
||||||
|
@ -56,12 +61,14 @@ class RewriterTestContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
FileID createOnDiskFile(StringRef Name, StringRef Content) {
|
FileID createOnDiskFile(StringRef Name, StringRef Content) {
|
||||||
if (!TemporaryDirectory.isValid()) {
|
if (TemporaryDirectory.empty()) {
|
||||||
std::string ErrorInfo;
|
int FD;
|
||||||
TemporaryDirectory = llvm::sys::Path::GetTemporaryDirectory(&ErrorInfo);
|
assert(!llvm::sys::fs::unique_file("rewriter-test-%%-%%-%%-%%/anchor",
|
||||||
assert(ErrorInfo.empty());
|
FD, TemporaryDirectory));
|
||||||
|
llvm::raw_fd_ostream Closer(FD, /*shouldClose=*/true);
|
||||||
|
TemporaryDirectory = llvm::sys::path::parent_path(TemporaryDirectory);
|
||||||
}
|
}
|
||||||
llvm::SmallString<1024> Path(TemporaryDirectory.str());
|
llvm::SmallString<1024> Path(TemporaryDirectory);
|
||||||
llvm::sys::path::append(Path, Name);
|
llvm::sys::path::append(Path, Name);
|
||||||
std::string ErrorInfo;
|
std::string ErrorInfo;
|
||||||
llvm::raw_fd_ostream OutStream(Path.c_str(),
|
llvm::raw_fd_ostream OutStream(Path.c_str(),
|
||||||
|
@ -107,8 +114,8 @@ class RewriterTestContext {
|
||||||
LangOptions Options;
|
LangOptions Options;
|
||||||
Rewriter Rewrite;
|
Rewriter Rewrite;
|
||||||
|
|
||||||
// Will be set once on disk files are generated.
|
// Will be set once on disk files are generated.
|
||||||
llvm::sys::Path TemporaryDirectory;
|
SmallString<128> TemporaryDirectory;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end namespace clang
|
} // end namespace clang
|
||||||
|
|
Loading…
Reference in New Issue