✨"now configurable!"; customizable auto-labels and diff style
Fully implements customizable labelling and diff style for assert_eq!(...) and assert_ne!(...), but easily extended).
Fixes: #35 Fixes: #37 Alternative to: #33, #39
It needs some condensing and refactoring before release, but this now allows much more flexible configuration. Customized labels and git-style diff prefixes are built-in as features ('labels' and 'diffstyle-git', respectively).
I'll polish it and get it ready for release as a real PR over the next week or so...
Code functionality and most of the code polish is done.
- Adding automatic labelling of
assertarguments is as simple as adding the "labels" feature when including the crate dependency (drop-in equivalent to current usage, no code changes necessary). - Displaying git-style-ish diffs is also simply feature gated with the "diffstyle_git" feature (again, drop-in equivalent to current usage, no code changes necessary).
- More complex configurations can be easily accomplished with very simple macro boilerplate (see the pretty_assertion_custom example).
// from 'pretty_assertion_custom.rs'
use pretty_assertions;
macro_rules! assert_eq { ($($arg:tt)+) => ({
pretty_assertions::with_config_assert_eq!( pretty_assertions::Config {
auto_label: true,
style: pretty_assertions::Color::Yellow.normal(),
prefix: "<=>",
prefix_left: "<<=", prefix_right: "=>>",
..Default::default()
},
$($arg)+
)
})}
/// ... assert_eq!( actual, expect ); ...
Commit squashing into more logical chunks is the next WIP. And then some documentation work.
Commits are more polished and logical. Docs are still WIP.
This covers the most common requested changes (labels and "git-esque" diffs) plus additional styling flexibility.
I'd like to be able to configure the other text in the assert. However, I haven't found a clean method as of yet. (Any suggestions?)
The added configuration flexibility is opt-in. Basic use of the "labels" or "diffstyle_git" features is straightforward by adding the feature in the dependency ... and the resulting use is still a drop-in for the usual assert_eq!(...) and assert_ne!(...).
Thoughts? (cc: @colin-kiegel, @cormacrelf, @aquarhead, @TimoFreiberg, @spenserblack, @martinlindhe)
Although the boilerplate customization is fairly simple, I'd like to present a simpler generator/helper macro to more automatically generate a replacement assert_eq!(), but I'm not sure if it's possible.
When I create a generator macro, the generated assert_eq!() macro "shadows" the original at a deeper scope level producing a compiler error. So, I'm stymied, unable to produce an error-free version. Is there a possible workaround?
But, in the end, since the boilerplate is relatively simple, I'm ok with the current implementation.
Thoughts?
Is there any progress on this?
Ping @tommilligan ... are you maintaining this now? If so, could you review?
@rivy thanks for the ping. I have looked over the basic design and like what you've done, but I need to invest some more time in benchmarking the changes and thinking about extensibility/the right public API to expose.
You might be interested in the recent discussion on this issue: https://github.com/colin-kiegel/rust-pretty-assertions/issues/24#issuecomment-797762148