diff options
author | Daniel Silverstone <dsilvers@digital-scurf.org> | 2023-02-25 14:51:44 +0000 |
---|---|---|
committer | Daniel Silverstone <dsilvers@digital-scurf.org> | 2023-02-25 14:51:44 +0000 |
commit | 3ccd4398b7a2d42b574bfdd8baed8e665c0d1cca (patch) | |
tree | 09a8f5307f193892de951ae0c3a21c35b698921d /src/doc.rs | |
parent | 7e02c646edb95ddb4cf2aceeb67888b9d420d930 (diff) | |
download | subplot-3ccd4398b7a2d42b574bfdd8baed8e665c0d1cca.tar.gz |
(doc, md, bin): Update APIs so warnings are externally accumulated
Signed-off-by: Daniel Silverstone <dsilvers@digital-scurf.org>
Diffstat (limited to 'src/doc.rs')
-rw-r--r-- | src/doc.rs | 42 |
1 files changed, 20 insertions, 22 deletions
@@ -68,7 +68,6 @@ pub struct Document { meta: Metadata, files: EmbeddedFiles, style: Style, - warnings: Warnings, } impl Document { @@ -85,17 +84,11 @@ impl Document { meta, files, style, - warnings: Warnings::default(), }; trace!("Document::new -> {:#?}", doc); doc } - /// Return all warnings about this document. - pub fn warnings(&self) -> &[Warning] { - self.warnings.warnings() - } - fn from_ast<P>( basedir: P, subplot: PathBuf, @@ -266,7 +259,11 @@ impl Document { /// Check that all named files (in matched steps) are actually present in the /// document. - pub fn check_named_files_exist(&mut self, template: &str) -> Result<bool, SubplotError> { + pub fn check_named_files_exist( + &self, + template: &str, + warnings: &mut Warnings, + ) -> Result<bool, SubplotError> { let filenames: HashSet<_> = self .files() .iter() @@ -285,7 +282,7 @@ impl Document { if matches!(step.types().get(name.as_str()), Some(CaptureType::File)) && !filenames.contains(&text.to_lowercase()) { - self.warnings.push(Warning::UnknownEmbeddedFile( + warnings.push(Warning::UnknownEmbeddedFile( scenario.title().to_string(), text.to_string(), )); @@ -299,7 +296,11 @@ impl Document { } /// Check that all embedded files are used by matched steps. - pub fn check_embedded_files_are_used(&mut self, template: &str) -> Result<bool, SubplotError> { + pub fn check_embedded_files_are_used( + &self, + template: &str, + warnings: &mut Warnings, + ) -> Result<bool, SubplotError> { let mut filenames: HashSet<_> = self .files() .iter() @@ -322,8 +323,7 @@ impl Document { } } for filename in filenames.iter() { - self.warnings - .push(Warning::UnusedEmbeddedFile(filename.to_string())); + warnings.push(Warning::UnusedEmbeddedFile(filename.to_string())); } // We always succeed. Subplot's own subplot had valid cases of @@ -334,7 +334,7 @@ impl Document { } /// Check that all matched steps actually have function implementations - pub fn check_matched_steps_have_impl(&mut self, template: &str) -> bool { + pub fn check_matched_steps_have_impl(&self, template: &str, warnings: &mut Warnings) -> bool { trace!("Checking that steps have implementations"); let mut okay = true; let scenarios = match self.matched_scenarios(template) { @@ -347,7 +347,7 @@ impl Document { for step in scenario.steps() { if step.function().is_none() { trace!("Missing step implementation: {:?}", step.text()); - self.warnings.push(Warning::MissingStepImplementation( + warnings.push(Warning::MissingStepImplementation( scenario.title().to_string(), step.text().to_string(), )); @@ -359,11 +359,8 @@ impl Document { } /// Typeset a Subplot document. - pub fn typeset(&mut self) { - let warnings = self.md.typeset(self.style.clone(), self.meta.bindings()); - for w in warnings { - self.warnings.push(w); - } + pub fn typeset(&mut self, warnings: &mut Warnings) { + warnings.push_all(self.md.typeset(self.style.clone(), self.meta.bindings())); } /// Return all scenarios in a document. @@ -478,9 +475,10 @@ pub fn codegen( if !doc.meta().templates().any(|t| t == template) { return Err(SubplotError::TemplateSupportNotPresent); } - if !doc.check_named_files_exist(&template)? - || !doc.check_matched_steps_have_impl(&template) - || !doc.check_embedded_files_are_used(&template)? + let mut warnings = Warnings::default(); + if !doc.check_named_files_exist(&template, &mut warnings)? + || !doc.check_matched_steps_have_impl(&template, &mut warnings) + || !doc.check_embedded_files_are_used(&template, &mut warnings)? { error!("Found problems in document, cannot continue"); std::process::exit(1); |