23 releases (stable)

1.6.0 Nov 7, 2023
1.5.2 Jul 30, 2023
1.4.5 Nov 6, 2022
1.4.3 Jun 24, 2022
0.5.0 Dec 4, 2016

#33 in Testing

Download history 6489/week @ 2023-12-04 6798/week @ 2023-12-11 6493/week @ 2023-12-18 3654/week @ 2023-12-25 5110/week @ 2024-01-01 6205/week @ 2024-01-08 7040/week @ 2024-01-15 7415/week @ 2024-01-22 7001/week @ 2024-01-29 5354/week @ 2024-02-05 4826/week @ 2024-02-12 6656/week @ 2024-02-19 7458/week @ 2024-02-26 6502/week @ 2024-03-04 7004/week @ 2024-03-11 7472/week @ 2024-03-18

28,848 downloads per month
Used in 29 crates (16 directly)

MIT license

12KB
169 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

extern crate goldenfile;

use std::io::Write;

use goldenfile::Mint;

#[test]
fn test() {
    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();

    write!(file1, "Hello world!").unwrap();
    write!(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–12MB
~124K SLoC