diff options
author | Lars Wirzenius <liw@liw.fi> | 2023-11-11 16:09:12 +0000 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-11-11 16:09:12 +0000 |
commit | add9bdb828833e6086b6f49df98fc655be897875 (patch) | |
tree | c5e2a24cc5e6368b21e237298b2bf584c37be321 | |
parent | ef9d59ae8b2529d71c3d4a732751c5b1cbec322a (diff) | |
parent | 2bf14f68ec463a30d2806b67158a64459b47a301 (diff) | |
download | subplot-add9bdb828833e6086b6f49df98fc655be897875.tar.gz |
Merge branch 'fix-320' into 'main'
Make bindings parsing more strict, and validate that strictness
Closes #320
See merge request subplot/subplot!364
-rw-r--r-- | src/bindings.rs | 6 | ||||
-rw-r--r-- | subplot.md | 68 |
2 files changed, 72 insertions, 2 deletions
diff --git a/src/bindings.rs b/src/bindings.rs index 5fe5887..380b0ed 100644 --- a/src/bindings.rs +++ b/src/bindings.rs @@ -423,13 +423,14 @@ pub struct Bindings { } #[derive(Debug, Deserialize)] +#[serde(deny_unknown_fields)] struct ParsedImpl { function: String, cleanup: Option<String>, } #[derive(Debug, Deserialize)] -#[serde(transparent)] +#[serde(transparent, deny_unknown_fields)] struct ParsedImplWrapper { #[serde(deserialize_with = "deserialize_struct_case_insensitive")] pimpl: ParsedImpl, @@ -444,6 +445,7 @@ impl Deref for ParsedImplWrapper { } #[derive(Debug, Deserialize)] +#[serde(deny_unknown_fields)] struct ParsedBinding { given: Option<String>, when: Option<String>, @@ -459,7 +461,7 @@ struct ParsedBinding { } #[derive(Debug, Deserialize)] -#[serde(transparent)] +#[serde(transparent, deny_unknown_fields)] struct ParsedBindingWrapper { #[serde(deserialize_with = "deserialize_struct_case_insensitive")] binding: ParsedBinding, @@ -812,6 +812,74 @@ given file missing.md ~~~ +### Bindings file strictness - given when then + +The bindings file is semi-strict. For example you must have only one +of `given`, `when`, or `then` in your binding. + + +```scenario +given file badbindingsgwt.subplot +and file badbindingsgwt.md +and file badbindingsgwt.yaml +and an installed subplot +when I try to run subplot docgen --output ignored.html badbindingsgwt.subplot +then command fails +and stderr contains "binding has more than one keyword" +``` + +~~~{#badbindingsgwt.subplot .file .yaml .numberLines} +title: Bad bindings cause everything to fail +markdowns: [badbindingsgwt.md] +bindings: [badbindingsgwt.yaml] +~~~ + +~~~{#badbindingsgwt.md .file .markdown .numberLines} +# Bad bindings +```scenario +given we won't reach here +``` +~~~ + +~~~{#badbindingsgwt.yaml .file .yaml .numberLines} +- given: we won't reach here + then: we won't reach here +~~~ + +### Bindings file strictness - unknown field + +The bindings file is semi-strict. For example, you must not have keys +in the bindings file which are not known to Subplot. + + +```scenario +given file badbindingsuf.subplot +and file badbindingsuf.md +and file badbindingsuf.yaml +and an installed subplot +when I try to run subplot docgen --output ignored.html badbindingsuf.subplot +then command fails +and stderr contains "unknown field `function`" +``` + +~~~{#badbindingsuf.subplot .file .yaml .numberLines} +title: Bad bindings cause everything to fail +markdowns: [badbindingsuf.md] +bindings: [badbindingsuf.yaml] +~~~ + +~~~{#badbindingsuf.md .file .markdown .numberLines} +# Bad bindings +```scenario +given we won't reach here +``` +~~~ + +~~~{#badbindingsuf.yaml .file .yaml .numberLines} +- given: we won't reach here + function: old_school_function +~~~ + ## Functions file Functions implementing steps are supported in Bash and Python. The |