From f059ce44cda9f5b97fec791bd8b0dd58ee94ab74 Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Tue, 18 Oct 2022 10:22:41 +0300 Subject: feat: have Rust lib/files steps for verifying file contents dump it When a step check that a file contents fulfills a requirement, write it to stdout if it doesn't. This helps debug failing scenarios. Sponsored-by: author --- subplotlib/src/steplibrary/files.rs | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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"); } } -- cgit v1.2.1