Allow disabling the functionality via a feature flag
This way, tools (such as RustRover) that do not work with the functionality of this plugin can easily turn off this tool with a single line change in cargo.toml instead of needing to remove imports.
Hi, thanks for the suggestion. This feels a little weird to me to include in the pretty_assertions crate itself - the whole purpose of pretty_assertions is to do pretty printing functionality, so disabling everything feels analagous to the caller not including it.
I think this would work as a general pattern for projects that have this problem, using a feature flag:
#[cfg(test)]
mod assertions {
#[cfg(feature = "pretty")]
pub(crate) use pretty_assertions::assert_eq;
#[cfg(not(feature = "pretty"))]
pub(crate) use std::assert_eq;
}
#[cfg(test)]
mod test {
use crate::assertions::assert_eq;
#[test]
fn fails() {
assert_eq!([0, 1, 2], [0, 3, 2]);
}
}
However, I'm open to including some sort of fallback given this crate aims to be a drop in replacement.
I'm not convinced that a feature flag is the correct way to gate this; it depends on why tools like RustRover can't use it. Do you have a specific problem you're trying to fix?
Would an environment variable work? There is some old discussion around using something like RUST_ASSERT=style=std to change the output style.
This was only not done due to time/effort constraints, I think it can be picked up if it solves your case. The back-compatibility story is also much nicer than feature flags.
Would an environment variable work? There is some old discussion around using something like
RUST_ASSERT=style=stdto change the output style.
Definitely. The idea is that some tools need the original diff so they can show a pretty version of the diff in their UI, and the presence of pretty_assertions breaks these tools. So when one uses such a tool, they should have an easy escape hatch to disable the pretty asserts temporarily without needing to change the imports/code.