[cfe-commits] r158112 - /cfe/trunk/unittests/Tooling/RewriterTestContext.h

Manuel Klimek klimek at google.com
Wed Jun 6 14:28:13 PDT 2012


Author: klimek
Date: Wed Jun  6 16:28:13 2012
New Revision: 158112

URL: http://llvm.org/viewvc/llvm-project?rev=158112&view=rev
Log:
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.

Modified:
    cfe/trunk/unittests/Tooling/RewriterTestContext.h

Modified: cfe/trunk/unittests/Tooling/RewriterTestContext.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RewriterTestContext.h?rev=158112&r1=158111&r2=158112&view=diff
==============================================================================
--- cfe/trunk/unittests/Tooling/RewriterTestContext.h (original)
+++ cfe/trunk/unittests/Tooling/RewriterTestContext.h Wed Jun  6 16:28:13 2012
@@ -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 @@
   }
 
   ~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 @@
   }
 
   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 @@
   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





More information about the cfe-commits mailing list