Rollup merge of #126270 - GuillaumeGomez:migrate-run-make-const_fn_mir, r=jieyouxu
Migrate run make const fn mir Part of https://github.com/rust-lang/rust/issues/121876. r? ```@jieyouxu```
This commit is contained in:
commit
254f10a59c
@ -1,8 +1,9 @@
|
|||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
use similar::TextDiff;
|
use similar::TextDiff;
|
||||||
use std::path::Path;
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
use crate::drop_bomb::DropBomb;
|
use crate::drop_bomb::DropBomb;
|
||||||
|
use crate::fs_wrapper;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests;
|
mod tests;
|
||||||
@ -17,6 +18,7 @@ pub fn diff() -> Diff {
|
|||||||
pub struct Diff {
|
pub struct Diff {
|
||||||
expected: Option<String>,
|
expected: Option<String>,
|
||||||
expected_name: Option<String>,
|
expected_name: Option<String>,
|
||||||
|
expected_file: Option<PathBuf>,
|
||||||
actual: Option<String>,
|
actual: Option<String>,
|
||||||
actual_name: Option<String>,
|
actual_name: Option<String>,
|
||||||
normalizers: Vec<(String, String)>,
|
normalizers: Vec<(String, String)>,
|
||||||
@ -30,6 +32,7 @@ impl Diff {
|
|||||||
Self {
|
Self {
|
||||||
expected: None,
|
expected: None,
|
||||||
expected_name: None,
|
expected_name: None,
|
||||||
|
expected_file: None,
|
||||||
actual: None,
|
actual: None,
|
||||||
actual_name: None,
|
actual_name: None,
|
||||||
normalizers: Vec::new(),
|
normalizers: Vec::new(),
|
||||||
@ -40,9 +43,10 @@ impl Diff {
|
|||||||
/// Specify the expected output for the diff from a file.
|
/// Specify the expected output for the diff from a file.
|
||||||
pub fn expected_file<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
|
pub fn expected_file<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
|
||||||
let path = path.as_ref();
|
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();
|
let name = path.to_string_lossy().to_string();
|
||||||
|
|
||||||
|
self.expected_file = Some(path.into());
|
||||||
self.expected = Some(content);
|
self.expected = Some(content);
|
||||||
self.expected_name = Some(name);
|
self.expected_name = Some(name);
|
||||||
self
|
self
|
||||||
@ -58,10 +62,7 @@ impl Diff {
|
|||||||
/// Specify the actual output for the diff from a file.
|
/// Specify the actual output for the diff from a file.
|
||||||
pub fn actual_file<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
|
pub fn actual_file<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
|
||||||
let path = path.as_ref();
|
let path = path.as_ref();
|
||||||
let content = match std::fs::read_to_string(path) {
|
let content = fs_wrapper::read_to_string(path);
|
||||||
Ok(c) => c,
|
|
||||||
Err(e) => panic!("failed to read `{}`: {:?}", path.display(), e),
|
|
||||||
};
|
|
||||||
let name = path.to_string_lossy().to_string();
|
let name = path.to_string_lossy().to_string();
|
||||||
|
|
||||||
self.actual = Some(content);
|
self.actual = Some(content);
|
||||||
@ -104,6 +105,15 @@ impl Diff {
|
|||||||
.to_string();
|
.to_string();
|
||||||
|
|
||||||
if !output.is_empty() {
|
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!(
|
panic!(
|
||||||
"test failed: `{}` is different from `{}`\n\n{}",
|
"test failed: `{}` is different from `{}`\n\n{}",
|
||||||
expected_name, actual_name, output
|
expected_name, actual_name, output
|
||||||
|
@ -18,7 +18,6 @@ run-make/compiler-lookup-paths-2/Makefile
|
|||||||
run-make/compiler-lookup-paths/Makefile
|
run-make/compiler-lookup-paths/Makefile
|
||||||
run-make/compiler-rt-works-on-mingw/Makefile
|
run-make/compiler-rt-works-on-mingw/Makefile
|
||||||
run-make/compressed-debuginfo/Makefile
|
run-make/compressed-debuginfo/Makefile
|
||||||
run-make/const_fn_mir/Makefile
|
|
||||||
run-make/crate-hash-rustc-version/Makefile
|
run-make/crate-hash-rustc-version/Makefile
|
||||||
run-make/crate-name-priority/Makefile
|
run-make/crate-name-priority/Makefile
|
||||||
run-make/cross-lang-lto-clang/Makefile
|
run-make/cross-lang-lto-clang/Makefile
|
||||||
|
@ -1,6 +0,0 @@
|
|||||||
# needs-unwind -Cpanic=abort gives different MIR output
|
|
||||||
include ../tools.mk
|
|
||||||
|
|
||||||
all:
|
|
||||||
$(RUSTC) main.rs --emit=mir -o "$(TMPDIR)"/dump.mir
|
|
||||||
$(RUSTC_TEST_OP) "$(TMPDIR)"/dump.mir dump.mir
|
|
8
tests/run-make/const_fn_mir/rmake.rs
Normal file
8
tests/run-make/const_fn_mir/rmake.rs
Normal file
@ -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();
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user