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

✨"now configurable!"; customizable auto-labels and diff style #38

Closed
wants to merge 16 commits into from

Conversation

rivy
Copy link

@rivy rivy commented Jan 1, 2020

Fully implements customizable labelling and diff style for assert_eq!(...) and assert_ne!(...), but easily extended).

Fixes: #35
Fixes: #37
Alternative to: #33, #39

@rivy rivy changed the title WIP ~ add optional replacement labels for 'left'/'right' WIP ~ "now configurable!"; customizable auto-labels and prefixes Feb 5, 2020
@rivy
Copy link
Author

rivy commented Feb 5, 2020

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...

@rivy rivy changed the title WIP ~ "now configurable!"; customizable auto-labels and prefixes RFC/WIP ~ "now configurable!"; customizable auto-labels and prefixes Feb 6, 2020
@rivy rivy force-pushed the add.labels branch 2 times, most recently from 1c43e82 to 20601d7 Compare February 14, 2020 05:45
@rivy
Copy link
Author

rivy commented Feb 14, 2020

Code functionality and most of the code polish is done.

  • Adding automatic labelling of assert arguments 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.

- with the "labels" feature enabled, `assert_{eq,ne}!(...)` will auto-label arguments
- `with_labels_assert_{eq,ne}!(...)` will always auto-label arguments
  - arguments may be manually labelled by using `with_labels_assert_{eq,ne}!(foo: ..., bar: ...)` syntax

* note: to be auto-labeled, both arguments must be identifiers, not values
@rivy rivy force-pushed the add.labels branch 2 times, most recently from ebdd31e to d28055c Compare February 25, 2020 01:32
@rivy
Copy link
Author

rivy commented Feb 25, 2020

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)

@rivy
Copy link
Author

rivy commented Feb 25, 2020

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?

@rivy rivy changed the title RFC/WIP ~ "now configurable!"; customizable auto-labels and prefixes "now configurable!"; customizable auto-labels and prefixes Apr 9, 2020
@rivy rivy changed the title "now configurable!"; customizable auto-labels and prefixes "now configurable!"; customizable auto-labels and diff style Aug 23, 2020
@wycats
Copy link

wycats commented Nov 3, 2020

Is there any progress on this?

Base automatically changed from master to main February 9, 2021 15:52
@rivy rivy changed the title "now configurable!"; customizable auto-labels and diff style ✨"now configurable!"; customizable auto-labels and diff style Apr 17, 2021
@rivy
Copy link
Author

rivy commented Apr 17, 2021

Ping @tommilligan ... are you maintaining this now? If so, could you review?

@tommilligan
Copy link
Collaborator

@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: #24 (comment)

@rivy
Copy link
Author

rivy commented Oct 13, 2022

⚰️

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

Successfully merging this pull request may close these issues.

Use -/+ instead of </> Allow optional argument names (replacing "left"/"right")
3 participants