Add ChangeToTempDir to TestUtil
[folly.git] / folly / experimental / TestUtil.cpp
index 5b2c43484673246f8769595e89f690ba0319f369..788e36287fea2d759999c9fac365324bd7cb8ac7 100644 (file)
@@ -107,5 +107,15 @@ TemporaryDirectory::~TemporaryDirectory() {
   }
 }
 
+ChangeToTempDir::ChangeToTempDir() : initialPath_(fs::current_path()) {
+  std::string p = dir_.path().native();
+  ::chdir(p.c_str());
+}
+
+ChangeToTempDir::~ChangeToTempDir() {
+  std::string p = initialPath_.native();
+  ::chdir(p.c_str());
+}
+
 }  // namespace test
 }  // namespace folly