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

Fix blessing of rmake tests #129040

Merged
merged 2 commits into from
Aug 13, 2024
Merged
Changes from 1 commit
Commits
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
Prev Previous commit
Fix blessing of rmake tests
Zalathar committed Aug 13, 2024
commit cc58cf6443a1982aa613a6f3b4032fc31aefd6b9
15 changes: 7 additions & 8 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
@@ -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() {
13 changes: 9 additions & 4 deletions src/tools/run-make-support/src/diff/mod.rs
Original file line number Diff line number Diff line change
@@ -140,16 +140,21 @@ impl Diff {

/// 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;
};
if std::env::var("RUSTC_BLESS_TEST").is_err() {
let Ok(bless_dir) = std::env::var("RUSTC_BLESS_TEST") else {
return false;
}
};

println!("Blessing `{}`", expected_file.display());
fs::write(expected_file, actual);
let bless_file = Path::new(&bless_dir).join(expected_file);
println!("Blessing `{}`", bless_file.display());
fs::write(bless_file, actual);
true
}
}