summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers+gitlab@digital-scurf.org>2023-05-15 07:44:21 +0000
committerDaniel Silverstone <dsilvers+gitlab@digital-scurf.org>2023-05-15 07:44:21 +0000
commit18c50cafb77fe5ebdeae65048c7327c4d7bda04d (patch)
treee44c6b885dc03e3f3ff9a16cf75d63e84caee256
parent5b30f07a5989769397de7441ac9440e379a53488 (diff)
parent113ed1a871fddae8ccf942c19fe6737106fb3e84 (diff)
downloadsubplot-18c50cafb77fe5ebdeae65048c7327c4d7bda04d.tar.gz
Merge branch 'liw/dup-scenario' into 'main'
feat: check for duplicate scenario titles See merge request subplot/subplot!329
-rw-r--r--src/doc.rs13
-rw-r--r--src/error.rs7
-rw-r--r--subplot.md42
3 files changed, 62 insertions, 0 deletions
diff --git a/src/doc.rs b/src/doc.rs
index 640968c..f08f795 100644
--- a/src/doc.rs
+++ b/src/doc.rs
@@ -265,12 +265,25 @@ impl Document {
pub fn lint(&self) -> Result<(), SubplotError> {
trace!("Linting document");
self.check_doc_has_title()?;
+ self.check_scenarios_are_unique()?;
self.check_filenames_are_unique()?;
self.check_block_classes()?;
trace!("No linting problems found");
Ok(())
}
+ // Check that all titles for scenarios are unique.
+ fn check_scenarios_are_unique(&self) -> Result<(), SubplotError> {
+ let mut known = HashSet::new();
+ for title in self.scenarios()?.iter().map(|s| s.title().to_lowercase()) {
+ if known.contains(&title) {
+ return Err(SubplotError::DuplicateScenario(title));
+ }
+ known.insert(title);
+ }
+ Ok(())
+ }
+
// Check that all filenames for embedded files are unique.
fn check_filenames_are_unique(&self) -> Result<(), SubplotError> {
let mut known = HashSet::new();
diff --git a/src/error.rs b/src/error.rs
index a322bd6..f7dfe52 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -173,6 +173,13 @@ pub enum SubplotError {
#[error("continuation keyword used too early")]
ContinuationTooEarly,
+ /// Scenario has the same title as another scenario
+ ///
+ /// Titles of scenarios must be unique in the input document,
+ /// but Subplot found at least one with the same title as another.
+ #[error("Scenario title is duplicate: {0:?}")]
+ DuplicateScenario(String),
+
/// Embedded file has the same name as another embedded file
///
/// Names of embedded files must be unique in the input document,
diff --git a/subplot.md b/subplot.md
index 8556afd..9929e8b 100644
--- a/subplot.md
+++ b/subplot.md
@@ -1309,6 +1309,48 @@ then bar was done
```
~~~~
+## Duplicate scenario titles
+
+_Requirement: Subplot treats it as an error if two scenarios have the
+same title._
+
+Justification: the title is how a scenario is identified, and the user
+needs to be able to do so unambiguously.
+
+~~~scenario
+given file duplicate-scenario-titles.subplot
+given file duplicate-scenario-titles.md
+given file b.yaml
+given file f.py
+given an installed subplot
+when I try to run subplot metadata duplicate-scenario-titles.subplot
+then command fails
+then stderr contains "duplicate"
+~~~
+
+~~~~{#duplicate-scenario-titles.subplot .file .yaml .numberLines}
+title: Test scenario
+markdowns:
+- duplicate-scenario-titles.md
+bindings: [b.yaml]
+impls:
+ python: [f.py]
+~~~~
+
+~~~~{#duplicate-scenario-titles.md .file .markdown .numberLines}
+# My sceanrio
+
+```scenario
+when I do bar
+```
+
+# My sceanrio
+
+```scenario
+when I do bar
+```
+~~~~
+
## Empty lines in scenarios
This scenario verifies that empty lines in scenarios are OK.