diff options
author | Lars Wirzenius <liw@liw.fi> | 2022-03-24 07:41:47 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2022-03-25 07:22:50 +0200 |
commit | 2937d00329ec9fbd632ffdd9265183919172905d (patch) | |
tree | d539bc85ed4b794b96ada0c869a06590b206545b /subplotlib | |
parent | 0b7adc238746b3d4c974775a8b13fbb81cb2eda9 (diff) | |
download | subplot-2937d00329ec9fbd632ffdd9265183919172905d.tar.gz |
feat: add "file doesn't contain" step to lib/files, Python and Rust
Sponsored-by: author
Diffstat (limited to 'subplotlib')
-rw-r--r-- | subplotlib/src/steplibrary/files.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/subplotlib/src/steplibrary/files.rs b/subplotlib/src/steplibrary/files.rs index fd84e1c..b94155f 100644 --- a/subplotlib/src/steplibrary/files.rs +++ b/subplotlib/src/steplibrary/files.rs @@ -232,6 +232,21 @@ pub fn file_contains(context: &Datadir, filename: &str, data: &str) { } } +/// Check if a file lacks a given sequence of characters +/// +/// # `then file (?P<filename>\S+) does not contain "(?P<data>.*)"` +/// +/// This will load the content of the named file and ensure it lacks the given string. +/// Note: this assumes everything is utf-8 encoded. If not, things will fail. +#[step] +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) { + throw!("unexpected file content found"); + } +} + /// Check if a file's content matches the given regular expression /// /// # `then file (?P<filename>\S+) matches regex /(?P<regex>.*)/` |