bashunit icon indicating copy to clipboard operation
bashunit copied to clipboard

Add diff to failed assertions

Open khru opened this issue 2 years ago • 4 comments

Example of tools we could use:

https://github.com/dandavison/delta

khru avatar Sep 07 '23 22:09 khru

I've done a mini investigation and I want to leave the results here to advance this task a bit, first of all, I've tested 3 tools, diff, wdiff, and colordiff.

I've done all the tests with the following files:

file1:

Hello World
This is the file
And its gorgerous

But this is different
This one is equal

file2:

Hello
This is a file
And its awesome
I like trains
This one is equal

diff comes installed by default (at least on Linux Mint and I think on Ubuntu as well, to be confirmed on other OS) It's a very simple command that returns a line with a code indicating on which lines the changes have occurred, followed by the lines of the first file (prefixed with <) that differ from the lines of the second file (prefixed with >), so this command:

diff file1 file2

Outputs this:

1,5c1,4
< Hello World
< This is the file
< And its gorgerous
< 
< But this is different
---
> Hello
> This is a file
> And its awesome
> I like trains

`colordiff` is a command that needs to be installed, apparently it can be done with apt and brew among others, and this command exclusively colors the diffs, so the output of this command is exactly the same, but in color:
```bash
colordiff file1 file2

Outputs this: image

wdiff needs to be installed too, apparently it can be done with apt and brew among others, focuses on not duplicating the differences and what it does is surround with certain symbols the differences between both files. The following command:

wdiff -n file1 file2

Outputs this:

Hello [-World-]
This is [-the-] {+a+} file
And its [-gorgerous-]
[--]
[-But this is different-] {+awesome+}
{+I like trains+}
This one is equal

And here comes the cherry on top, colordiff is also compatible with wdiff, and if you pass the return of the wdiff with a pipe:

wdiff -n file1 file2 | colordiff

It is able to color it and achieve this wonder: image

If we decide to use these tools, it would be interesting to consider the idea that as the user has more commands available, more functionalities are enabled for them, that is, use diff by default or use wdiff instead if they have it installed, and use colordiff whenever they have it installed together with diff or wdiff.

Another interesting option would be for the user to be able to configure in the .env which command they want to use to print their diffs.

antonio-gg-dev avatar Oct 16 '23 07:10 antonio-gg-dev

Question here, does these two diffs work on Mac as well?

khru avatar Oct 16 '23 08:10 khru

I've also discovered that very similar results can be obtained using git (which is very likely that our users have installed).

git diff --no-index file1 file2

image

git diff --no-index --word-diff file1 file2

image

antonio-gg-dev avatar Oct 16 '23 08:10 antonio-gg-dev

Can we close this, @antonio-gg-dev @khru ?

Chemaclass avatar Jun 16 '24 10:06 Chemaclass