Skip to content

Commit a9d3962

Browse files
committed
compiletest: Remove/don't write empty 'expected' files
1 parent a03fe2c commit a9d3962

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/tools/compiletest/src/runtest.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ fn remove_and_create_dir_all(path: &Path) {
213213
fs::create_dir_all(path).unwrap();
214214
}
215215

216-
#[derive(Copy, Clone)]
216+
#[derive(Copy, Clone, Debug)]
217217
struct TestCx<'test> {
218218
config: &'test Config,
219219
props: &'test TestProps,
@@ -2579,6 +2579,13 @@ impl<'test> TestCx<'test> {
25792579
actual_unnormalized: &str,
25802580
expected: &str,
25812581
) -> bool {
2582+
let expected_path =
2583+
expected_output_path(self.testpaths, self.revision, &self.config.compare_mode, stream);
2584+
2585+
if self.config.bless && actual.is_empty() && expected_path.exists() {
2586+
self.delete_file(&expected_path);
2587+
}
2588+
25822589
let are_different = match (self.force_color_svg(), expected.find('\n'), actual.find('\n')) {
25832590
// FIXME: We ignore the first line of SVG files
25842591
// because the width parameter is non-deterministic.
@@ -2628,9 +2635,6 @@ impl<'test> TestCx<'test> {
26282635
}
26292636
println!("Saved the actual {stream} to {actual_path:?}");
26302637

2631-
let expected_path =
2632-
expected_output_path(self.testpaths, self.revision, &self.config.compare_mode, stream);
2633-
26342638
if !self.config.bless {
26352639
if expected.is_empty() {
26362640
println!("normalized {}:\n{}\n", stream, actual);
@@ -2653,10 +2657,12 @@ impl<'test> TestCx<'test> {
26532657
self.delete_file(&old);
26542658
}
26552659

2656-
if let Err(err) = fs::write(&expected_path, &actual) {
2657-
self.fatal(&format!("failed to write {stream} to `{expected_path:?}`: {err}"));
2660+
if !actual.is_empty() {
2661+
if let Err(err) = fs::write(&expected_path, &actual) {
2662+
self.fatal(&format!("failed to write {stream} to `{expected_path:?}`: {err}"));
2663+
}
2664+
println!("Blessing the {stream} of {test_name} in {expected_path:?}");
26582665
}
2659-
println!("Blessing the {stream} of {test_name} in {expected_path:?}");
26602666
}
26612667

26622668
println!("\nThe actual {0} differed from the expected {0}.", stream);

0 commit comments

Comments
 (0)