summaryrefslogtreecommitdiff
path: root/tests/util/server/src/fs.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/util/server/src/fs.rs')
-rw-r--r--tests/util/server/src/fs.rs9
1 files changed, 9 insertions, 0 deletions
diff --git a/tests/util/server/src/fs.rs b/tests/util/server/src/fs.rs
index b9ae81b49..558d25ffb 100644
--- a/tests/util/server/src/fs.rs
+++ b/tests/util/server/src/fs.rs
@@ -150,24 +150,29 @@ impl PathRef {
.unwrap_or_else(|| panic!("JSON file was empty for {}", self))
}
+ #[track_caller]
pub fn rename(&self, to: impl AsRef<Path>) {
fs::rename(self, self.join(to)).unwrap();
}
+ #[track_caller]
pub fn append(&self, text: impl AsRef<str>) {
let mut file = OpenOptions::new().append(true).open(self).unwrap();
file.write_all(text.as_ref().as_bytes()).unwrap();
}
+ #[track_caller]
pub fn write(&self, text: impl AsRef<[u8]>) {
fs::write(self, text).unwrap();
}
+ #[track_caller]
pub fn write_json<TValue: Serialize>(&self, value: &TValue) {
let text = serde_json::to_string_pretty(value).unwrap();
self.write(text);
}
+ #[track_caller]
pub fn symlink_dir(
&self,
oldpath: impl AsRef<Path>,
@@ -187,6 +192,7 @@ impl PathRef {
}
}
+ #[track_caller]
pub fn symlink_file(
&self,
oldpath: impl AsRef<Path>,
@@ -206,12 +212,14 @@ impl PathRef {
}
}
+ #[track_caller]
pub fn read_dir(&self) -> fs::ReadDir {
fs::read_dir(self.as_path())
.with_context(|| format!("Reading {}", self.as_path().display()))
.unwrap()
}
+ #[track_caller]
pub fn copy(&self, to: &impl AsRef<Path>) {
std::fs::copy(self.as_path(), to)
.with_context(|| format!("Copying {} to {}", self, to.as_ref().display()))
@@ -247,6 +255,7 @@ impl PathRef {
}
}
+ #[track_caller]
pub fn make_dir_readonly(&self) {
self.create_dir_all();
if cfg!(windows) {