testify icon indicating copy to clipboard operation
testify copied to clipboard

Colorize "expected" and "actual"

Open golopot opened this issue 4 years ago • 8 comments

Can we have an option to colorize "expected" and "actual" in test output? Like this: Screenshot from 2020-05-13 18-27-59

0_ZTerrO_akuDWSV8h

For me the colors helps because it allows me to locate the diff faster. This kind of coloring is very common in Node.js test frameworks.

golopot avatar May 13 '20 10:05 golopot

It's an interesting idea. I'm slightly leaning towards keeping testify as simple as possible but ultimately we do it for the community. If there is strong support for this, I'd be happy to look into it :)

boyan-soubachov avatar May 14 '20 09:05 boyan-soubachov

I like this idea. Perhaps the default should be set to the current behaviour and starting 2.0 we could enable it by default?

@boyan-soubachov I'd say let's do this assuming we can keep it a lightweight and KISSy solution.

Anyone any concrete ideas for a PR?

mvdkleijn avatar Jul 30 '20 22:07 mvdkleijn

I recommend an interface for decorating the output. The default implementation behaves as is now without decorating the output. Then anyone could implement this interface for colourful output.

Example

Spec library has this interface for generating reports. Here is an example implementation.

arsham avatar Jul 31 '20 07:07 arsham

Agreed with @arsham. I think it makes a lot more sense to provide the interface which users can customize. Not all users can see specific colours the same or well, not all colours have the same meanings to all people, etc.

boyan-soubachov avatar Aug 03 '20 10:08 boyan-soubachov

So, since we're agreed that this is a nice idea... Here's an initial spec sheet for this new feature:

  • [ ] Use an interface for decoration
  • [ ] Default interface implementation should leave the output undecorated (pre 2.0 at least)
  • [ ] An optional implementation should be provided for people who just want it to work
  • [ ] Initial optional implementation should colourize actual vs expected at the very least

For now I don't think it should be more than this.

mvdkleijn avatar Aug 04 '20 10:08 mvdkleijn

This will detect when running in interactive vs non-iterative mode (i.e. I don't want to see control characters in logged output).

alxn avatar Jan 16 '21 04:01 alxn

Are there plans to merge https://github.com/stretchr/testify/pull/1232?

juanzolotoochin avatar Mar 18 '23 18:03 juanzolotoochin

Just here to say that I would also love a little bit of colour! It makes it a little bit easier for people's eyes to parse the information dump that they see on the screen. Seems like a good addition to the suite :+1:

DennisTheMenace780 avatar Mar 24 '24 22:03 DennisTheMenace780