Improve describeMismatch output across the board.#28
Improve describeMismatch output across the board.#28louisth wants to merge 9 commits intohamcrest:masterfrom
Conversation
Also: Make AnyOf and AllOf have the same base class. Make the mismatch description for TypeSafeDiagnosingMatcher match TypeSafeMatcher.
…es in core package.
…reTest and improve descriptions as necessary.
…scribeMismatchTortureTest and improve descriptions as necessary.
…xml matchers in DescribeMismatchTortureTest and improve descriptions as necessary.
…nd improve descriptions as necessary.
|
As much as I applaud your good work, this change-set is rather large, and hence difficult to digest. Also, there appears to be a number of unrelated changes mixed in (for instance several classes like NullDescription and CombinableBothMatcher have had their Is there any way you could break your work into smaller, incremental changes? I realise that your torture test probably mandates many of these changes in order to run, but perhaps we could add the individual matcher description changes first, in smaller batches, and finish up with the passing torture test? Suggestions welcome. |
|
I'll work on refactoring the change sets. |
|
@louisth before you put all the work in, we should take a look as this is quite a big change, especially if you (rightly or wrongly) want to redefine mismatchDescription |
|
OK. Now I'm confused. I admit, there are not the cleanest change sets and I should give more explaination. I also admit I'd rather not spend hours juggling change sets, especially if it's all going to be rejected anyway. What do you guys want? |
|
What's the quickest path to seeing the list of mismatch messages, especially in comparison to the old messages? If people can see the end result easily and like it, they'll be much more inclined to help move this forward. |
|
@dharkness: That makes sense. I've made a commit here (louisth/JavaHamcrest@93f2e82) that shows the difference between the current and the proposed. You can use your diff tool of choice to make the comparison. (GitHub is OK, but in this case every line needs a line-by-line comparison and GitHub's block comparisons don't make the changes easy to see.) This was an interesting exercise. While I picked examples to exercise all the code, I'm not sure I picked examples that demonstrate the potential for improvement, since with simple objects like Strings and Integers it's pretty easy to see why a match failed no matter how they're described. Oh well. A lot of the changes I made were to make the Matchers produce inteligible descriptions when the match succeeded. Since not() currently describes the passed object itself (rather than delegating to the wrapped Matcher for a more context sensitive description), the current "not" messages are usually acceptible. Once we delegate to the matchers, a lot of breakage occurs that does not show up here. Some of my favorite results:
|
|
I really like what you did there, but I would change the The problem of the current version (without your changes) is that every matcher assumes it is the only one, which leads to verbose messages when you combine them. I think it is perfectly fine if some matcher does not fully fill the "Y" of the template sentence. If every matcher only added to the description what they say in the source code, readable code automatically guarantees good descriptions. The other problem is the sentence structure "Expected X but ...". Take, for instance If the template was changed to "Expected that value X but ..." (again, closer to what the code says), and every matcher sticks to their factory method, you would get |
|
@louisth fancy rebasing this from master, as |
|
Personally, I think this one will cause unexpected problems. The reason we kept it slightly clunky is that getting rid of the clumsiness takes a lot of code and is never quite right. The uses cases here are straightfoward, but it gets messy very quickly. Then you're left with a lot more complicated code and still the same problem. I strongly recommend not taking this one, or at least simplifying it. |
|
Going to try and kick start hamcrest, so if you want to get it merged, please rebase from the branch |
9bc653b to
e9f7fc8
Compare
After running into confusing output from describeMismatch and reading the discussion at #9, I have tackled the problem head on. I believe @sf105 and @ihaworth have the right idea. Instead of trying to describe the failure, we need to describe the given item from the Matcher's point of view. According to this contract for describeMismatch, the existing implementations are basically correct.
What I've done is three things.
(DescribeMismatch is now rather misnamed, but I leave it to the maintainers to decide whether they want to break backwards compatibility to fix this.)
For anyone disagrees with my solution and wants to try their own hand at tackling this problem, I encourage you to at least grab the torture test. I think it does a pretty good job of illustrating and exercising the complexity of the problem.