Expand description
Test fixture utilities for defining multi-file test cases inline.
This crate provides a way to define file trees inline in test code using
the //- /path.rs syntax inspired by rust-analyzer.
§Single file fixture
use v_fixtures::Fixture;
let fixture = Fixture::parse(r#"
fn main() {
println!("Hello World")
}
"#);
assert_eq!(fixture.files.len(), 1);
assert_eq!(fixture.files[0].path, "/main.rs");§Multi-file fixture
use v_fixtures::Fixture;
let fixture = Fixture::parse(r#"
//- /main.rs
mod foo;
fn main() { foo::bar(); }
//- /foo.rs
pub fn bar() {}
"#);
assert_eq!(fixture.files.len(), 2);§Writing to temp directory
use v_fixtures::Fixture;
let fixture = Fixture::parse(r#"
//- /src/main.rs
fn main() {}
//- /src/lib.rs
pub fn hello() {}
"#);
let temp = fixture.write_to_tempdir();
assert!(temp.path("/src/main.rs").exists());
assert!(temp.path("/src/lib.rs").exists());§Testing with insta snapshots
ⓘ
use v_fixtures::Fixture;
// Apply some transformation to files...
let temp = fixture.write_to_tempdir();
// ... run your tool ...
let result = temp.read_all_from_disk();
insta::assert_snapshot!(result.render(), @"...");Modules§
- fs_
standards - Filesystem standard extensions for TempFixture.
Structs§
- Fixture
- Parsed fixture containing multiple files
- Fixture
File - A single file in a fixture
- Fixture
Renderer - Builder for rendering fixtures with various normalizations.
- Temp
Fixture - A fixture written to a temporary directory
Functions§
- assert_
fixture_ eq - Compare two fixtures for equality, with nice diff output on failure
- parse_
before_ after - Parse a before/after fixture separated by
=> - trim_
indent - Remove common leading indentation from all lines.