Simple goldenfile testing in Rust
Goldenfile tests generate one or more output files as they run. At the end of the test, the generated files are compared to checked-in "golden" files produced by previous runs. This ensures that all changes to goldenfiles are intentional, explicit, and version controlled.
```rust extern crate goldenfile;
use std::io::Write;
use goldenfile::Mint;
fn test() { let mut mint = Mint::new("tests/goldenfiles"); let mut file1 = mint.newgoldenfile("file1.txt").unwrap(); let mut file2 = mint.newgoldenfile("file2.txt").unwrap();
write!(file1, "Hello ").unwrap();
write!(file1, "World!").unwrap();
write!(file2, "Foo").unwrap();
write!(file2, "Bar").unwrap();
// When the Mint goes out of scope, it will check the new contents of file1
// and file2 against their version controlled "golden" contents and fail the
// test if they differ.
//
// To update the goldenfiles themselves, run:
//
// env REGENERATE_GOLDENFILES=1 cargo test
//
} ```
Goldenfiles often get a bad rap. Used sparingly, they provide simple, insightful tests of a program's operation. You can use them to test the output of a parser, the order of a graph traversal, the results of a simulation, or anything else that shouldn't change without a human's approval.
Feel free to submit pull requests for new and better differs or anything else that's missing!
This project follows the Rust community's Code of Conduct.