diff options
Diffstat (limited to 'subplot/benchmark.rs')
-rw-r--r-- | subplot/benchmark.rs | 31 |
1 files changed, 29 insertions, 2 deletions
diff --git a/subplot/benchmark.rs b/subplot/benchmark.rs index 1a64ecc..7ea4a94 100644 --- a/subplot/benchmark.rs +++ b/subplot/benchmark.rs @@ -1,8 +1,10 @@ // Implementations of Subplot scenario steps for sshca.md. -use subplotlib::steplibrary::runcmd::Runcmd; - +use serde_json::value::Value; +use std::fs::File; use std::path::Path; +use subplotlib::steplibrary::datadir::Datadir; +use subplotlib::steplibrary::runcmd::Runcmd; #[derive(Default)] struct SubplotContext {} @@ -24,3 +26,28 @@ fn install_rust_program(context: &ScenarioContext) { false, )?; } + +#[step] +#[context(Datadir)] +#[context(SubplotContext)] +fn json_files_match(context: &ScenarioContext, first: &str, second: &str) { + context.with( + |context: &Datadir| { + let first = context.canonicalise_filename(&first).expect("can't use first filename"); + let first = File::open(&first)?; + let first: Value = serde_json::from_reader(&first)?; + + let second = context.canonicalise_filename(&second).expect("can't use second filename"); + let second = File::open(&second)?; + let second: Value = serde_json::from_reader(&second)?; + + if first != second { + eprintln!("JSON files differ:\n{:#?}\n\n{:#?}\n", first, second,); + panic!("ERROR: JSON files differ"); + }; + + Ok(()) + }, + false, + ); +} |