From 07fb523edb88ed258243869ab474ee7a24e1e4de Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 10 Dec 2021 09:05:11 +0200 Subject: test: add implementation, running of Subplot scenarios Sponsored-by: author --- build.rs | 7 +++++++ subplot/subplot.rs | 30 ++++++++++++++++++++++++++++++ subplot/subplot.yaml | 4 ++++ tests/subplot.rs | 1 + 4 files changed, 42 insertions(+) create mode 100644 build.rs create mode 100644 subplot/subplot.rs create mode 100644 subplot/subplot.yaml create mode 100644 tests/subplot.rs diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..fac2fff --- /dev/null +++ b/build.rs @@ -0,0 +1,7 @@ +use std::path::Path; + +fn main() { + println!("{:#?}", std::env::vars()); + subplot_build::codegen(Path::new("pandoc-filter-diagram.md")) + .expect("failed to generate code with Subplot"); +} diff --git a/subplot/subplot.rs b/subplot/subplot.rs new file mode 100644 index 0000000..1496154 --- /dev/null +++ b/subplot/subplot.rs @@ -0,0 +1,30 @@ +// Rust support for running Subplot scenarios for +// pandoc-filter-diagram. + +use subplotlib::steplibrary::runcmd::Runcmd; + +use std::env; +use std::path::Path; + +#[step] +#[context(Runcmd)] +fn install_rust_program(context: &ScenarioContext, name: &str) { + println!("install_rust_program 1"); + println!("install_rust_program: name={:?}", name); + let target_dir = Path::new(env!("CARGO_TARGET_DIR")); + let exe = target_dir.join("debug").join(name); + println!("install_rust_program: exe={:?} {}", exe, exe.exists()); + assert!(exe.exists()); + println!("install_rust_program 2"); + let path = Path::new(&exe).parent().ok_or("No parent?")?; + println!("install_rust_program 3"); + + context.with_mut( + |context: &mut Runcmd| { + context.prepend_to_path(path); + Ok(()) + }, + false, + )?; + println!("install_rust_program 999"); +} diff --git a/subplot/subplot.yaml b/subplot/subplot.yaml new file mode 100644 index 0000000..14f5856 --- /dev/null +++ b/subplot/subplot.yaml @@ -0,0 +1,4 @@ +- given: an installed Rust program {name} + impl: + rust: + function: install_rust_program diff --git a/tests/subplot.rs b/tests/subplot.rs new file mode 100644 index 0000000..465b459 --- /dev/null +++ b/tests/subplot.rs @@ -0,0 +1 @@ +include!(concat!(env!("OUT_DIR"), "/pandoc-filter-diagram.rs")); -- cgit v1.2.1