Assert_eq tailored for multi-line text?

I'm having a lot of tests where the expected value is multi-line text in a &'static str. When a test fails, I find it hard to read the actual problem, as what I get is the left and right debug-escaped very long strings. I would like to get something more similar to command-line diff left right (if the strings were files).

I found pretty_assertions which is kind of similar but for structured data rather than text. If i do:

pretty_assertions::assert_eq!(
    result.lines().collect::<Vec<_>>(),
    expected.lines().collect::<Vec<_>>(),
);

but I would prefer

  1. To have the lines split/collected automatically (and only on failure)
  2. I would like to not get color-coded output (at least when running the tests in an emacs buffer, which doesn't handle that).

Is there any assert utility that might suite me better?

Here’s what we use in rust-analyzer: rust-analyzer/lib.rs at 1dbdac8f518e5d3400a0bbc0478a606ab70d8a44 · rust-lang/rust-analyzer · GitHub

Thanks @matklad ! That's at least some code I can use as a starting point if there isn't a ready-made crate for it.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.