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

equalTo matcher should show a diff of the difference to make it possible to see where it is #209

Open
hakanai opened this issue Jun 3, 2018 · 4 comments · May be fixed by #339
Open

equalTo matcher should show a diff of the difference to make it possible to see where it is #209

hakanai opened this issue Jun 3, 2018 · 4 comments · May be fixed by #339

Comments

@hakanai
Copy link

hakanai commented Jun 3, 2018

If large texts are compared with equalTo, you just get both texts in full, and ultimately have to copy them out to text files manually and run a diff tool to figure out what the difference is. This is made worse because downstream tools reading the results don't produce diffs themselves. (To point the finger at one of the major suspects, IntelliJ IDEA shows diffs but only for tiny strings, even though for tiny strings you don't really need a diff to see the difference, but then doesn't show it for large strings, where you certainly can't see the difference without using diff.)

I think it's reasonable for the matcher's description of the mismatch to include this sort of thing as the primary message, and maybe include the full messages only for further information.

@garretwilson
Copy link

I just had the same idea this week. I'm writing an XML/HTML formatter, and I have a reasonably large HTML document of what I expect in a unit test. Using a similar approach as TDD, I set up the unit test before the formatter is fully complete, and I need to know which items the formatter needs work on.

Currently I'm placing the expected document and a System.out.prinln() of the formatted output in separate tabs in VS Code and comparing them. This give a nice, colorful diff, but it's all manual.

I don't know if a diff should occur with every use of equalTo(), but maybe that would be OK. Another option would be to add a verbose parameter or a diff parameter. Or maybe even an equalToWithDiff() matcher.

In a perfect world this would also use something like Jansi to provide a color-coded diff, like VS Code, TortoiseGit, and even Eclipse does nowadays.

@night-gale
Copy link

night-gale commented Apr 24, 2021

Hi, I would like to work on this issue @nhojpatrick .
My idea currently is to add Classes/Methods to equalTo matcher family for strings with WithDiff version, e.g. equalToWithDiff as @garretwilson commented. However, I am not sure whether it's okay or not to introduce dependencies to external libraries that provide diff functionality, like Difflib.

@hakanai
Copy link
Author

hakanai commented Apr 27, 2021

I would probably find a heuristic to guess whether the caller would like a diff or not, e.g. something like if the expected string contains more than one \n then show the diff, otherwise don't.

Otherwise we're going to have to go through our millions of assertions and manually change some of them to equalToWithDiff which will take a while.

@night-gale
Copy link

I think it a great idea to use some heuristics to infer whether to diff the output or not, but It could be difficult to have a general standard. Maybe more discussions are required.

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 a pull request may close this issue.

3 participants