27 releases (stable)

1.7.3 Sep 8, 2024
1.7.1 Apr 16, 2024
1.6.0 Nov 7, 2023
1.5.2 Jul 30, 2023
0.5.0 Dec 4, 2016

#33 in Testing

Download history 9481/week @ 2024-08-03 10859/week @ 2024-08-10 10782/week @ 2024-08-17 10066/week @ 2024-08-24 9819/week @ 2024-08-31 11547/week @ 2024-09-07 9822/week @ 2024-09-14 10200/week @ 2024-09-21 11357/week @ 2024-09-28 11744/week @ 2024-10-05 10322/week @ 2024-10-12 10714/week @ 2024-10-19 10642/week @ 2024-10-26 9549/week @ 2024-11-02 9877/week @ 2024-11-09 11035/week @ 2024-11-16

42,914 downloads per month
Used in 36 crates (23 directly)

MIT license

13KB
179 lines

👑 Rust Goldenfile

Documentation Latest Version Build Status Coverage Status

Simple goldenfile testing in Rust.

Goldenfile tests generate one or more output files as they run. If any files differ from their checked-in "golden" version, the test fails. This ensures that behavioral changes are intentional, explicit, and version controlled.

You can use goldenfiles to test the output of a parser, the order of a graph traversal, the result of a simulation, or anything else that should only change with human review.

Usage

use goldenfile::Mint;
use std::io::Write;

let mut mint = Mint::new("tests/goldenfiles");
let mut file1 = mint.new_goldenfile("file1.txt").unwrap();
let mut file2 = mint.new_goldenfile("file2.txt").unwrap();

writeln!(file1, "Hello world!").unwrap();
writeln!(file2, "Foo bar!").unwrap();

When the Mint goes out of scope, it compares the contents of each file to its checked-in golden version and fails the test if they differ. To update the checked-in versions, run:

UPDATE_GOLDENFILES=1 cargo test

Contributing

Pull requests are welcome! This project follows the Rust community's Code of Conduct.

Dependencies

~2–10MB
~122K SLoC