diff options
author | Lars Wirzenius <liw@liw.fi> | 2021-11-27 09:17:58 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2021-11-27 14:10:35 +0200 |
commit | 99c0d2c80a476e13866cbd74b6e35ff95a1e5d58 (patch) | |
tree | 62249bc5c5a3b6a47bffc723dc21849f8f83689f /subplotlib/build.rs | |
parent | e3a8468282771369b5fb37be5c6e23c1e2833433 (diff) | |
download | subplot-99c0d2c80a476e13866cbd74b6e35ff95a1e5d58.tar.gz |
refactor: use build.rs for testing subplotlib subplots
A bit of dog-fooding: use subplot-build to test subplotlib.
Add a subplotlib/build.rs script to generate test code in Rust for the
subplotlib/*.md subplots. The generated code is included in
tests/*.rs, and run with "cargo test". Drop the same functionality
from the ./check script..
Sponsored-by: author
Diffstat (limited to 'subplotlib/build.rs')
-rw-r--r-- | subplotlib/build.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/subplotlib/build.rs b/subplotlib/build.rs new file mode 100644 index 0000000..5f94883 --- /dev/null +++ b/subplotlib/build.rs @@ -0,0 +1,30 @@ +// Build script for subplotlib. +// +// We use the `subplot_build` crate to generate a Rust test code file +// with functions for the scenarios for each subplot file +// (subplot/*.md in the source tree). The generated file is written to +// the Cargo target directory. For each subplot foo.md there should be +// a tests/foo.rs in the source tree, which includes the generated +// file from the Cargo target tree. The source file should look like this: +// +// ```rust +// include!(concat!(env!("OUT_DIR"), "/foo.rs")); +// ``` + +use glob::glob; +use std::path::Path; + +fn main() { + let subplots = glob("*.md").expect("failed to find subplots in subplotlib"); + let tests = Path::new("tests"); + for entry in subplots { + let entry = entry.expect("failed to get subplot dir entry in subplotlib"); + let mut inc = tests.join(&entry); + inc.set_extension("rs"); + if !inc.exists() { + panic!("missing include file: {}", inc.display()); + } + println!("cargo:rerun-if-changed={}", inc.display()); + subplot_build::codegen(Path::new(&entry)).expect("failed to generate code with Subplot"); + } +} |