Add file path in case it cannot be read in Diff::actual_file

This commit is contained in:
Guillaume Gomez 2024-05-25 13:03:53 +02:00
parent 90fec5a087
commit 1551fd1202

View File

@ -51,7 +51,10 @@ 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 = std::fs::read_to_string(path).expect("failed to read file");
let content = match std::fs::read_to_string(path) {
Ok(c) => c,
Err(e) => panic!("failed to read `{}`: {:?}", path.display(), e),
};
let name = path.to_string_lossy().to_string();
self.actual = Some(content);