19 releases (stable)

Uses new Rust 2021

1.4.5 Nov 6, 2022
1.4.3 Jun 24, 2022
1.2.0 May 29, 2022
1.1.0 Sep 7, 2019
0.5.0 Dec 4, 2016

#36 in Testing

Download history 9005/week @ 2022-08-08 12042/week @ 2022-08-15 17255/week @ 2022-08-22 10083/week @ 2022-08-29 10022/week @ 2022-09-05 11939/week @ 2022-09-12 14187/week @ 2022-09-19 11283/week @ 2022-09-26 7954/week @ 2022-10-03 11734/week @ 2022-10-10 12520/week @ 2022-10-17 9355/week @ 2022-10-24 9720/week @ 2022-10-31 6143/week @ 2022-11-07 5607/week @ 2022-11-14 5077/week @ 2022-11-21

26,827 downloads per month
Used in 26 crates (13 directly)

MIT license

11KB
160 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. 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.

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 shouldn't change without a human's approval.

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 will compare the contents of each file to its checked-in "golden" version and fail the test if they differ. To update the check-in versions, run:

REGENERATE_GOLDENFILES=1 cargo test

Contributing

Pull requests are welcome! Run dev/install-git-hooks to install pre-commit test and formatting hooks.

This project follows the Rust community's Code of Conduct.

Dependencies

~520KB
~11K SLoC