diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-12-05 11:27:51 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-12-05 11:27:51 +0200 |
commit | 131e0f8fec6bbce21dc66fbdd5f2140834199cf2 (patch) | |
tree | 93ce26c4e0f62ae46841c15a12acf1f385446641 /subplot | |
parent | 0cdf96eaf0782021a0bade74d742bf70c1569244 (diff) | |
download | obnam-benchmark-131e0f8fec6bbce21dc66fbdd5f2140834199cf2.tar.gz |
fix: make first scenario work
Sponsored-by: author
Diffstat (limited to 'subplot')
-rw-r--r-- | subplot/benchmark.rs | 31 | ||||
-rw-r--r-- | subplot/benchmark.yaml | 5 |
2 files changed, 34 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, + ); +} diff --git a/subplot/benchmark.yaml b/subplot/benchmark.yaml index 079abd2..b0e6727 100644 --- a/subplot/benchmark.yaml +++ b/subplot/benchmark.yaml @@ -2,3 +2,8 @@ impl: rust: function: install_rust_program + +- then: JSON files {first} and {second} match + impl: + rust: + function: json_files_match |