summaryrefslogtreecommitdiff
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
parente4a9e9fd71d1a5867a872246bf8b84f8a3d51ee3 (diff)
downloadobnam-benchmark-729afd43e10c69da322d751dc98c9d81907d71f0.tar.gz
test: add Subplot scenario for a smoke test
Sponsored-by: author
-rw-r--r--obnam-benchmark.md21
-rw-r--r--subplot/benchmark.rs33
-rw-r--r--subplot/benchmark.yaml5
3 files changed, 53 insertions, 6 deletions
diff --git a/obnam-benchmark.md b/obnam-benchmark.md
index 076255d..709260d 100644
--- a/obnam-benchmark.md
+++ b/obnam-benchmark.md
@@ -115,3 +115,24 @@ benchmarks:
}
```
+
+## Smoke test to run a trivial benchmark
+
+_Requirement: The benchmark tool can benchmarks at all._
+
+We verify this by running a trivial benchmark, which backs up an
+empty directory.
+
+~~~scenario
+given an installed Rust program obnam-benchmark
+given file smoke.yaml
+when I run obnam-benchmark run smoke.yaml --output smoke.json
+then file smoke.json is valid JSON
+~~~
+
+```{#smoke.yaml .yaml .file .numberLines}
+benchmarks:
+- benchmark: smoke
+ backups:
+ - changes: []
+```
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