aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorManuel Klimek <klimek@google.com>2012-06-06 21:28:13 +0000
committerManuel Klimek <klimek@google.com>2012-06-06 21:28:13 +0000
commit7b699ac3ac8ce48cf9e9387f6b6830f3a8d409d5 (patch)
treefc24d9401793b724dd2b223b42f7b3d3efcb5944
parentc86c40b912e53fb11ff8f745ed616035b8b7259c (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158112 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--unittests/Tooling/RewriterTestContext.h21
1 files changed, 14 insertions, 7 deletions
diff --git a/unittests/Tooling/RewriterTestContext.h b/unittests/Tooling/RewriterTestContext.h
index 73f9aa662f..9d5b4c92e0 100644
--- a/unittests/Tooling/RewriterTestContext.h
+++ b/unittests/Tooling/RewriterTestContext.h
@@ -21,6 +21,7 @@
#include "clang/Frontend/DiagnosticOptions.h"
#include "clang/Frontend/TextDiagnosticPrinter.h"
#include "clang/Rewrite/Rewriter.h"
+#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
@@ -43,6 +44,10 @@ class RewriterTestContext {
}
~RewriterTestContext() {
+ if (!TemporaryDirectory.empty()) {
+ uint32_t RemovedCount = 0;
+ llvm::sys::fs::remove_all(TemporaryDirectory.str(), RemovedCount);
+ }
}
FileID createInMemoryFile(StringRef Name, StringRef Content) {
@@ -56,12 +61,14 @@ class RewriterTestContext {
}
FileID createOnDiskFile(StringRef Name, StringRef Content) {
- if (!TemporaryDirectory.isValid()) {
- std::string ErrorInfo;
- TemporaryDirectory = llvm::sys::Path::GetTemporaryDirectory(&ErrorInfo);
- assert(ErrorInfo.empty());
+ if (TemporaryDirectory.empty()) {
+ int FD;
+ assert(!llvm::sys::fs::unique_file("rewriter-test-%%-%%-%%-%%/anchor",
+ 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);
std::string ErrorInfo;
llvm::raw_fd_ostream OutStream(Path.c_str(),
@@ -107,8 +114,8 @@ class RewriterTestContext {
LangOptions Options;
Rewriter Rewrite;
- // Will be set once on disk files are generated.
- llvm::sys::Path TemporaryDirectory;
+ // Will be set once on disk files are generated.
+ SmallString<128> TemporaryDirectory;
};
} // end namespace clang