-
Notifications
You must be signed in to change notification settings - Fork 0
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
Opentest4j or use diff views for string comparison #39
Comments
Can we do both? I would like to have the diff view in IntelliJ so opentest4j would be great if we are on the JVM. Your diff view would be helpful on other platforms. |
might be possible. I am not yet sure how well we can map to opentest4j exceptions as Atrium is more expressive, but we will see. |
As mentioned by @igorakkerman the diff makes probably not sense if the String is to short (TBD what short means). I agree for text reporting and to a console which does not support colours. |
I'd say: just don't. It bothers more than it helps, really. A viable alternative for seeing the differences would be an IDE plugin that would show the differences in a popup, when requested. IntelliJ IDEA does that already for some Java frameworks. |
@igorakkerman that is what adopting opentest4j is about. They are currently discussing providing, diffs, too. I would like to make a WIP PR that makes atrium adopt opentest4j. We can then see what that will result in and discuss there. |
This will most likely require a breaking change as the super-class of AtriumError will need to change, thus assigned it to 1.0.0 |
I made a quick test with opentest4j. As it seems intellij does not bother whether the exception is one of opentest4j's classes or not but it searches for a particular pattern in the error message. For instance, intellij will provide a diff view for the following
The prototyp is in the branch: https://github.com/robstoll/atrium/tree/%23339-avoid-duplicate-for-jvm-opentest4j |
Found a stackoverflow issue: with a link to some patterns which were in use (would be interesting to see the current patterns): The good thing, we probably don't have to bother about opentest4j (one dependency less 👍) on the other hand it seems a bit random and we need to see if we actually want to use the patterns or not (surely not changing the whole reporting only for that but maybe as additional hint). |
That’s interesting. I was playing around with the Opentest4j exceptions and was not able to merry them easily to atrium’s existing exception infrastructure. If JetBrains keeps a list of patterns they search for, maybe we can open a ticket to have our pattern added? We would then need to guarantee that this pattern stays stable, though. |
What do you think of a reporter that collects all the failed expectations in known to idea format? In other words, generate something like
Then it could be compared via idea's diff. See also https://youtrack.jetbrains.com/issue/IDEA-313769 Yet another alternative is to call https://github.com/approvals/ApprovalTests.Java/blob/master/approvaltests/docs/Reporters.md#supported-diff-tools have implemented launcers for many diff tools, however, they are not exracted as a seperate module/dependency |
that's what I was thinking as well, using a format where intellij provides a diff link. I would like to discuss whether we include it into the regular error message or if we repeat it at the end. in error message could be something like:
currently my plan would be:
Thoughts? |
Sounds like a good plan to me.
Just in case, IDEA supports at most one "diff link" (I was not able to make it display several links), so incline we need to build a single debug hint for all equal-like comparisons.
I think IDEA injects a class or something, so we can show "diff for IDEA" only in case we know there's IDEA.
We could probably omit the diff in case it exceeds 50% of the full length. |
Opentest4j allows throwing "comparison failed" exceptions without displaying too much information on the screen, so Opentest4j seems to be a reasonable way to achieve "click to see diff". However, it looks like Opentest4j exception is not properly displayed when the test is executed via Gradle runner: https://youtrack.jetbrains.com/issue/IDEA-275065/Click-to-see-diference-does-not-appear-with-org.opentest4j.AssertionFailedError-when-running-tests-with-Gradle |
That's bad to hear, maybe we can trick it by using different patterns? let's see, in the worst case we make one big debug string but in this case I would put it at the end, after the error message as such.
My guess is that also other IDEs have this diff functionslity and also parse the exception message for
I don't understand what you mean, could you elaborate please?
Yes, at least for the JVM platform. As far as I remember they also have an exceptions which gathers multiple other exceptions so that IDEA shows several click to see diff. |
I studied the code around, and it looks currently the behaviour is:
At all times, it extracts a single "diff" only.
Frankly speaking, I do not know if the other IDEs use regexp parsing for JUnit patterns
I consider diff as an option to shrink and pin-point the difference.
Right you are.
There's
Frankly speaking, I do not know what are the solutions for other platforms. |
I see it the same way and now I understand what you mean, makes sense. 👍
that's bad news, I wonder if I recall wrong or if it's a bug. Anyway, I tend to go down the opentest4j approach (if we can subclass reasonably) where we should be able to offer one click to see difference link which usually appears after the exception message, isn't it?
I see your point. I think if we use opentest4j then it is fair if we assume the IDE supports a diff feature based on it and we don't need to print the pattern at all. |
for gradle we could alternatively also provide an own TestFailureMapper |
took a close look how we could provide an own TestFailureMapper but it doesn't seem to possible for now, the implementation uses a hard-coded list of mappers: |
@dsvoronin thanks for reminding me about the missing diff functionality in Atrium via robstoll/atrium#1797. I would like to gather some feedback before implementing something. Maybe you can share your ideas. @VEZE I saw your thumbs up, so maybe you can give your feedback as well. (of course any other feedback is welcome as well) I see three main problems:
Personally I don't think we will end up with a nice solution if we try to come up with a diff for something the following current output because oft he above mentioned problems:
I therefore suggest, we focus on simple
) Question 1 Currently Intellij uses the following format in the output in case
We can influence what is written after
We end up with something like
Which is too noisy IMO. Therefore my suggestion would be that we always append something to
And the diff would look then as follows (so my suggestion would be to append Question 2 I see the intellij diff view as quick-win, long term it would be nicer IMO if the diff would be included in the error message directly, i.e. something like Question 3 If you have any other suggestions, please raise your voice 🙂 |
Most common scenario for me is diff between data classes, or long enough strings to be hard to spot difference in console. That would fit the "simple one value" scenario. Simple blue-ish diff highlighting in Idea helps a lot here. Sometimes i prefer to diff data classes instead of using feature extraction, which could help here too. It's just easier to maintain mostly.
Small diffs usually simple to spot, big data classes/strings would require soft-wrapping, big window, so i would say it could be helpful in some cases, but not completely covers Idea diff
No idea, really. Could it make things worse, for example for people with non-standard color schemas in terminal? Should I already see aligned expected/actual |
@dsvoronin thanks for the feedback 🙂 👍 Atrium v1.2.0 does not include the alignment yet but it's implemented on the proof branch: This branch also includes the |
diff for I've checked up your discussion above and really glad that you go with opentest4j solution, cause
|
As for me it's not a problem to use "click to show diff", it allows to navigate between not matching parts, |
@Nikita-Guchakov thanks for the feedback I have come across use cases where the diff view of intellij was helpful even for short text due to hidden chars (e.g. different line ending, different spaces, background/foreground colour etc.). As for now I see the coloured diff as addition which might be especially helpful in CI and on non-JVM platforms (e.g. when running JS tests). Of course, colours only help if the terminal supports them, where windows is an enemy 😆 I don't think MultipleFailuresError will be a good fit for Atrium as provided out of the box as it splits the error message into multiple parts (which kind of goes against the reporting strategy of atrium). But having the possibility for mulitple <click to see difference> links is of course nice. I will check later (i.e. in 1.4.0) if we can misuse it somewhat. |
@Nikita-Guchakov @dsvoronin and others reading this, I have released v1.3.0-alpha-1 which includes the click to see difference link: Please try it out and give feedback, especially if you should find bugs or if something seems odd in reporting. Thanks |
I was thinking to use opentest4j to improve String comparisons so that one gets support in the IDE to see a diff view.
However, I am not sure if opentest4j is a good fit as it is meant for jvm only. Maybe it is better if we deliver a diff hint in case the subject is a CharSequence. For instance:
Should result in something like
I guess this is especially helpful if someone compares long texts such as file contents (e.g. two json).
The text was updated successfully, but these errors were encountered: