summaryrefslogtreecommitdiff
path: root/subplot
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-12-10 10:08:55 +0200
committerLars Wirzenius <liw@liw.fi>2021-12-10 10:08:55 +0200
commit729afd43e10c69da322d751dc98c9d81907d71f0 (patch)
tree7c985c8428edbcbd227c1c8f4b99e298282173ca /subplot
parente4a9e9fd71d1a5867a872246bf8b84f8a3d51ee3 (diff)
downloadobnam-benchmark-729afd43e10c69da322d751dc98c9d81907d71f0.tar.gz
test: add Subplot scenario for a smoke test
Sponsored-by: author
Diffstat (limited to 'subplot')
-rw-r--r--subplot/benchmark.rs33
-rw-r--r--subplot/benchmark.yaml5
2 files changed, 32 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)?)
+}
diff --git a/subplot/benchmark.yaml b/subplot/benchmark.yaml
index b0e6727..70ebb54 100644
--- a/subplot/benchmark.yaml
+++ b/subplot/benchmark.yaml
@@ -7,3 +7,8 @@
impl:
rust:
function: json_files_match
+
+- then: file {filename} is valid JSON
+ impl:
+ rust:
+ function: file_is_valid_json