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

Allow custom diffing algorithm #50

Open
cpud36 opened this issue Sep 26, 2024 · 0 comments
Open

Allow custom diffing algorithm #50

cpud36 opened this issue Sep 26, 2024 · 0 comments

Comments

@cpud36
Copy link

cpud36 commented Sep 26, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant