Simple goldenfile testing in Rust.

Overview

👑 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.

Comments
  • Add support for binary file diffing

    Add support for binary file diffing

    Added a new differ, binary_diff, which prints a single message if the files differ in size or contents. Added a parameter to new_goldenfile which allows the user to specify the differ to use. Updated tests and example usage.

    This is a breaking change. All calls to new_goldenfile must include a new parameter, which should be DifferType::Text for regaining old behavior.

    I thought it'd be best to make this a breaking change, seeing as there aren't a lot of users of this crate, and being explicit about the file type in code is better than e.g. detecting the file type based on the extension, and all other alternative ways to integrate this API felt weird. (Make a new method such as new_goldenfile_with_differ ? Then text diffing looks like the "default", and that default wasn't chosen, it just turned out to be the one that was first implemented, etc.) If you disagree, I'll be happy to make changes to this PR.

    I'm currently using this library to verify in tests that there are no regressions regarding font rendering in my app. Since these tests produce image files (.pngs), text diffing fails because these files aren't valid UTF-8 (and text diffing wouldn't have made sense anyhow). Bottomline is---I'm really liking rust-goldenfile. Thanks for building it!

    opened by geomaster 4
  • Replace difference with diff?

    Replace difference with diff?

    cargo audit reports that difference is unmaintained:

    Crate:  difference
    Title:  difference is unmaintained
    Date:   2020-12-20
    URL:    https://rustsec.org/advisories/RUSTSEC-2020-0095
    

    pretty-assertions switched to the diff crate; would this work for this crate as well?

    opened by swsnr 3
  • Thoughts on best practices for line endings?

    Thoughts on best practices for line endings?

    I'm currently using git attributes to keep LF endings on Windows, but I'm wondering if the text differ should ignore LF/CTLF differences by default. WDYT?

    opened by SUPERCILEX 2
  • Address compilation and clippy warnings

    Address compilation and clippy warnings

    • Use explicit dyn for trait in Differ definition.
    • Remove unnecessary lifetime in file_byte_iter by using '_
    • Replace ".expect" with "unwrap_or_else to avoid building the string in the caller, even when it's not used.
    opened by lpenz 1
  • Add binary file support

    Add binary file support

    This adds a new_binary_goldenfile and binary_diff functions. If the files differ in size, it'll report the sizes. If the files' contents differ and the sizes are the same, it'll report the index of the first different byte (as suggested in #1).

    opened by simon-bourne 0
Owner
Calder Coalson
Calder Coalson
Simple assertion library for unit testing in python with a fluent API

Simple assertions library for unit testing in Python with a nice fluent API. Supports both Python 2 and 3.

snakedye 19 Sep 10, 2022
Testing Framework for Rust

Polish Polish is Test-Driven Development done right Getting Started Installing the Package The crates.io package is kept up-to-date with all the major

Fadi Hanna Al-Kass 49 Dec 18, 2022
ArchTest is a rule based architecture testing tool for rust

ArchTest is a rule based architecture testing tool. It applies static analyses on the specified rust project to extract use relationships.

Tom Dymel 7 Sep 26, 2021
Automated property based testing for Rust (with shrinking).

quickcheck QuickCheck is a way to do property based testing using randomly generated input. This crate comes with the ability to randomly generate and

Andrew Gallant 2k Jan 2, 2023
Hypothesis-like property testing for Rust

Proptest Introduction Proptest is a property testing framework (i.e., the QuickCheck family) inspired by the Hypothesis framework for Python. It allow

Jason Lingle 1.1k Jan 1, 2023
Cucumber testing framework for Rust. Fully native, no external test runners or dependencies.

An implementation of the Cucumber testing framework for Rust. Fully native, no external test runners or dependencies.

Brendan Molloy 394 Jan 1, 2023
Loom is a concurrency permutation testing tool for Rust.

Loom is a testing tool for concurrent Rust code

Tokio 1.4k Jan 9, 2023
Drill is an HTTP load testing application written in Rust inspired by Ansible syntax

Drill is an HTTP load testing application written in Rust inspired by Ansible syntax

Ferran Basora 1.5k Jan 1, 2023
assay - A super powered testing macro for Rust

assay - A super powered testing macro for Rust as·say /ˈaˌsā,aˈsā/ noun - the testing of a metal or ore to determine its ingredients and quality. Rust

Michael Gattozzi 105 Dec 4, 2022
Rust testing library

K9 - Rust Testing Library Snapshot testing + better assertions Available test macros snapshot assert_equal assert_greater_than assert_greater_than_or_

Aaron Abramov 269 Dec 10, 2022
Testing Framework for Rust

Polish Polish is Test-Driven Development done right Getting Started Installing the Package The crates.io package is kept up-to-date with all the major

Fadi Hanna Al-Kass 49 Dec 18, 2022
Rustress - stress testing library in Rust. For fun

rustress Simple network stress testing library. To get familiar with Rust Planned features (Subject to change) Multithreaded client/server Throughput

Hakan Sönmez 7 Sep 22, 2022
insta: a snapshot testing library for Rust

insta: a snapshot testing library for Rust Introduction Snapshots tests (also sometimes called approval tests) are tests that assert values against a

Armin Ronacher 1.4k Jan 1, 2023
Viceroy provides local testing for developers working with Compute@Edge.

Viceroy provides local testing for developers working with Compute@Edge. It allows you to run services written against the Compute@Edge APIs on your local development machine, and allows you to configure testing backends for your service to communicate with.

Fastly 99 Jan 7, 2023
Declarative Testing Framework

Demonstrate allows tests to be written without as a much repetitive code within the demonstrate! macro, which will generate the corresponding full tests.

Austin Baugh 41 Aug 17, 2022
🧵 Generate self-describing strings of a given length to help aid software testing

rust-counter-strings Counter strings generator written in rust to help aid software testing What is a counterstring? "A counterstring is a graduated s

Thomas Chaplin 23 Jun 24, 2022
🔥 Unit testing framework for Subgraph development on The Graph protocol. ⚙️

?? Welcome to Matchstick - a unit testing framework for The Graph protocol. Try out your mapping logic in a sandboxed environment and ensure your hand

null 157 Dec 20, 2022
This is a tiny (but delightful!) utility library for exhaustive testing.

Exhaustigen This is a tiny (but delightful!) utility library for exhaustive testing. It is based (directly) on the idea and code in the following blog

Graydon Hoare 34 Dec 14, 2022
A series of utility macros for outputting testing results.

test-results A series of utility macros for outputting testing results. Getting Started Simply add the test-results crate to your project's Cargo.toml

EYHN 1 Jan 27, 2022