Skip to content

Commit

Permalink
Rollup merge of rust-lang#126270 - GuillaumeGomez:migrate-run-make-co…
Browse files Browse the repository at this point in the history
…nst_fn_mir, r=jieyouxu

Migrate run make const fn mir

Part of rust-lang#121876.

r? ``@jieyouxu``
  • Loading branch information
matthiaskrgr committed Jun 14, 2024
2 parents 158d2c1 + 5f4111f commit 44e618d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
22 changes: 16 additions & 6 deletions src/tools/run-make-support/src/diff/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
use regex::Regex;
use similar::TextDiff;
use std::path::Path;
use std::path::{Path, PathBuf};

use crate::drop_bomb::DropBomb;
use crate::fs_wrapper;

#[cfg(test)]
mod tests;
Expand All @@ -17,6 +18,7 @@ pub fn diff() -> Diff {
pub struct Diff {
expected: Option<String>,
expected_name: Option<String>,
expected_file: Option<PathBuf>,
actual: Option<String>,
actual_name: Option<String>,
normalizers: Vec<(String, String)>,
Expand All @@ -30,6 +32,7 @@ impl Diff {
Self {
expected: None,
expected_name: None,
expected_file: None,
actual: None,
actual_name: None,
normalizers: Vec::new(),
Expand All @@ -40,9 +43,10 @@ impl Diff {
/// Specify the expected output for the diff from a file.
pub fn expected_file<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
let path = path.as_ref();
let content = std::fs::read_to_string(path).expect("failed to read file");
let content = fs_wrapper::read_to_string(path);
let name = path.to_string_lossy().to_string();

self.expected_file = Some(path.into());
self.expected = Some(content);
self.expected_name = Some(name);
self
Expand All @@ -58,10 +62,7 @@ impl Diff {
/// Specify the actual output for the diff from a file.
pub fn actual_file<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
let path = path.as_ref();
let content = match std::fs::read_to_string(path) {
Ok(c) => c,
Err(e) => panic!("failed to read `{}`: {:?}", path.display(), e),
};
let content = fs_wrapper::read_to_string(path);
let name = path.to_string_lossy().to_string();

self.actual = Some(content);
Expand Down Expand Up @@ -104,6 +105,15 @@ impl Diff {
.to_string();

if !output.is_empty() {
// If we can bless (meaning we have a file to write into and the `RUSTC_BLESS_TEST`
// environment variable set), then we write into the file and return.
if let Some(ref expected_file) = self.expected_file {
if std::env::var("RUSTC_BLESS_TEST").is_ok() {
println!("Blessing `{}`", expected_file.display());
fs_wrapper::write(expected_file, actual);
return;
}
}
panic!(
"test failed: `{}` is different from `{}`\n\n{}",
expected_name, actual_name, output
Expand Down
1 change: 0 additions & 1 deletion src/tools/tidy/src/allowed_run_make_makefiles.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ run-make/compiler-lookup-paths-2/Makefile
run-make/compiler-lookup-paths/Makefile
run-make/compiler-rt-works-on-mingw/Makefile
run-make/compressed-debuginfo/Makefile
run-make/const_fn_mir/Makefile
run-make/crate-hash-rustc-version/Makefile
run-make/crate-name-priority/Makefile
run-make/cross-lang-lto-clang/Makefile
Expand Down
6 changes: 0 additions & 6 deletions tests/run-make/const_fn_mir/Makefile

This file was deleted.

8 changes: 8 additions & 0 deletions tests/run-make/const_fn_mir/rmake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// The `needs-unwind -Cpanic=abort` gives a different MIR output.

use run_make_support::{cwd, diff, rustc};

fn main() {
rustc().input("main.rs").emit("mir").output("dump-actual.mir").run();
diff().expected_file("dump.mir").actual_file("dump-actual.mir").run();
}

0 comments on commit 44e618d

Please sign in to comment.