diff options
Diffstat (limited to 'src/doc.rs')
-rw-r--r-- | src/doc.rs | 38 |
1 files changed, 25 insertions, 13 deletions
@@ -13,6 +13,7 @@ use crate::ScenarioStep; use crate::Style; use crate::{bindings::CaptureType, parser::parse_scenario_snippet}; use crate::{Result, SubplotError}; +use crate::{Warning, Warnings}; use std::collections::HashSet; use std::default::Default; @@ -83,6 +84,7 @@ pub struct Document { meta: Metadata, files: DataFiles, style: Style, + warnings: Warnings, } impl<'a> Document { @@ -99,9 +101,15 @@ impl<'a> Document { meta, files, style, + warnings: Warnings::default(), } } + /// Return all warnings about this document. + pub fn warnings(&self) -> &[Warning] { + self.warnings.warnings() + } + fn from_ast<P>( basedir: P, markdowns: Vec<PathBuf>, @@ -153,6 +161,11 @@ impl<'a> Document { style: Style, template: Option<&str>, ) -> Result<Document> { + trace!( + "Document::from_file: basedir={} filename={}", + basedir.display(), + filename.display() + ); let markdowns = vec![filename.to_path_buf()]; let mut pandoc = pandoc::new(); @@ -172,6 +185,7 @@ impl<'a> Document { pandoc::PandocOutput::ToBuffer(o) => o, _ => return Err(SubplotError::NotJson), }; + trace!("Pandoc was happy"); let doc = Document::from_json(basedir, markdowns, &output, style, template)?; trace!("Loaded document OK"); Ok(doc) @@ -344,7 +358,10 @@ impl<'a> Document { if matches!(step.types().get(name.as_str()), Some(CaptureType::File)) && !filenames.contains(&text.to_lowercase()) { - eprintln!("Found reference to unknown file {}", text); + self.warnings.push(Warning::UnknownEmbeddedFile( + scenario.title().to_string(), + text.to_string(), + )); okay = false; } } @@ -378,10 +395,8 @@ impl<'a> Document { } } for filename in filenames.iter() { - eprintln!( - "WARNING: embedded file is not used by any scenario: {}", - filename - ); + self.warnings + .push(Warning::UnusedEmbeddedFile(filename.to_string())); } // We always succeed. Subplot's own subplot had valid cases of @@ -402,16 +417,13 @@ impl<'a> Document { trace!("Found {} scenarios", scenarios.len()); for scenario in scenarios { trace!("Checking that steps in scenario"); - let mut said_scenario = false; for step in scenario.steps() { if step.function().is_none() { - if !said_scenario { - eprintln!("Scenario: '{}'", scenario.title()); - eprintln!(" Template: '{}'", template); - said_scenario = true; - } - eprintln!(" Step missing implementation: '{}'", step.text()); trace!("Missing step implementation: {:?}", step.text()); + self.warnings.push(Warning::MissingStepImplementation( + scenario.title().to_string(), + step.text().to_string(), + )); okay = false; } } @@ -424,6 +436,7 @@ impl<'a> Document { let mut visitor = visitor::TypesettingVisitor::new(self.style.clone(), self.meta.bindings()); visitor.walk_pandoc(&mut self.ast); + self.warnings.push_all(visitor.warnings()); } /// Return all scenarios in a document. @@ -618,7 +631,6 @@ mod test_extract { } fn check_result(r: Result<(Option<Scenario>, usize)>, title: Option<&str>, i: usize) { - eprintln!("checking result: {:?}", r); assert!(r.is_ok()); let (actual_scen, actual_i) = r.unwrap(); if title.is_none() { |