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.rs34
1 files changed, 30 insertions, 4 deletions
diff --git a/tests/util/server/src/fs.rs b/tests/util/server/src/fs.rs
index d99572b06..fb3e36ab6 100644
--- a/tests/util/server/src/fs.rs
+++ b/tests/util/server/src/fs.rs
@@ -2,6 +2,7 @@
use pretty_assertions::assert_eq;
use std::borrow::Cow;
+use std::collections::HashSet;
use std::ffi::OsStr;
use std::fs;
use std::fs::OpenOptions;
@@ -21,7 +22,7 @@ use crate::testdata_path;
/// Represents a path on the file system, which can be used
/// to perform specific actions.
-#[derive(Clone, Debug, Default, PartialEq, Eq)]
+#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct PathRef(PathBuf);
impl AsRef<Path> for PathRef {
@@ -124,12 +125,29 @@ impl PathRef {
fs::read(self).with_context(|| format!("Could not read file: {}", self))
}
+ #[track_caller]
pub fn read_json<TValue: DeserializeOwned>(&self) -> TValue {
- serde_json::from_str(&self.read_to_string()).unwrap()
+ serde_json::from_str(&self.read_to_string())
+ .with_context(|| format!("Failed deserializing: {}", self))
+ .unwrap()
}
+ #[track_caller]
pub fn read_json_value(&self) -> serde_json::Value {
- serde_json::from_str(&self.read_to_string()).unwrap()
+ serde_json::from_str(&self.read_to_string())
+ .with_context(|| format!("Failed deserializing: {}", self))
+ .unwrap()
+ }
+
+ #[track_caller]
+ pub fn read_jsonc_value(&self) -> serde_json::Value {
+ jsonc_parser::parse_to_serde_value(
+ &self.read_to_string(),
+ &Default::default(),
+ )
+ .with_context(|| format!("Failed to parse {}", self))
+ .unwrap()
+ .expect("Found no value.")
}
pub fn rename(&self, to: impl AsRef<Path>) {
@@ -204,6 +222,14 @@ impl PathRef {
///
/// Note: Does not handle symlinks.
pub fn copy_to_recursive(&self, to: &PathRef) {
+ self.copy_to_recursive_with_exclusions(to, &HashSet::new())
+ }
+
+ pub fn copy_to_recursive_with_exclusions(
+ &self,
+ to: &PathRef,
+ file_exclusions: &HashSet<PathRef>,
+ ) {
to.create_dir_all();
let read_dir = self.read_dir();
@@ -215,7 +241,7 @@ impl PathRef {
if file_type.is_dir() {
new_from.copy_to_recursive(&new_to);
- } else if file_type.is_file() {
+ } else if file_type.is_file() && !file_exclusions.contains(&new_from) {
new_from.copy(&new_to);
}
}