Skip to content

Commit a17e5e2

Browse files
committed
Auto merge of #39717 - pnkfelix:check-timestamps-in-compiletest-miropt, r=alexcrichton
When compiletest'ing src/test/mir-opt, check timestamps. The tests in src/test/mir-opt embed references to generated files. The names of the generated files embed node id's, which will change depending on the content of the original source. To guard against comparisons against stale output, check the timestamps of the supposed output against the timestamp of the original source (i.e. any output should be at least as new as the source that was recompiled). Fix #39690.
2 parents c1368fc + 6a78282 commit a17e5e2

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/tools/compiletest/src/runtest.rs

+14
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use common::{CompileFail, ParseFail, Pretty, RunFail, RunPass, RunPassValgrind};
1313
use common::{Codegen, DebugInfoLldb, DebugInfoGdb, Rustdoc, CodegenUnits};
1414
use common::{Incremental, RunMake, Ui, MirOpt};
1515
use errors::{self, ErrorKind, Error};
16+
use filetime::FileTime;
1617
use json;
1718
use header::TestProps;
1819
use header;
@@ -2457,12 +2458,25 @@ actual:\n\
24572458
}
24582459
}
24592460

2461+
fn check_mir_test_timestamp(&self, test_name: &str, output_file: &Path) {
2462+
let t = |file| FileTime::from_last_modification_time(&fs::metadata(file).unwrap());
2463+
let source_file = &self.testpaths.file;
2464+
let output_time = t(output_file);
2465+
let source_time = t(source_file);
2466+
if source_time > output_time {
2467+
debug!("source file time: {:?} output file time: {:?}", source_time, output_time);
2468+
panic!("test source file `{}` is newer than potentially stale output file `{}`.",
2469+
source_file.display(), test_name);
2470+
}
2471+
}
2472+
24602473
fn compare_mir_test_output(&self, test_name: &str, expected_content: &Vec<&str>) {
24612474
let mut output_file = PathBuf::new();
24622475
output_file.push(self.get_mir_dump_dir());
24632476
output_file.push(test_name);
24642477
debug!("comparing the contests of: {:?}", output_file);
24652478
debug!("with: {:?}", expected_content);
2479+
self.check_mir_test_timestamp(test_name, &output_file);
24662480

24672481
let mut dumped_file = fs::File::open(output_file.clone()).unwrap();
24682482
let mut dumped_string = String::new();

0 commit comments

Comments
 (0)