summaryrefslogtreecommitdiff
path: root/subplot/benchmark.rs
diff options
context:
space:
mode:
Diffstat (limited to 'subplot/benchmark.rs')
-rw-r--r--subplot/benchmark.rs33
1 files changed, 27 insertions, 6 deletions
diff --git a/subplot/benchmark.rs b/subplot/benchmark.rs
index 7ea4a94..566ce30 100644
--- a/subplot/benchmark.rs
+++ b/subplot/benchmark.rs
@@ -33,13 +33,15 @@ fn install_rust_program(context: &ScenarioContext) {
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 first = context
+ .canonicalise_filename(&first)
+ .expect("can't use first filename");
+ let first = read_json_file(&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)?;
+ let second = context
+ .canonicalise_filename(&second)
+ .expect("can't use second filename");
+ let second = read_json_file(&second)?;
if first != second {
eprintln!("JSON files differ:\n{:#?}\n\n{:#?}\n", first, second,);
@@ -51,3 +53,22 @@ fn json_files_match(context: &ScenarioContext, first: &str, second: &str) {
false,
);
}
+
+#[step]
+#[context(Datadir)]
+#[context(SubplotContext)]
+fn file_is_valid_json(context: &ScenarioContext, filename: &str) {
+ context.with(
+ |context: &Datadir| {
+ let filename = context.canonicalise_filename(&filename)?;
+ read_json_file(&filename)?;
+ Ok(())
+ },
+ false,
+ )?;
+}
+
+fn read_json_file(filename: &Path) -> anyhow::Result<Value> {
+ let file = File::open(filename)?;
+ Ok(serde_json::from_reader(&file)?)
+}