-
Notifications
You must be signed in to change notification settings - Fork 25
Open
Description
I would like to be able to plug-in custom diffing algorithm in case of failure. Currently the dissimilar crate is hardcoded in the Runtime::panic.
The use case I have, is the following. I would like to check llvm ir output with expect, but textual diffs on llvm ir do not make much sense. For example, if one were to add a variable at the beginning of the function, most futher variables would change their names (they are named in the form %1, %2, %3, ...). But there is an awesome llvm-diff tool, that handles renames much better, so on failure I would like to print the llvm-diff output, not the dissimilar one.
I have two concepts of api in mind:
// Expose the plug-in point, or
impl Expect {
pub fn diff_fn(&mut self, diff: impl FnOnce(...) -> ...); // <- actually boxes the diff fn
pub fn assert_eq_with_diff(&self, actual: &str, diff: impl FnOnce(...) -> ...);
}
// A low-level api to allow user customization
impl Expect {
/// Check if this expect is equal to `actual`.
///
/// Returns ExpectError that contains `expected` and `actual` (also holds the rt lock).
/// You are expected to report the error and drop it - ExpectError panics on drop.
///
/// If UPDATE_XFLAGS=1 is set, updates the expect and returns none.
pub fn check_eq(&self, actual: &str) -> Option<ExpectError<'_>>;
}
impl ExpectError {
/// Prints common error message with user-provided diff
pub fn report_diff(self, diff: &str);
/// Prints common error message with user-provided diff
pub fn report_diff(self, diff: &str);
}
I am willing to create PR if it is an acceptable change
Metadata
Metadata
Assignees
Labels
No labels