From 443041c23e2e02ea59d69e1f2093c67ddfd818fd Mon Sep 17 00:00:00 2001 From: David Sherret Date: Tue, 14 Jun 2022 10:05:37 -0400 Subject: feat(vendor): support using an existing import map (#14836) --- test_util/src/temp_dir.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'test_util/src/temp_dir.rs') 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) { + fs::create_dir_all(self.path().join(path)).unwrap(); + } + + pub fn read_to_string(&self, path: impl AsRef) -> 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, to: impl AsRef) { + fs::rename(self.path().join(from), self.path().join(to)).unwrap(); + } + + pub fn write(&self, path: impl AsRef, text: impl AsRef) { + fs::write(self.path().join(path), text.as_ref()).unwrap(); + } } -- cgit v1.2.3