Skip to content

Commit

Permalink
compiletest: Remove/don't write empty 'expected' files
Browse files Browse the repository at this point in the history
  • Loading branch information
clubby789 committed Dec 27, 2024
1 parent 942cf6c commit 7b35a2c
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ fn remove_and_create_dir_all(path: &Path) {
fs::create_dir_all(path).unwrap();
}

#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug)]
struct TestCx<'test> {
config: &'test Config,
props: &'test TestProps,
Expand Down Expand Up @@ -2589,7 +2589,14 @@ impl<'test> TestCx<'test> {
actual: &str,
actual_unnormalized: &str,
expected: &str,
) -> bool {
) -> CompareOutcome {
let expected_path =
expected_output_path(self.testpaths, self.revision, &self.config.compare_mode, stream);

if self.config.bless && actual.is_empty() && expected_path.exists() {
self.delete_file(&expected_path);
}

let are_different = match (self.force_color_svg(), expected.find('\n'), actual.find('\n')) {
// FIXME: We ignore the first line of SVG files
// because the width parameter is non-deterministic.
Expand Down Expand Up @@ -2639,9 +2646,6 @@ impl<'test> TestCx<'test> {
}
println!("Saved the actual {stream} to {actual_path:?}");

let expected_path =
expected_output_path(self.testpaths, self.revision, &self.config.compare_mode, stream);

if !self.config.bless {
if expected.is_empty() {
println!("normalized {}:\n{}\n", stream, actual);
Expand All @@ -2664,10 +2668,12 @@ impl<'test> TestCx<'test> {
self.delete_file(&old);
}

if let Err(err) = fs::write(&expected_path, &actual) {
self.fatal(&format!("failed to write {stream} to `{expected_path:?}`: {err}"));
if !actual.is_empty() {
if let Err(err) = fs::write(&expected_path, &actual) {
self.fatal(&format!("failed to write {stream} to `{expected_path:?}`: {err}"));
}
println!("Blessing the {stream} of {test_name} in {expected_path:?}");
}
println!("Blessing the {stream} of {test_name} in {expected_path:?}");
}

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

0 comments on commit 7b35a2c

Please sign in to comment.