Skip to content

Commit ec08622

Browse files
committed
compiletest: autoremove duplicate .nll.* files (#51204)
UI tests in bless mode should now check to see if `.nll.*` files have a matching `.*` file. If a match is found, it will be deleted. This should be extensible to other modes (i.e., Polonius). On running with `--bless`, the two files removed in #51186 are, in turn, removed automatically.
1 parent f9157f5 commit ec08622

File tree

1 file changed

+51
-8
lines changed

1 file changed

+51
-8
lines changed

src/tools/compiletest/src/runtest.rs

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010

1111
use common::CompareMode;
12-
use common::{expected_output_path, UI_FIXED, UI_STDERR, UI_STDOUT};
12+
use common::{expected_output_path, UI_EXTENSIONS, UI_FIXED, UI_STDERR, UI_STDOUT};
1313
use common::{output_base_dir, output_base_name, output_testname_unique};
1414
use common::{Codegen, CodegenUnits, DebugInfoGdb, DebugInfoLldb, Rustdoc};
1515
use common::{CompileFail, ParseFail, Pretty, RunFail, RunPass, RunPassValgrind};
@@ -2609,6 +2609,9 @@ impl<'test> TestCx<'test> {
26092609
errors += self.compare_output("stdout", &normalized_stdout, &expected_stdout);
26102610
errors += self.compare_output("stderr", &normalized_stderr, &expected_stderr);
26112611

2612+
let modes_to_prune = vec![CompareMode::Nll];
2613+
self.prune_duplicate_outputs(&modes_to_prune);
2614+
26122615
if self.config.compare_mode.is_some() {
26132616
// don't test rustfix with nll right now
26142617
} else if self.props.run_rustfix {
@@ -2971,6 +2974,16 @@ impl<'test> TestCx<'test> {
29712974
}
29722975
}
29732976

2977+
fn delete_file(&self, file: &PathBuf) {
2978+
if let Err(e) = ::std::fs::remove_file(file) {
2979+
self.fatal(&format!(
2980+
"failed to delete `{}`: {}",
2981+
file.display(),
2982+
e,
2983+
));
2984+
}
2985+
}
2986+
29742987
fn compare_output(&self, kind: &str, actual: &str, expected: &str) -> usize {
29752988
if actual == expected {
29762989
return 0;
@@ -3023,13 +3036,7 @@ impl<'test> TestCx<'test> {
30233036

30243037
for output_file in &files {
30253038
if actual.is_empty() {
3026-
if let Err(e) = ::std::fs::remove_file(output_file) {
3027-
self.fatal(&format!(
3028-
"failed to delete `{}`: {}",
3029-
output_file.display(),
3030-
e,
3031-
));
3032-
}
3039+
self.delete_file(output_file);
30333040
} else {
30343041
match File::create(&output_file).and_then(|mut f| f.write_all(actual.as_bytes())) {
30353042
Ok(()) => {}
@@ -3054,6 +3061,42 @@ impl<'test> TestCx<'test> {
30543061
}
30553062
}
30563063

3064+
fn prune_duplicate_output(&self, mode: CompareMode, kind: &str, canon_content: &str) {
3065+
let examined_path = expected_output_path(
3066+
&self.testpaths,
3067+
self.revision,
3068+
&Some(mode),
3069+
kind,
3070+
);
3071+
3072+
let examined_content = self
3073+
.load_expected_output_from_path(&examined_path)
3074+
.unwrap_or_else(|_| String::new());
3075+
3076+
if examined_path.exists() && canon_content == &examined_content {
3077+
self.delete_file(&examined_path);
3078+
}
3079+
}
3080+
3081+
fn prune_duplicate_outputs(&self, modes: &[CompareMode]) {
3082+
if self.config.bless {
3083+
for kind in UI_EXTENSIONS {
3084+
let canon_comparison_path = expected_output_path(
3085+
&self.testpaths,
3086+
self.revision,
3087+
&None,
3088+
kind,
3089+
);
3090+
3091+
if let Ok(canon) = self.load_expected_output_from_path(&canon_comparison_path) {
3092+
for mode in modes {
3093+
self.prune_duplicate_output(mode.clone(), kind, &canon);
3094+
}
3095+
}
3096+
}
3097+
}
3098+
}
3099+
30573100
fn create_stamp(&self) {
30583101
let mut f = File::create(::stamp(&self.config, self.testpaths, self.revision)).unwrap();
30593102
f.write_all(compute_stamp_hash(&self.config).as_bytes())

0 commit comments

Comments
 (0)