Add ChangeToTempDir to TestUtil
[folly.git] / folly / experimental / TestUtil.h
index 2a736c96ad923d8ae10d835805a9dcb523fbb9e3..adf8be39578eed9d86a1b58bb397cf18c361350a 100644 (file)
@@ -88,6 +88,22 @@ class TemporaryDirectory {
   fs::path path_;
 };
 
+/**
+ * Changes into a temporary directory, and deletes it with all its contents
+ * upon destruction, also changing back to the original working directory.
+ */
+class ChangeToTempDir {
+public:
+  ChangeToTempDir();
+  ~ChangeToTempDir();
+
+  const fs::path& path() const { return dir_.path(); }
+
+private:
+  fs::path initialPath_;
+  TemporaryDirectory dir_;
+};
+
 }  // namespace test
 }  // namespace folly