mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-29 02:03:53 +00:00
Rollup merge of #129040 - Zalathar:bless-rmake, r=jieyouxu
Fix blessing of rmake tests Fixes #129038. When running in `--bless` mode, we now set the value of `RUSTC_BLESS_TEST` to the current test's source directory. This allows the diff helper in `run_make_support` to find the original snapshot file in the source directory and bless that, instead of unhelpfully blessing the temporary copy in `build`. r? `@jieyouxu`
This commit is contained in:
commit
42f70c240a
@ -3735,15 +3735,14 @@ impl<'test> TestCx<'test> {
|
||||
}
|
||||
|
||||
if self.config.bless {
|
||||
cmd.env("RUSTC_BLESS_TEST", "--bless");
|
||||
// Assume this option is active if the environment variable is "defined", with _any_ value.
|
||||
// As an example, a `Makefile` can use this option by:
|
||||
// If we're running in `--bless` mode, set an environment variable to tell
|
||||
// `run_make_support` to bless snapshot files instead of checking them.
|
||||
//
|
||||
// ifdef RUSTC_BLESS_TEST
|
||||
// cp "$(TMPDIR)"/actual_something.ext expected_something.ext
|
||||
// else
|
||||
// $(DIFF) expected_something.ext "$(TMPDIR)"/actual_something.ext
|
||||
// endif
|
||||
// The value is this test's source directory, because the support code
|
||||
// will need that path in order to bless the _original_ snapshot files,
|
||||
// not the copies in `rmake_out`.
|
||||
// (See <https://github.com/rust-lang/rust/issues/129038>.)
|
||||
cmd.env("RUSTC_BLESS_TEST", &self.testpaths.file);
|
||||
}
|
||||
|
||||
if self.config.target.contains("msvc") && !self.config.cc.is_empty() {
|
||||
|
@ -112,15 +112,9 @@ impl Diff {
|
||||
let (expected_name, actual_name, output, actual) = self.run_common();
|
||||
|
||||
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::write(expected_file, actual);
|
||||
if self.maybe_bless_expected_file(&actual) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
panic!(
|
||||
"test failed: `{}` is different from `{}`\n\n{}",
|
||||
expected_name, actual_name, output
|
||||
@ -134,19 +128,33 @@ impl Diff {
|
||||
let (expected_name, actual_name, output, actual) = self.run_common();
|
||||
|
||||
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::write(expected_file, actual);
|
||||
if self.maybe_bless_expected_file(&actual) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
panic!(
|
||||
"test failed: `{}` is not different from `{}`\n\n{}",
|
||||
expected_name, actual_name, output
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/// If we have an expected file to write into, and `RUSTC_BLESS_TEST` is
|
||||
/// set, then write the actual output into the file and return `true`.
|
||||
///
|
||||
/// We assume that `RUSTC_BLESS_TEST` contains the path to the original test's
|
||||
/// source directory. That lets us bless the original snapshot file in the
|
||||
/// source tree, not the copy in `rmake_out` that we would normally use.
|
||||
fn maybe_bless_expected_file(&self, actual: &str) -> bool {
|
||||
let Some(ref expected_file) = self.expected_file else {
|
||||
return false;
|
||||
};
|
||||
let Ok(bless_dir) = std::env::var("RUSTC_BLESS_TEST") else {
|
||||
return false;
|
||||
};
|
||||
|
||||
let bless_file = Path::new(&bless_dir).join(expected_file);
|
||||
println!("Blessing `{}`", bless_file.display());
|
||||
fs::write(bless_file, actual);
|
||||
true
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user