summaryrefslogtreecommitdiff
path: root/src/bin/subplot.rs
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2021-10-05 12:02:56 +0300
committerLars Wirzenius <liw@liw.fi>2021-10-13 10:04:59 +0300
commit5855c963b8c1e1748f50301ddcc21a923be60240 (patch)
tree2b53f37057da8b93e9b67250de9104d7c0883795 /src/bin/subplot.rs
parent2459137129c64e02a2948f6c5f9e17bf56742c64 (diff)
downloadsubplot-5855c963b8c1e1748f50301ddcc21a923be60240.tar.gz
feat: add crate subplot-build for using Subplot from build.rs
Make it easy to generate test code from a subplot in another project's `build.rs` script. Move the code to load documents and generate test code from src/bin/subplot.rs and src/bin/cli/mod.rs to src/doc.rs so it can be used without using the subplot executable. Make the add_search_path function public so it can be used outside its module. The subplot executable arranged for the directory where the markdown input file resides to be added to the search path via another way. Sponsored-by: pep.foundation
Diffstat (limited to 'src/bin/subplot.rs')
-rw-r--r--src/bin/subplot.rs34
1 files changed, 7 insertions, 27 deletions
diff --git a/src/bin/subplot.rs b/src/bin/subplot.rs
index 3e865fb..8d4a660 100644
--- a/src/bin/subplot.rs
+++ b/src/bin/subplot.rs
@@ -5,9 +5,7 @@ use anyhow::Result;
use chrono::{Local, TimeZone};
use structopt::StructOpt;
-use subplot::{
- generate_test_program, resource, template_spec, DataFile, Document, MarkupOpts, Style,
-};
+use subplot::{codegen, load_document, resource, DataFile, Document, MarkupOpts, Style};
use tracing::{event, instrument, span, Level, Subscriber};
use std::convert::TryFrom;
@@ -162,7 +160,7 @@ impl Extract {
fn run(&self) -> Result<()> {
let span = span!(Level::TRACE, "extract");
let _enter = span.enter();
- let doc = cli::load_document(&self.filename, Style::default())?;
+ let doc = load_document(&self.filename, Style::default())?;
let files: Vec<&DataFile> = if self.embedded.is_empty() {
doc.files()
@@ -268,7 +266,7 @@ impl Metadata {
fn run(&self) -> Result<()> {
let span = span!(Level::TRACE, "metadata");
let _enter = span.enter();
- let mut doc = cli::load_document(&self.filename, Style::default())?;
+ let mut doc = load_document(&self.filename, Style::default())?;
let meta = cli::Metadata::try_from(&mut doc)?;
match self.output_format {
cli::OutputFormat::Plain => meta.write_out(),
@@ -310,7 +308,7 @@ impl Docgen {
event!(Level::TRACE, "PDF output chosen");
style.typeset_links_as_notes();
}
- let mut doc = cli::load_document(&self.input, style)?;
+ let mut doc = load_document(&self.input, style)?;
event!(Level::TRACE, "Got doc, now linting it");
doc.lint()?;
event!(Level::TRACE, "Doc linted ok");
@@ -415,32 +413,14 @@ impl Codegen {
fn run(&self) -> Result<()> {
let span = span!(Level::TRACE, "codegen");
let _enter = span.enter();
- let mut doc = cli::load_document_with_pullmark(&self.filename, Style::default())?;
- doc.lint()?;
- let template = doc
- .meta()
- .template_name()
- .ok_or_else(|| anyhow::anyhow!("No template name given"))?
- .to_string();
- event!(Level::TRACE, ?template);
- if !doc.check_named_files_exist(&template)? || !doc.check_matched_steps_have_impl(&template)
- {
- event!(Level::ERROR, "Found problems in document, cannot continue");
- eprintln!("Unable to continue");
- std::process::exit(1);
- }
-
- event!(Level::TRACE, "Generating code");
- let spec = template_spec(&doc)?;
- generate_test_program(&mut doc, &spec, &self.output, &template)?;
- event!(Level::TRACE, "Finished generating code");
+ let output = codegen(&self.filename, &self.output)?;
if self.run {
- let run = match spec.run() {
+ let run = match output.spec.run() {
None => {
eprintln!(
"Template {} does not specify how to run suites",
- spec.template_filename().display()
+ output.spec.template_filename().display()
);
std::process::exit(1);
}