summaryrefslogtreecommitdiff
path: root/test_util/src/fs.rs
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-07-26 17:23:07 -0400
committerGitHub <noreply@github.com>2023-07-26 17:23:07 -0400
commitcf16df00d9ba87de643abc6d80c860a2733917cc (patch)
treed8e17df213941675c8eecba89931b8417cd0367f /test_util/src/fs.rs
parent53e077133f9c95e4ed23d838129158b6e4b88d6f (diff)
fix(check): should bust check cache when json module or npm resolution changes (#19941)
A small part of #19928.
Diffstat (limited to 'test_util/src/fs.rs')
-rw-r--r--test_util/src/fs.rs11
1 files changed, 11 insertions, 0 deletions
diff --git a/test_util/src/fs.rs b/test_util/src/fs.rs
index 2a64fb9c4..005c467a6 100644
--- a/test_util/src/fs.rs
+++ b/test_util/src/fs.rs
@@ -10,6 +10,8 @@ use std::sync::Arc;
use anyhow::Context;
use lsp_types::Url;
+use serde::de::DeserializeOwned;
+use serde::Serialize;
use crate::assertions::assert_wildcard_match;
@@ -110,6 +112,10 @@ impl PathRef {
.with_context(|| format!("Could not read file: {}", self))
}
+ pub fn read_json<TValue: DeserializeOwned>(&self) -> TValue {
+ serde_json::from_str(&self.read_to_string()).unwrap()
+ }
+
pub fn rename(&self, to: impl AsRef<Path>) {
fs::rename(self, self.join(to)).unwrap();
}
@@ -118,6 +124,11 @@ impl PathRef {
fs::write(self, text.as_ref()).unwrap();
}
+ pub fn write_json<TValue: Serialize>(&self, value: &TValue) {
+ let text = serde_json::to_string_pretty(value).unwrap();
+ self.write(text);
+ }
+
pub fn symlink_dir(
&self,
oldpath: impl AsRef<Path>,