Skip to content

Commit 6672da9

Browse files
committed
tests/tex-outputs.rs: save expected/observed outputs to disk if a test fails
As in tests/trip.rs, it's a lot easier to diagnose failures this way. The code between this file and trip.rs is getting a bit redundant; worth thinking about ways to centralize them.
1 parent c5dab85 commit 6672da9

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

tests/tex-outputs.rs

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,33 @@ fn read_file<P: AsRef<Path>>(path: P) -> Vec<u8> {
6666
buffer
6767
}
6868

69+
70+
pub fn test_file(name: &OsStr, expected: &Vec<u8>, observed: &Vec<u8>) {
71+
if expected == observed {
72+
return;
73+
}
74+
75+
// For nontrivial tests, it's really tough to figure out what
76+
// changed without being able to do diffs, etc. So, write out the
77+
// buffers.
78+
79+
{
80+
let mut n = name.to_owned();
81+
n.push(".expected");
82+
let mut f = File::create(&n).expect(&format!("failed to create {} for test failure diagnosis", n.to_string_lossy()));
83+
f.write_all(expected).expect(&format!("failed to write {} for test failure diagnosis", n.to_string_lossy()));
84+
}
85+
{
86+
let mut n = name.to_owned();
87+
n.push(".observed");
88+
let mut f = File::create(&n).expect(&format!("failed to create {} for test failure diagnosis", n.to_string_lossy()));
89+
f.write_all(observed).expect(&format!("failed to write {} for test failure diagnosis", n.to_string_lossy()));
90+
}
91+
92+
panic!("difference in {}; contents saved to disk", name.to_string_lossy());
93+
}
94+
95+
6996
fn do_one(stem: &str, check_synctex: bool) {
7097
let _guard = LOCK.lock().unwrap(); // until we're thread-safe ...
7198

@@ -115,17 +142,17 @@ fn do_one(stem: &str, check_synctex: bool) {
115142
let files = mem.files.borrow();
116143

117144
let observed_log = files.get(&logname).unwrap();
118-
assert_eq!(&expected_log, observed_log);
145+
test_file(&logname, &expected_log, observed_log);
119146

120147
let observed_xdv = files.get(&xdvname).unwrap();
121-
assert_eq!(&expected_xdv, observed_xdv);
148+
test_file(&xdvname, &expected_xdv, observed_xdv);
122149

123150
if check_synctex {
124151
p.set_extension("synctex");
125152
let expected_synctex = read_file(&p);
126153
let synctexname = p.file_name().unwrap().to_owned();
127154
let observed_synctex = files.get(&synctexname).unwrap();
128-
assert_eq!(&expected_synctex, observed_synctex);
155+
test_file(&synctexname, &expected_synctex, observed_synctex);
129156
}
130157
}
131158

0 commit comments

Comments
 (0)