summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers+gitlab@digital-scurf.org>2022-10-18 07:55:19 +0000
committerDaniel Silverstone <dsilvers+gitlab@digital-scurf.org>2022-10-18 07:55:19 +0000
commit18dedca71451dab31f43a0725277308471d32dfe (patch)
tree42cac30cd1afb3962b612d5e8a62e5acd113ab51
parent1647ca0cc4d734e79bad2d8493cd5dd103d6a4be (diff)
parentf059ce44cda9f5b97fec791bd8b0dd58ee94ab74 (diff)
downloadsubplot-18dedca71451dab31f43a0725277308471d32dfe.tar.gz
Merge branch 'liw/files-debug' into 'main'
feat: have Rust lib/files steps for verifying file contents dump it Closes #299 See merge request subplot/subplot!292
-rw-r--r--subplotlib/src/steplibrary/files.rs13
1 files changed, 13 insertions, 0 deletions
diff --git a/subplotlib/src/steplibrary/files.rs b/subplotlib/src/steplibrary/files.rs
index 1a55f7a..09cde56 100644
--- a/subplotlib/src/steplibrary/files.rs
+++ b/subplotlib/src/steplibrary/files.rs
@@ -233,6 +233,7 @@ pub fn file_contains(context: &Datadir, filename: &str, data: &str) {
let full_path = context.canonicalise_filename(filename)?;
let body = fs::read_to_string(full_path)?;
if !body.contains(data) {
+ println!("file {} contains:\n{}", filename, body);
throw!("expected file content not found");
}
}
@@ -248,6 +249,7 @@ pub fn file_doesnt_contain(context: &Datadir, filename: &str, data: &str) {
let full_path = context.canonicalise_filename(filename)?;
let body = fs::read_to_string(full_path)?;
if body.contains(data) {
+ println!("file {} contains:\n{}", filename, body);
throw!("unexpected file content found");
}
}
@@ -265,6 +267,7 @@ pub fn file_matches_regex(context: &Datadir, filename: &str, regex: &str) {
let regex = Regex::new(regex)?;
let body = fs::read_to_string(full_path)?;
if !regex.is_match(&body) {
+ println!("file {} contains:\n{}", filename, body);
throw!("file content does not match given regex");
}
}
@@ -281,6 +284,16 @@ pub fn file_match(context: &Datadir, filename1: &str, filename2: &str) {
let body1 = fs::read(full_path1)?;
let body2 = fs::read(full_path2)?;
if body1 != body2 {
+ println!(
+ "file {} contains:\n{}",
+ filename1,
+ String::from_utf8_lossy(&body1)
+ );
+ println!(
+ "file {} contains:\n{}",
+ filename2,
+ String::from_utf8_lossy(&body2)
+ );
throw!("file contents do not match each other");
}
}