Crates.io | expectorate |
lib.rs | expectorate |
version | 1.1.0 |
source | src |
created_at | 2020-08-07 00:42:17.143029 |
updated_at | 2023-09-25 23:53:04.00799 |
description | Library for comparing output to file contents with simple updating |
homepage | |
repository | https://github.com/oxidecomputer/expectorate |
max_upload_size | |
id | 273790 |
size | 126,718 |
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.
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
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.