summaryrefslogtreecommitdiff
path: root/test_util/src/temp_dir.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2022-06-14 10:05:37 -0400
committerGitHub <noreply@github.com>2022-06-14 10:05:37 -0400
commit443041c23e2e02ea59d69e1f2093c67ddfd818fd (patch)
tree06f449773377ec655982d00cdaf4bbd60857973f /test_util/src/temp_dir.rs
parentfc3a966a2d0be8fc76c384603bf18b55e0bbcf14 (diff)
feat(vendor): support using an existing import map (#14836)
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();
+ }
}