summaryrefslogtreecommitdiff
path: root/test_util/src/temp_dir.rs
diff options
context:
space:
mode:
Diffstat (limited to 'test_util/src/temp_dir.rs')
-rw-r--r--test_util/src/temp_dir.rs20
1 files changed, 20 insertions, 0 deletions
diff --git a/test_util/src/temp_dir.rs b/test_util/src/temp_dir.rs
index da2b2a06e..cab55cc14 100644
--- a/test_util/src/temp_dir.rs
+++ b/test_util/src/temp_dir.rs
@@ -1,3 +1,4 @@
+use std::fs;
use std::path::Path;
use std::path::PathBuf;
use std::sync::atomic::AtomicU32;
@@ -84,4 +85,23 @@ impl TempDir {
let inner = &self.0;
inner.0.as_path()
}
+
+ pub fn create_dir_all(&self, path: impl AsRef<Path>) {
+ fs::create_dir_all(self.path().join(path)).unwrap();
+ }
+
+ pub fn read_to_string(&self, path: impl AsRef<Path>) -> String {
+ let file_path = self.path().join(path);
+ fs::read_to_string(&file_path)
+ .with_context(|| format!("Could not find file: {}", file_path.display()))
+ .unwrap()
+ }
+
+ pub fn rename(&self, from: impl AsRef<Path>, to: impl AsRef<Path>) {
+ fs::rename(self.path().join(from), self.path().join(to)).unwrap();
+ }
+
+ pub fn write(&self, path: impl AsRef<Path>, text: impl AsRef<str>) {
+ fs::write(self.path().join(path), text.as_ref()).unwrap();
+ }
}