#file-content #fixture #test

dev expectorate

Library for comparing output to file contents with simple updating

9 stable releases

2.0.1 Mar 25, 2021
1.1.0 Sep 25, 2023
1.0.7 Apr 17, 2023
1.0.6 Dec 27, 2022
1.0.2 Nov 14, 2020

#48 in Testing

Download history 5312/week @ 2024-01-31 3566/week @ 2024-02-07 6283/week @ 2024-02-14 4107/week @ 2024-02-21 4282/week @ 2024-02-28 4541/week @ 2024-03-06 6387/week @ 2024-03-13 6343/week @ 2024-03-20 4908/week @ 2024-03-27 6662/week @ 2024-04-03 6215/week @ 2024-04-10 7059/week @ 2024-04-17 7268/week @ 2024-04-24 6230/week @ 2024-05-01 8628/week @ 2024-05-08 7147/week @ 2024-05-15

30,516 downloads per month
Used in 15 crates


135 lines


This is a little library to validate expected output saved in files. It makes it easy to update that content when it should be updated to match the new results.

Validating Output

Say you have a function compose() that produces a string and you have a file named lyrics.txt that contain the expected output. You can compare the actual output like this:

    let actual: &str = compose();
    assert_content("lyrics.txt", actual);

If the output doesn't match, you'll see output like this:

White means that the content matches. Red means that content from the file was missing. Green means that content not in the file was added.

If we want to accept the changes from compose() we'd simply run with EXPECTORATE=overwrite. Assuming lyrics.txt is checked in, git diff will show you something like this:

diff --git a/examples/lyrics.txt b/examples/lyrics.txt
index e4104c1..ea6beaf 100644
--- a/examples/lyrics.txt
+++ b/examples/lyrics.txt
@@ -1,5 +1,2 @@
-No one hits like Gaston
-Matches wits like Gaston
-In a spitting match nobody spits like Gaston
+In a testing match nobody tests like Gaston
 I'm especially good at expectorating
-Ten points for Gaston

Predicates (feature: predicates)

Expectorate can be used in places where you might use the predicates crate. If you're using predicates::path::eq_file you can instead use expectorate::eq_file or expectorate::eq_file_or_panic. Populate or update the specified file as above.


~64K SLoC