Skip to content

Commit

Permalink
Only print errors on failure.
Browse files Browse the repository at this point in the history
  • Loading branch information
calder committed Nov 7, 2023
1 parent 6d1d5ed commit dd2bf37
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 22 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "goldenfile"
version = "1.5.2"
version = "1.6.0"
edition = "2021"
description = "Simple goldenfile testing library"
keywords = ["goldenfile", "test", "library"]
Expand All @@ -16,5 +16,7 @@ exclude = [
]

[dependencies]
scopeguard = "1.2"
similar-asserts = "1.4"
tempfile = "3"
yansi = "1.0.0-rc.1"
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
#![deny(missing_docs)]

#[macro_use(defer_on_unwind)]
extern crate scopeguard;

pub mod differs;
pub mod mint;

Expand Down
15 changes: 9 additions & 6 deletions src/mint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use std::path::{Path, PathBuf};
use std::thread;

use tempfile::TempDir;
use yansi::Paint;

use crate::differs::*;

Expand Down Expand Up @@ -94,13 +95,15 @@ impl Mint {
for &(ref file, ref differ) in &self.files {
let old = self.path.join(&file);
let new = self.tempdir.path().join(&file);

println!("\nGoldenfile diff for {:?}:", file.to_str().unwrap());
println!("To regenerate the goldenfile, run");
println!(" UPDATE_GOLDENFILES=1 cargo test");
println!("------------------------------------------------------------");
defer_on_unwind! {
eprintln!("note: run with `UPDATE_GOLDENFILES=1` to update goldenfiles");
eprintln!(
"{}: goldenfile changed: {}",
"error".bold().red(),
file.to_str().unwrap()
);
}
differ(&old, &new);
println!("<NO DIFFERENCE>");
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/goldenfiles/match1.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Hello world!
Hello world!
2 changes: 1 addition & 1 deletion tests/goldenfiles/match2.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
foobar
foobar
2 changes: 1 addition & 1 deletion tests/goldenfiles/subdir/file1.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
File in subdir
File in subdir
2 changes: 1 addition & 1 deletion tests/goldenfiles/text_diff1.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Hello world!
Hello world!
2 changes: 1 addition & 1 deletion tests/goldenfiles/text_diff2.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
foobar
foobar
2 changes: 1 addition & 1 deletion tests/goldenfiles/update_env1.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Hello world!
Hello world!
2 changes: 1 addition & 1 deletion tests/goldenfiles/update_env2.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
foobar
foobar
16 changes: 8 additions & 8 deletions tests/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn subdir() {
let mut mint = Mint::new("tests/goldenfiles");
let mut file1 = mint.new_goldenfile("subdir/file1.txt").unwrap();

write!(file1, "File in subdir").unwrap();
writeln!(file1, "File in subdir").unwrap();
}

#[test]
Expand All @@ -47,8 +47,8 @@ fn text_match() {
let mut file1 = mint.new_goldenfile("match1.txt").unwrap();
let mut file2 = mint.new_goldenfile("match2.txt").unwrap();

write!(file1, "Hello world!").unwrap();
write!(file2, "foobar").unwrap();
writeln!(file1, "Hello world!").unwrap();
writeln!(file2, "foobar").unwrap();
}

#[test]
Expand All @@ -58,8 +58,8 @@ fn text_diff() {
let mut file1 = mint.new_goldenfile("text_diff1.txt").unwrap();
let mut file2 = mint.new_goldenfile("text_diff2.txt").unwrap();

write!(file1, "Hello world!").unwrap();
write!(file2, "monkeybrains").unwrap();
writeln!(file1, "Hello world!").unwrap();
writeln!(file2, "monkeybrains").unwrap();
}

#[test]
Expand All @@ -75,7 +75,7 @@ fn external_panic() {
let mut mint = Mint::new("tests/goldenfiles");
let mut file1 = mint.new_goldenfile("panic.txt").unwrap();

write!(file1, "new").unwrap();
writeln!(file1, "new").unwrap();
assert!(false);
}

Expand All @@ -88,8 +88,8 @@ fn update() {
let mut file1 = mint.new_goldenfile("update_env1.txt").unwrap();
let mut file2 = mint.new_goldenfile("update_env2.txt").unwrap();

write!(file1, "Hello world!").unwrap();
write!(file2, "foobar").unwrap();
writeln!(file1, "Hello world!").unwrap();
writeln!(file2, "foobar").unwrap();

mint.update_goldenfiles()
}

0 comments on commit dd2bf37

Please sign in to comment.