summaryrefslogtreecommitdiff
path: root/test_util/src
diff options
context:
space:
mode:
authorDavid Sherret <dsherret@users.noreply.github.com>2023-06-26 21:53:17 +0200
committerGitHub <noreply@github.com>2023-06-26 15:53:17 -0400
commita8d472f88e79703b1890bfdc87d7a3bb20b21428 (patch)
treed2c2daf1261d6dbcce7852368550d56c134bc97e /test_util/src
parentfa935e553a9ec37d39d2274432a00f1b465cef0f (diff)
feat(lock): skip saving declaration files in the lockfile (#19447)
This is also a performance improvement because declaration file hashes don't need to be stored in the lockfile. Closes #19444
Diffstat (limited to 'test_util/src')
-rw-r--r--test_util/src/assertions.rs11
-rw-r--r--test_util/src/builders.rs17
-rw-r--r--test_util/src/fs.rs17
3 files changed, 30 insertions, 15 deletions
diff --git a/test_util/src/assertions.rs b/test_util/src/assertions.rs
index 29066ded0..239e0e99c 100644
--- a/test_util/src/assertions.rs
+++ b/test_util/src/assertions.rs
@@ -49,3 +49,14 @@ macro_rules! assert_not_contains {
}
}
}
+
+#[track_caller]
+pub fn assert_wildcard_match(actual: &str, expected: &str) {
+ if !expected.contains("[WILDCARD]") {
+ pretty_assertions::assert_eq!(actual, expected);
+ } else if !crate::wildcard_match(expected, actual) {
+ println!("OUTPUT START\n{actual}\nOUTPUT END");
+ println!("EXPECTED START\n{expected}\nEXPECTED END");
+ panic!("pattern match failed");
+ }
+}
diff --git a/test_util/src/builders.rs b/test_util/src/builders.rs
index 324d30e94..48c001a7e 100644
--- a/test_util/src/builders.rs
+++ b/test_util/src/builders.rs
@@ -12,8 +12,8 @@ use std::process::Stdio;
use std::rc::Rc;
use os_pipe::pipe;
-use pretty_assertions::assert_eq;
+use crate::assertions::assert_wildcard_match;
use crate::deno_exe_path;
use crate::env_vars_for_npm_tests_no_sync_download;
use crate::fs::PathRef;
@@ -23,7 +23,6 @@ use crate::new_deno_dir;
use crate::pty::Pty;
use crate::strip_ansi_codes;
use crate::testdata_path;
-use crate::wildcard_match;
use crate::HttpServerGuard;
use crate::TempDir;
@@ -660,14 +659,7 @@ impl TestCommandOutput {
actual: &str,
expected: impl AsRef<str>,
) -> &Self {
- let expected = expected.as_ref();
- if !expected.contains("[WILDCARD]") {
- assert_eq!(actual, expected);
- } else if !wildcard_match(expected, actual) {
- println!("OUTPUT START\n{actual}\nOUTPUT END");
- println!("EXPECTED START\n{expected}\nEXPECTED END");
- panic!("pattern match failed");
- }
+ assert_wildcard_match(actual, expected.as_ref());
self
}
@@ -679,10 +671,7 @@ impl TestCommandOutput {
) -> &Self {
let output_path = self.testdata_dir().join(file_path);
println!("output path {}", output_path);
- let expected_text =
- std::fs::read_to_string(&output_path).unwrap_or_else(|err| {
- panic!("failed loading {}\n\n{err:#}", output_path)
- });
+ let expected_text = output_path.read_to_string();
self.inner_assert_matches_text(actual, expected_text)
}
}
diff --git a/test_util/src/fs.rs b/test_util/src/fs.rs
index 12750ffa4..f9443c9c5 100644
--- a/test_util/src/fs.rs
+++ b/test_util/src/fs.rs
@@ -11,6 +11,8 @@ use std::sync::Arc;
use anyhow::Context;
use lsp_types::Url;
+use crate::assertions::assert_wildcard_match;
+
/// Represents a path on the file system, which can be used
/// to perform specific actions.
#[derive(Clone, Debug, Default, PartialEq, Eq)]
@@ -105,7 +107,7 @@ impl PathRef {
pub fn read_to_string_if_exists(&self) -> Result<String, anyhow::Error> {
fs::read_to_string(self)
- .with_context(|| format!("Could not find file: {}", self))
+ .with_context(|| format!("Could not read file: {}", self))
}
pub fn rename(&self, to: impl AsRef<Path>) {
@@ -195,6 +197,19 @@ impl PathRef {
Command::new("chmod").arg("555").arg(self).output().unwrap();
}
}
+
+ pub fn assert_matches_file(&self, wildcard_file: impl AsRef<Path>) -> &Self {
+ let wildcard_file = PathRef::new(wildcard_file);
+ println!("output path {}", wildcard_file);
+ let expected_text = wildcard_file.read_to_string();
+ self.assert_matches_text(&expected_text)
+ }
+
+ pub fn assert_matches_text(&self, wildcard_text: impl AsRef<str>) -> &Self {
+ let actual = self.read_to_string();
+ assert_wildcard_match(&actual, wildcard_text.as_ref());
+ self
+ }
}
#[cfg(not(windows))]