4 releases (stable)
new 1.0.2 | May 6, 2025 |
---|---|
0.1.0 | Sep 17, 2023 |
#236 in Testing
77 downloads per month
Used in typeshare-java
6KB
fixtures
fixtures
is a Rust crate which allows developers to run tests against fixture files.
Usage
Installation
[dependencies]
fixtures = "1"
[build-dependencies]
fixtures = "1"
Setup
Add the following code to build.rs
to watch your fixtures directories for changes.
// build.rs
use fixtures::build::watch_fixture_dir;
fn main() {
watch_fixture_dir("path/to/fixtures");
// or...
watch_fixture_dir(&[
"path/to/fixtures",
// ...
]);
}
Basic Usage
#[cfg(test)]
mod tests {
use fixtures::fixtures;
#[fixtures(["fixtures/*.txt"])]
fn test(path: &std::path::Path) {
// This test will be run once for each file matching the glob pattern
}
}
The above example expands to:
#[cfg(test)]
mod tests {
use fixtures::fixtures;
fn test(path: &std::path::Path) {
// This test will be run once for each file matching the glob pattern
}
#[test]
fn test_one_dot_txt_1() {
test(::std::path::Path::new("fixtures/one.txt"));
}
#[test]
fn test_two_dot_txt_1() {
test(::std::path::Path::new("fixtures/two.txt"));
}
// ...
}
Multiple Globs
#[cfg(test)]
mod tests {
use fixtures::fixtures;
#[fixtures(["fixtures/*.txt", "fixtures/*.data"])]
fn test(path: &std::path::Path) {
// This test will be run once for each file matching either "fixtures/*.txt" or "fixtures/*.data"
}
}
Extended Glob Syntax
fixtures
supports gitignore
's extended glob syntax.
#[cfg(test)]
mod tests {
use fixtures::fixtures;
#[fixtures(["fixtures/*.{txt,data}", "!fixtures/skip.*.{txt,data}"])]
fn test(path: &std::path::Path) {
// This test will be run once for each fixture with the extension `txt` or `data`, unless it is prefixed with `skip.`
}
}
Dependencies
~4–12MB
~138K SLoC