Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 5 pull requests #126462

Merged
merged 18 commits into from
Jun 14, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}