11 releases (5 stable)

1.1.0 Sep 7, 2019
1.0.3 Feb 23, 2019
0.7.1 Apr 29, 2018
0.6.0 Apr 29, 2018
0.4.0 Dec 3, 2016

#137 in Testing

Download history 2409/week @ 2021-06-30 3060/week @ 2021-07-07 3114/week @ 2021-07-14 3694/week @ 2021-07-21 2962/week @ 2021-07-28 3572/week @ 2021-08-04 2229/week @ 2021-08-11 1260/week @ 2021-08-18 1451/week @ 2021-08-25 1244/week @ 2021-09-01 2410/week @ 2021-09-08 2630/week @ 2021-09-15 2514/week @ 2021-09-22 2236/week @ 2021-09-29 3102/week @ 2021-10-06 2733/week @ 2021-10-13

12,524 downloads per month
Used in 4 crates

MIT license

11KB
147 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 ").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
    //
}

Contributing

Feel free to submit pull requests for new and better differs or other improvements! Run scripts/install-git-hooks to install pre-commit test and formatting hooks.

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

Dependencies

~590KB