| Crates.io | glob_test |
| lib.rs | glob_test |
| version | 0.1.0 |
| created_at | 2025-08-17 14:40:13.558432+00 |
| updated_at | 2025-08-17 14:40:13.558432+00 |
| description | Generate tests from a glob pattern |
| homepage | |
| repository | https://github.com/jprochazk/glob-test |
| max_upload_size | |
| id | 1799444 |
| size | 19,269 |
Read files based on a glob pattern, and generate a separate test for each matching file:
#[glob_test::glob("./usage/inputs/**/*.txt")]
fn test(path: &std::path::Path) {
std::fs::read_to_string(path).unwrap();
}
mod usage {
use super::*;
mod inputs {
use super::*;
#[test]
fn a() {
(|path: &std::path::Path| {
std::fs::read_to_string(path).unwrap();
})(
::std::path::Path::new(
"CARGO_MANIFEST_DIR/tests/usage/inputs/a.txt"
)
)
}
#[test]
fn b() {
(|path: &std::path::Path| {
std::fs::read_to_string(path).unwrap();
})(
::std::path::Path::new(
"CARGO_MANIFEST_DIR/tests/usage/inputs/b.txt"
)
)
}
}
}
inputs/a.txt -> mod inputs { #[test] fn a() {} }inputs/nested/a.txt -> mod inputs { mod nested { #[test] fn a() {} } }syn or quote, instead parsing from proc_macro2 tokens.glob.This library was specifically developed with insta in mind:
#[glob_test::glob("./**/*.txt")]
fn snapshots(path: &Path) {
insta::assert_snapshot!(std::fs::read_to_string(path).unwrap());
}
Each file will produce one snapshot, just like insta::glob!. The primary difference is that now each snapshot
also gets its own unique test function, which means:
glob! to stop.It is recommended that you put a build.rs file in any crate which uses this library:
// build.rs
fn main() {
println!("cargo:rerun-if-changed=tests/usage/inputs")
}
That ensures changes to test files are always reflected in the test binary.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.