diff options
| author | Guillaume Gomez <guillaume.gomez@huawei.com> | 2024-06-11 14:05:30 +0200 |
|---|---|---|
| committer | Guillaume Gomez <guillaume.gomez@huawei.com> | 2024-06-13 12:59:24 +0200 |
| commit | 9bff23005dc8cfca8fab4e5edaaf7d910b6c10f3 (patch) | |
| tree | 05cd0298220dd9a7fe7980109a61f51e4bd155a6 | |
| parent | 921645c737f1d6d107a0a10ca5ee129d364dcd7a (diff) | |
| download | rust-9bff23005dc8cfca8fab4e5edaaf7d910b6c10f3.tar.gz rust-9bff23005dc8cfca8fab4e5edaaf7d910b6c10f3.zip | |
Allow to bless diff tests
| -rw-r--r-- | src/tools/run-make-support/src/diff/mod.rs | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/src/tools/run-make-support/src/diff/mod.rs b/src/tools/run-make-support/src/diff/mod.rs index 105cdbc7b32..d0be57ca9d7 100644 --- a/src/tools/run-make-support/src/diff/mod.rs +++ b/src/tools/run-make-support/src/diff/mod.rs @@ -1,6 +1,6 @@ use regex::Regex; use similar::TextDiff; -use std::path::Path; +use std::path::{Path, PathBuf}; use crate::drop_bomb::DropBomb; @@ -17,6 +17,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)>, @@ -30,6 +31,7 @@ impl Diff { Self { expected: None, expected_name: None, + expected_file: None, actual: None, actual_name: None, normalizers: Vec::new(), @@ -43,6 +45,7 @@ impl Diff { let content = std::fs::read_to_string(path).expect("failed to read file"); let name = path.to_string_lossy().to_string(); + self.expected_file = Some(path.into()); self.expected = Some(content); self.expected_name = Some(name); self @@ -104,6 +107,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()); + std::fs::write(expected_file, actual).unwrap(); + return; + } + } panic!( "test failed: `{}` is different from `{}`\n\n{}", expected_name, actual_name, output |
